user3668129
user3668129

Reputation: 4820

Where is the Linux socket implementation?

In C programs, in order to use sockets, we need to include:

#include<sys/socket.h>

I have searched for the socket.c file (the implementation of <sys/socket.h>) but didn't found it (find -iname "socket.c*")

  1. Where can I find the Linux socket implementation?
  2. Can I modify this file and change this implementation?

Upvotes: 11

Views: 6169

Answers (2)

ensc
ensc

Reputation: 6994

socket() implementation is in net/socket.c in the linux kernel sources

SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol)

You can modify this file an the implementation.

Upvotes: 3

iehrlich
iehrlich

Reputation: 3580

The header file contains declarations for socket-related system calls. To start diving into the implementation, please consider referring to net/socket.c file in the Linux source tree.

Regarding changing the implementation - Linux is an open-source software product distributed under the terms of GNU GPL. If you'll spend quite some time to understand how to re-build the kernel from scratch, you'll be able to apply any changes you want to the kernel and deploy it to your local machines (at your own risk of course).

Upvotes: 12

Related Questions