Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

where is socket header in linux

Tags:

c++

linux

I compile my simple prog with #include <sys/socket.h> but there's none of this file. Where is it, I just start coding in linux and I have no idea where is it . Or do we need to download it online .

like image 403
Dzung Nguyen Avatar asked Oct 26 '10 11:10

Dzung Nguyen


People also ask

What is header in socket programming?

Socket header files contain data definitions, structures, constants, macros, and options used by socket subroutines. An application program must include the appropriate header file to make use of structures or other information a particular socket subroutine requires.

What is the socket in Linux?

Sockets are a way to enable inter-process communication between programs running on a server, or between programs running on separate servers. Communication between servers relies on network sockets, which use the Internet Protocol (IP) to encapsulate and handle sending and receiving data.

What does socket () return?

Upon successful completion, socket() returns a nonnegative integer, the socket file descriptor. Otherwise a value of -1 is returned and errno is set to indicate the error.


4 Answers

In case you have installed manual pages, the first stop should be man socket.

Without manual pages you could call

find /usr/include -name socket.h

which outputs

/usr/include/asm/socket.h
/usr/include/sys/socket.h
/usr/include/bits/socket.h
/usr/include/linux/socket.h

on my system, the one to include is sys/socket.h .

Also see the Single UNIX Specification.

like image 144
Peter G. Avatar answered Nov 15 '22 17:11

Peter G.


On a fresh Linux, for example, Ubuntu X86-64, while there is no gcc installed, there is no socket.h headers, while installed gcc, you can find it under /usr/include, for me, the output is:

$ find /usr/include/ -name socket.h
/usr/include/asm-generic/socket.h
/usr/include/x86_64-linux-gnu/asm/socket.h
/usr/include/x86_64-linux-gnu/bits/socket.h
/usr/include/x86_64-linux-gnu/sys/socket.h
/usr/include/linux/socket.h
like image 27
coanor Avatar answered Nov 15 '22 17:11

coanor


man socket

should give you the answer.

like image 38
mouviciel Avatar answered Nov 15 '22 16:11

mouviciel


You need to

#include <sys/socket.h>

See this :

http://linux.die.net/man/7/socket

like image 34
BЈовић Avatar answered Nov 15 '22 17:11

BЈовић