Linux socket () implementation location

On Linux, to create a socket, we include the sys / socket.h header file and use the socket () function. The header file is located at /usr/include/sys/socket.h.

extern int socket (int __domain, int __type, int __protocol) __THROW;

      

Can anyone point out the location where socket () function is actually implemented.

Thank.

+3


source to share


3 answers


Acutally, int socket (int __domain, int __type, int __protocol) __THROW

implemented in glibc,



and glibc calls the sys_socket kernel function implemented in the net / socket.c kernel file .

asmlinkage long sys_socket(int family, int type, int protocol);

      

+4


source


socket (2) is a call to ssytem . The function socket

inside Glibc is just a tiny wrapper to make the actual system call.

From an application's point of view, system calls are atomic; in other words, the virtual machine your Linux application is running on is an x86 machine (a set of forbidden commands), complemented by over 300 system calls provided by the kernel. See also the Assembly Howto , which explains how you can code the system call. More on linux kernel and syscalls (2) and intro (2) man page.



The real work about sockets is done inside the kernel, which is the networking subsystem.

+1


source


Here it is => socket.c .

Usually, most socket functions, including this one, are just wrappers around system calls (direct calls to the kernel), so this is all handled by the almighty kernel.

Here is the kernel implementation: SYSCALL_DEFINE3 (socket, int, family, int, type, int, protocol) {...}

0


source







All Articles