Netsocketc

asmlinkage long sys_socketcall(int call, unsigned long _user *args)

unsigned long a[6]; unsigned long a0,a1; int err;

if(call<1||call>SYS_RECVMSG) return -EINVAL;

/* copy_from_user should be SMP safe. */ if (copy_from_user(a, args, nargs[call])) return -EFAULT;

switch(call) {

case SYS_SOCKET:

case SYS_BIND:

err = sys_bind(a0,(struct sockaddr _user *)a1, a[2]);

break;

case SYS_SENDMSG:

err = sys_sendmsg break;

case SYS_RECVMSG:

err = sys_recvmsg break;

default:

return err;

Even though the target functions comply with the same naming conventions as system calls, they can be invoked only via the socketcall call and not by any other system call.

Table 12-3 shows which "subcalls" of socketcall are available.

12.10.4 Creating Sockets sys_socket is the starting point for creating a new socket. The associated code flow diagram is shown in Figure 12-32.

sys_socket sock_create

__sock_create |

sock_alloc 1

net_families[family] >create |

Figure 12-32: Code flow diagram for sys_socket.

First, a new socket data structure is created using sock_create, which directly calls_sock_create. The task of reserving the required memory is delegated to sock_alloc, which not only reserves space for an instance of struct socket, but also allocates memory for an inode instance directly below. This enables the two objects to be combined as discussed above.

All transport protocols of the kernel are grouped into the array static struct net_proto_family *net_families[NPROTO] defined in net/socket.c. (ccodesock_register is used to add new entries to the database.) The individual members provide a protocol-specific initialization function.

Continue reading here: Info

Was this article helpful?

0 0