以下是协议栈初始化函数调用层次结构
socket.c :BSD socket层,属于表示层,为应用层系统调用提供接口;
af_inet.c :INET Socket层,属于会话层,屏蔽底层协议
以下是sock_init()函数
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; /* * 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 }
for (i = 0; i < NPROTO; ++i) pops[i] = NULL;
pops[]定义如下:
static struct proto_ops *pops[NPROTO];
proto_ops结构体定义如下:
struct proto_ops { int family; int (*create) (struct socket *sock, int protocol); int (*dup) (struct socket *newsock, struct socket *oldsock); int (*release) (struct socket *sock, struct socket *peer); int (*bind) (struct socket *sock, struct sockaddr *umyaddr, int sockaddr_len); int (*connect) (struct socket *sock, struct sockaddr *uservaddr, int sockaddr_len, int flags); int (*socketpair) (struct socket *sock1, struct socket *sock2); int (*accept) (struct socket *sock, struct socket *newsock, int flags); int (*getname) (struct socket *sock, struct sockaddr *uaddr, int *usockaddr_len, int peer); int (*read) (struct socket *sock, char *ubuf, int size, int nonblock); int (*write) (struct socket *sock, char *ubuf, int size, int nonblock); int (*select) (struct socket *sock, int sel_type, select_table *wait); int (*ioctl) (struct socket *sock, unsigned int cmd, unsigned long arg); int (*listen) (struct socket *sock, int len); int (*send) (struct socket *sock, void *buff, int len, int nonblock, unsigned flags); int (*recv) (struct socket *sock, void *buff, int len, int nonblock, unsigned flags); int (*sendto) (struct socket *sock, void *buff, int len, int nonblock, unsigned flags, struct sockaddr *, int addr_len); int (*recvfrom) (struct socket *sock, void *buff, int len, int nonblock, unsigned flags, struct sockaddr *, int *addr_len); int (*shutdown) (struct socket *sock, int flags); int (*setsockopt) (struct socket *sock, int level, int optname, char *optval, int optlen); int (*getsockopt) (struct socket *sock, int level, int optname, char *optval, int *optlen); int (*fcntl) (struct socket *sock, unsigned int cmd, unsigned long arg); };