Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sockets - IPPPROTO_TCP Vs. 0

Tags:

c++

c

unix

sockets

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.

like image 800
John Humphreys Avatar asked Sep 16 '25 18:09

John Humphreys


1 Answers

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

like image 189
SKi Avatar answered Sep 18 '25 09:09

SKi