BSD Socket 层(一)—— sock_create sock_create/__sock_create 原型: int sock_create(int family, int type, int protocol, struct socket ) 实例: sock_create(AF_INET, SOCK_DGRAM, IPPROTO_IP, &sock ) int sock_create(int family, int type, int protocol, struct socket **res) { return __sock_create(current -> nsproxy ->net_ns , family , type , protocol , res , 0 ); } : 真正的工作由 __sock_create 来做 current 是指向当前 task 的指针, task 的类型为 struct task_struct nsproxy 是它的一个成员变量,是 task 的命名空间指针 11/26/11 CCNT, ZJU struct nsproxy { struct uts_namespace *uts_ns; struct ipc_namespace *ipc_ns; struct mnt_namespace *mnt_ns; struct pid_namespace *pid_ns; struct net *net_ns; };
8.
BSD Socket 层(二) —— sock_create __sock_create 11/26/11 CCNT, ZJU static int __sock_create(struct net *net, int family, int type, int protocol,struct socket * *res, int kern){ …… if (family < 0 || family >= NPROTO) return -EAFNOSUPPORT; if (type < 0 || type >= SOCK_MAX) return -EINVAL; …… } 对 family 和 type 进行检查,查看是否超出正常范围
9.
BSD Socket 层(三) —— sock_create 申请一个 socket node 11/26/11 CCNT, ZJU sock = sock_alloc(); if (!sock) { if (net_ratelimit()) printk(KERN_WARNING “socket: no more sockets\n”); return -ENFILE; } 转入 sock_alloc