-
protocol
hello friends,when I want to create new socket i use the function socket defined as
Code:
int socket ( int domain , int type , int protocol ) ;
the problem i found three protocols:and andthe question in most case we use IPPROTO_IP why ? when we use the other protocol?
-
that because in normal IP sockets, the protocol argument in the 'socket' call is not really needed and you can just use '0' as the protocol. and it turns out that IPPROTO_IP happens to be #define'ed to be 0. the other IPPROTOS_xxx DO mean something when you are using setsockopt.
"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 specified as 0"
edit: in other words, the underlying code in 'socket' knows what type of socket to use based on the 'type' argument so that 'protocol' is redundant.