3

What's the difference under the covers between using:

socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);

and

socket(AF_INET, SOCK_STREAM, 0);

I had a reason to use a stream socket within an application and was told to use the 2nd one (which I'm guessing is because TCP would be overkill since its in-box and reliable by default). I wasn't quite sure what the socket created with a null final parameter actually was though, so I'm hesitant to use it.

John Humphreys
  • 37,047
  • 37
  • 155
  • 255
  • 2
    Probably this [post][1] helps. [1]: http://stackoverflow.com/questions/5385312/ipproto-ip-vs-ipproto-tcp-ipproto-udp – Simon Aug 19 '11 at 13:17

2 Answers2

5

There is no difference. Both will return a TCP socket, because TCP is the default STREAM protocol of INET family.

SKi
  • 8,007
  • 2
  • 26
  • 57
3

socket() reference:

Specifying a protocol of 0 causes socket() to use an unspecified default protocol appropriate for the requested socket type.

Default protocol for a stream socket is naturally TCP. So, to answer your question, there is no difference.

otto
  • 1,138
  • 6
  • 14