what does 0 indicate in socket() system call?

后端 未结 3 2144
旧时难觅i
旧时难觅i 2021-02-09 06:46

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

server = socket(AF_UNIX, SOCK_STREAM, 0)
相关标签:
3条回答
  • 2021-02-09 07:08

    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.

    0 讨论(0)
  • 2021-02-09 07:08

    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.

    0 讨论(0)
  • 2021-02-09 07:17

    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.

    0 讨论(0)
提交回复
热议问题