Thread: protocol

  1. #1
    Registered User
    Join Date
    Jun 2012
    Posts
    21

    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:
    Code:
    IPPROTO_IP=0
    and
    Code:
    IPPROTO_TCP=6
    and
    Code:
    IPPROTO_UDP = 17
    the question in most case we use IPPROTO_IP why ? when we use the other protocol?

  2. #2
    Registered User
    Join Date
    Mar 2011
    Posts
    546
    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.
    Last edited by dmh2000; 07-20-2012 at 09:26 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Anyone with SIP protocol and CPP?
    By Yosuf in forum Networking/Device Communication
    Replies: 6
    Last Post: 05-28-2009, 09:51 AM
  2. FTP protocol
    By IfYouSaySo in forum Tech Board
    Replies: 5
    Last Post: 08-07-2006, 08:54 PM
  3. irc protocol
    By chrismiceli in forum C Programming
    Replies: 4
    Last Post: 09-16-2003, 12:56 AM
  4. Protocol
    By newbie_grg in forum Networking/Device Communication
    Replies: 1
    Last Post: 08-17-2003, 05:15 PM
  5. help on protocol
    By Prasad kulkarni in forum C Programming
    Replies: 3
    Last Post: 10-20-2002, 08:54 AM