Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what does 0 indicate in socket() system call?

Tags:

c

unix

sockets

what 0 indicates in following line? what are other flags i can use?

server = socket(AF_UNIX, SOCK_STREAM, 0)
like image 706
bunty Avatar asked Sep 17 '10 13:09

bunty


2 Answers

As others have likely said, the third argument to socket is generally an int indicating the protocol. 0 indicates that the caller does not want to specify the protocol and will leave it up to the service provider.

Other than zero, another common one is IPPROTO_TCP.

Full details can be found on the man page using man 2 socket on your machine or visiting here.

like image 164
mrduclaw Avatar answered Oct 17 '22 20:10

mrduclaw


From the man pages of socket:

int socket(int domain, int type, int protocol);

The protocol specifies a particular protocol to be used with the socket. Normally only a single protocol exists to support a particular socket type within a given protocol family, in which case protocol can be speci‐ fied as 0. However, it is possible that many protocols may exist, in which case a particular protocol must be specified in this manner. The protocol number to use is specific to the “communication domain” in which commu‐ nication is to take place; see protocols(5). See getprotoent(3) on how to map protocol name strings to proto‐ col numbers.

like image 36
codaddict Avatar answered Oct 17 '22 21:10

codaddict