日期:2014-05-16 浏览次数:20646 次
?
一、socket绑定入口
struct sockaddr_in server_address; server_address.sin_family = AF_INET; server_address.sin_addr.s_addr = inet_addr("0.0.0.0"); server_address.sin_port = htons(9734); server_len = sizeof(server_address); bind(server_sockfd, (struct sockaddr *)&server_address, server_len);?
asmlinkage long sys_socketcall(int call, unsigned long __user *args) { unsigned long a[6]; unsigned long a0, a1; int err; if (copy_from_user(a, args, nargs[call])) return -EFAULT; a0 = a[0]; a1 = a[1]; switch (call) { …... case SYS_BIND: err = sys_bind(a0, (struct sockaddr __user *)a1, a[2]); …... }?
asmlinkage long sys_bind(int fd, struct sockaddr __user *umyaddr, int addrlen) { struct socket *sock; char address[MAX_SOCK_ADDR]; int err, fput_needed; // 1, 根据fd查找相应的socket结构 sock = sockfd_lookup_light(fd, &err, &fput_needed); if (sock) { // 2, 将用户空间的地址结构拷贝到内核空间 err = move_addr_to_kernel(umyaddr, addrlen, address); if (err >= 0) { err = security_socket_bind(sock, (struct sockaddr *)address, addrlen); if (!err) // 3, 根据协议域及socket类型,调用相应的bind函数 err = sock->ops->bind(sock, (struct sockaddr *) address, addrlen); } fput_light(sock->file, fput_needed); } ret