linux 内核版本 1.2.13
文件:net/socket.c
1.
void sock_init(void)
{
int i;
printk("Swansea University Computer Society NET3.019\n");
/*
*Initialize all address (protocol) families.
*/
for (i = 0; i < NPROTO; ++i) pops[i] = NULL;
//pops 全局变量,初始化为NULL
/*
*Initialize the protocols module.
*/
proto_init();
#ifdef CONFIG_NET
/*
*Initialize the DEV module.
*/
dev_init();
/*
*And the bottom half handler
*/
bh_base[NET_BH].routine= net_bh;
enable_bh(NET_BH);
#endif
}
2.
struct net_protoprotocols[] = {
#ifdefCONFIG_UNIX
{ "UNIX",unix_proto_init},
#endif
#if defined(CONFIG_IPX)||defined(CONFIG_ATALK)
{ "802.2",p8022_proto_init },
{ "SNAP",snap_proto_init },
#endif
#ifdef CONFIG_AX25
{ "AX.25",ax25_proto_init },
#endif
#ifdefCONFIG_INET
{ "INET",inet_proto_init}, //(*pro->init_func)(pro) 在这执行初始化 函数
#endif
#ifdef CONFIG_IPX
{ "IPX",ipx_proto_init },
#endif
#ifdef CONFIG_ATALK
{ "DDP",atalk_proto_init },
#endif
{ NULL,NULL}
};
voidproto_init(void)
{
extern struct net_proto protocols[];/* Network protocols */
struct net_proto *pro;
/* Kick all configured protocols. */
pro = protocols;
while (pro->name != NULL)
{
(*pro->init_func)(pro);
pro++;
}
/* We're all done... */
}
voidinet_proto_init(struct net_proto *pro)
{
struct inet_protocol *p;
int i;
printk("Swansea University Computer Society TCP/IP for NET3.019\n");
/*
* Tell SOCKET that we are alive...
*/
(void) sock_register(inet_proto_ops.family, &inet_proto_ops);//pops 在这获得初始化值,family和一系列的函数
seq_offset = CURRENT_TIME*250;
/*
*Add all the protocols.
*/
for(i = 0; i < SOCK_ARRAY_SIZE; i++)
{
tcp_prot.sock_array[i] = NULL;
udp_prot.sock_array[i] = NULL;
raw_prot.sock_array[i] = NULL;
}
tcp_prot.inuse = 0;
tcp_prot.highestinuse = 0;
udp_prot.inuse = 0;
udp_prot.highestinuse = 0;
raw_prot.inuse = 0;
raw_prot.highestinuse = 0;
printk("IP Protocols: ");
for(p = inet_protocol_base; p != NULL;) //inet_protocol_base已经被初始化程一个链表 :igmp_protocol/icmp_protocol ->udp_protocol->tcp_protocol->NULL
{
struct inet_protocol *tmp = (struct inet_protocol *) p->next;
inet_add_protocol(p);// inet生成hash值 ,便于直接查找 协议 。个人理解
printk("%s%s",p->name,tmp?", ":"\n");
p = tmp;
}
/*
*Set the ARP module up
*/
arp_init();//注册arp ,并将arp_packet_type链入到ptype_base
/*
*Set the IP module up
*/
ip_init();//注册ip, 并将ip_packet_type链入到ptype_base
}
至此,初始化完成。