Re: socket(,,protocol): when htons?
From: Phil Frisbie, Jr. (phil_at_hawksoft.com)
Date: Wed, 12 Oct 2005 16:21:19 GMT
Sam Steingold wrote:
>>* Phil Frisbie, Jr. <email@example.com> [2005-10-11 19:51:46 +0000]:
>>Sam Steingold wrote:
>>>when do I need to call htons on the 3rd argument to socket()?
>>Never. That third argument is almost never needed, and since they are
>>predefined in the OS specific headers the values should already be in
>>the proper format.
> then why does googling for htons(ETH_P_ALL) returns 847 pages?
> mostly in this context:
> socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
OK, raw sockets is another story, and it it is not really a protocol.
>>>it appears that 0 is the most common argument,
>>>but I often see examples like
>>>so, what is the rule?
>>>what CPP #define's can be passed to socket() as the protocol?
>>>which ones need htons()?
>>>the next question is, of course,
>>>how portable the answer to the previous question is?
>>>(i.e., what are the proper protocol argument to socket() on *BSD &c)
>>If you are only using the TCP/IP protocol and need full portability
>>then only use '0' for the third argument.
> what if I need UDP and need full portability?
TCP/IP includes both TCP and UDP sockets. Just use '0'.
-- Phil Frisbie, Jr. Hawk Software http://www.hawksoft.com