Chinaunix首页 | 论坛 | 博客
  • 博客访问: 603558
  • 博文数量: 113
  • 博客积分: 2554
  • 博客等级: 少校
  • 技术积分: 1428
  • 用 户 组: 普通用户
  • 注册时间: 2011-12-21 19:53
文章分类

全部博文(113)

文章存档

2014年(1)

2013年(2)

2012年(94)

2011年(16)

分类: C/C++

2012-04-24 14:38:44

首先定义函数和结构体

点击(此处)折叠或打开

  1. /* function prototypes */
  2. void     init_v6(void);
  3. void     proc_v4(char *, ssize_t, struct msghdr *, struct timeval *);
  4. void     proc_v6(char *, ssize_t, struct msghdr *, struct timeval *);
  5. void     send_v4(void);
  6. void     send_v6(void);
  7. void     readloop(void);
  8. void     sig_alrm(int);
  9. void     tv_sub(struct timeval *, struct timeval *);

  10. struct proto {
  11.   void     (*fproc)(char *, ssize_t, struct msghdr *, struct timeval *);
  12.   void     (*fsend)(void);
  13.   void     (*finit)(void);
  14.   struct sockaddr *sasend;    /* sockaddr{} for send, from getaddrinfo */
  15.   struct sockaddr *sarecv;    /* sockaddr{} for receiving */
  16.   socklen_t     salen;        /* length of sockaddr{}s */
  17.   int          icmpproto;    /* IPPROTO_xxx value for ICMP */
  18. } *pr;
  19. 然后初始化结构体

  20. 点击(此处)折叠或打开

    1. struct proto    proto_v4 = { proc_v4, send_v4, NULL, NULL, NULL, 0, IPPROTO_ICMP };
    然后初始化指针

  21. 点击(此处)折叠或打开

    1. pr = &proto_v6;
    然后调用方式
  22. (*pr->fproc)(recvbuf, n, &msg, &tval);

阅读(894) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~