Chinaunix首页 | 论坛 | 博客
  • 博客访问: 317897
  • 博文数量: 57
  • 博客积分: 146
  • 博客等级: 入伍新兵
  • 技术积分: 769
  • 用 户 组: 普通用户
  • 注册时间: 2012-05-29 14:57
文章分类
文章存档

2014年(39)

2013年(13)

2012年(5)

我的朋友

分类: C/C++

2014-10-09 16:56:56

内核版本:2.6.18

点击(此处)折叠或打开

  1. #define AF_INET        2    /* Internet IP Protocol     */
  2. #define PF_INET        AF_INET

点击(此处)折叠或打开

  1. static struct net_proto_family inet_family_ops = {
  2.     .family = PF_INET,
  3.     .create = inet_create,
  4.     .owner    = THIS_MODULE,
  5. }
注册PF_INET协议族。

点击(此处)折叠或打开

  1. (void)sock_register(&inet_family_ops)

源代码:

点击(此处)折叠或打开

  1. int sock_register(struct net_proto_family *ops)
  2. {
  3.     int err;

  4.     if (ops->family >= NPROTO) {
  5.         printk(KERN_CRIT "protocol %d >= NPROTO(%d)\n", ops->family, NPROTO);
  6.         return -ENOBUFS;
  7.     }
  8.     net_family_write_lock();
  9.     err = -EEXIST;
  10.     if (net_families[ops->family] == NULL) {
  11.         net_families[ops->family]=ops;//inet_family_ops挂到net_families全局数组
  12.         err = 0;
  13.     }
  14.     net_family_write_unlock();
  15.     printk(KERN_INFO "NET: Registered protocol family %d\n",
  16.      ops->family);
  17.     return err;
  18. }


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