当应用程序使用socket()创建一个socket时,会执行sys_socket,其定义如下
asmlinkage long sys_socket(int family, int type, int protocol) retval = sock_create(family, type, protocol, &sock);//创建socket retval = sock_map_fd(sock);//分配一个未使用的文件描述符fd,并将socket和fd建立联系 out: out_release: |
结构体socket的定义如下(include\linux\net.h):
struct socket { socket_state state; unsigned long flags; struct proto_ops *ops; struct fasync_struct *fasync_list; struct file *file;//通过这个和文件描述符建立联系 struct sock *sk; wait_queue_head_t wait; short type; }; |