PDA

View Full Version : what is diffrence ???


alokdotnet
09-07-2004, 06:40 PM
Hi all geeks,
just tell me what is diffrence bwteen these two fiunction
htons(); and htonl();

RobSeace
09-07-2004, 07:14 PM
The first works with 16-bit "shorts" (hence the "s" suffix), and the
latter works with 32-bit "longs" (hence the "l" suffix)... Both convert
from host byte-order to network byte-order... And, of course, there
are companion inverse functions: ntohs() and ntohl(), which convert
from network to host byte-order... (The "short" vs. "long" naming
is a fairly poor choice, since when we all move to 64-bit systems,
"long" will be 64-bit... But, they really have to keep htonl() working
on 32-bit data, unless they want to break all network code everwhere...
A more logical naming scheme would be hton16(), hton32(), etc...)

i3839
09-07-2004, 07:15 PM
htons(); host to network short.
htonl(); host to network long.

The first one swaps shorts (16 bits) and the second one longs (32 bits). The 'long' isn't always appropriate, because a long can be 64 bit too on certain architectures, but the network htonl() works only with 32 bit 'longs'.