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 .
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.
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.
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.
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.
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
man socket
should give you the answer.
You need to
#include <sys/socket.h>
See this :
http://linux.die.net/man/7/socket
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With