Chapter 12: Networks
switch(call)
{
case SYS_SOCKET:
err = sys_socket(a0,a1,a[2]);
break;
case SYS_BIND:
err = sys_bind(a0,(struct sockaddr __user *)a1, a[2]);
break;
...
case SYS_SENDMSG:
err = sys_sendmsg(a0, (struct msghdr __user *) a1, a[2]);
break;
case SYS_RECVMSG:
err = sys_recvmsg(a0, (struct msghdr __user *) a1, a[2]);
break;
default:
err = -EINVAL;
break;
}
return err;
}
Even though the target functions complywith the same naming conventions as
system calls, they can be invoked only via thesocketcallcall and not by any other
system call.
Table 12-3 shows which ‘‘subcalls‘‘ ofsocketcallare available.
12.10.4 Creating Sockets
sys_socketis the starting point for creating a new socket. The associated code flow diagram is shown in
Figure 12-32.
sys_socket
sock_create
sock_alloc
sock_map_fd
net_families[family]->create
_ _sock_create
Figure 12-32: Code flow diagram forsys_socket.
First, a new socket data structure is created usingsock_create, which directly calls__sock_create.The
task of reserving the required memory is delegated tosock_alloc, which not only reserves space for an
instance ofstruct socket, but also allocates memory for an inode instance directly below. This enables
the two objects to be combined as discussed above.