Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is the Linux socket implementation?

Tags:

linux

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?
like image 738
user3668129 Avatar asked Jun 30 '17 15:06

user3668129


2 Answers

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).

like image 152
iehrlich Avatar answered Nov 02 '22 09:11

iehrlich


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.

like image 40
ensc Avatar answered Nov 02 '22 07:11

ensc