声明:本文为原创
#####请转贴时保留以下内容######
作者:GTT
请提出宝贵意见Mail:mtloveft@hotmail.com
Linux Version:2.6.33
提示:本文是关于linux 如何实现socket 通信的介绍!
ipv4网络在内核初始化时进行来一些设置,以后对socket操作都跟这些设置有关,
先来看看inet的初始化过程
static int __init inet_init(void) { struct sk_buff *dummy_skb; struct inet_protosw *q; struct list_head *r; int rc = -EINVAL;
BUILD_BUG_ON(sizeof(struct inet_skb_parm) > sizeof(dummy_skb->cb));
rc = proto_register(&tcp_prot, 1); if (rc) goto out;
rc = proto_register(&udp_prot, 1); if (rc) goto out_unregister_tcp_proto;
rc = proto_register(&raw_prot, 1); if (rc) goto out_unregister_udp_proto;
/* Tell SOCKET that we are alive... */ (void)sock_register(&inet_family_ops);
#ifdef CONFIG_SYSCTL ip_static_sysctl_init(); #endif
/* Add all the base protocols. */
if (inet_add_protocol(&icmp_protocol, IPPROTO_ICMP) < 0) printk(KERN_CRIT "inet_init: Cannot add ICMP protocol\n"); if (inet_add_protocol(&udp_protocol, IPPROTO_UDP) < 0) printk(KERN_CRIT "inet_init: Cannot add UDP protocol\n"); if (inet_add_protocol(&tcp_protocol, IPPROTO_TCP) < 0) printk(KERN_CRIT "inet_init: Cannot add TCP protocol\n"); #ifdef CONFIG_IP_MULTICAST if (inet_add_protocol(&igmp_protocol, IPPROTO_IGMP) < 0) printk(KERN_CRIT "inet_init: Cannot add IGMP protocol\n"); #endif
/* Register the socket-side information for inet_create. */ for (r = &inetsw[0]; r < &inetsw[SOCK_MAX]; ++r) INIT_LIST_HEAD(r);
for (q = inetsw_array; q < &inetsw_array[INETSW_ARRAY_LEN]; ++q) inet_register_protosw(q);
/* Set the ARP module up */ arp_init();
/* Set the IP module up */ ip_init();
tcp_v4_init();
/* Setup TCP slab cache for open requests. */ tcp_init();
/* Setup UDP memory threshold */ udp_init();
/* Add UDP-Lite (RFC 3828) */ udplite4_register();
/* Set the ICMP layer up */
if (icmp_init() < 0) panic("Failed to create the ICMP control socket.\n");
/* Initialise the multicast router */ #if defined(CONFIG_IP_MROUTE) if (ip_mr_init()) printk(KERN_CRIT "inet_init: Cannot init ipv4 mroute\n"); #endif /* Initialise per-cpu ipv4 mibs */
if (init_ipv4_mibs()) printk(KERN_CRIT "inet_init: Cannot init ipv4 mibs\n");
ipv4_proc_init();
ipfrag_init();
dev_add_pack(&ip_packet_type);
rc = 0; out: return rc; out_unregister_udp_proto: proto_unregister(&udp_prot); out_unregister_tcp_proto: proto_unregister(&tcp_prot); goto out; }
|
先关注字体加大加粗的方法,其它慢慢介绍
最后把tcp ,udp , raw 这3种关于socket的数据结构的一览表贴出来,以后说明时一眼就能看出区别。
阅读(1864) | 评论(0) | 转发(0) |