Re: socket(,,protocol): when htons?
From: Phil Frisbie, Jr. (phil_at_hawksoft.com)
Date: 10/12/05
- Next message: rahul8143_at_gmail.com: "SSh usage"
- Previous message: rahul8143_at_gmail.com: "ethernet card setup problem"
- In reply to: Sam Steingold: "Re: socket(,,protocol): when htons?"
- Next in thread: Sam Steingold: "Re: socket(,,protocol): when htons?"
- Reply: Sam Steingold: "Re: socket(,,protocol): when htons?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 12 Oct 2005 16:21:19 GMT
Sam Steingold wrote:
>>* Phil Frisbie, Jr. <cuvy@unjxfbsg.pbz> [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
>>> socket(,,htons(ETH_P_ALL));
>>>and
>>> socket(,,IPPROTO_TCP);
>>>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
- Next message: rahul8143_at_gmail.com: "SSh usage"
- Previous message: rahul8143_at_gmail.com: "ethernet card setup problem"
- In reply to: Sam Steingold: "Re: socket(,,protocol): when htons?"
- Next in thread: Sam Steingold: "Re: socket(,,protocol): when htons?"
- Reply: Sam Steingold: "Re: socket(,,protocol): when htons?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]