views:

54

answers:

3

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

server = socket(AF_UNIX, SOCK_STREAM, 0)
+3  A: 

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.

codaddict
A: 

The best thing to do here is read the man page. This document states that the third parameter is the protocol, which in this case is SOCK_STREAM but can be others.

Mike Axiak
+4  A: 

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.

mrduclaw