Thread (1 message) 1 message, 1 author, 2001-01-06

Re: Endianness and comparing IP's

From: drscholl <hidden>
Date: 2001-01-06 22:14:07

On Sat, Jan 06, 2001 at 12:22:33AM +0000, Iain Sandoe wrote:
more to the point is that there are a set of macros/functions designed for
this purpose (try man htons)... which avoids thinking to hard about
transferring between endian-ness of machines.

I'm not sure why the BSWAP32 is being used instead of one of the network
macros... maybe a red-herring but...
Unfortunately Napster, Inc. chose to use little-endian format IP addresses
in the protocol, so the traditional htonl() macros aren't useful in
this case.  What gets stored in the context for the connection is the
little-endian version so that each time the ip address is sent as part
of the protocol, there is no need for bit manipulation.  The particular check
that Alex set has the IP address in network byte order (from the
gethostbyname() call), so its *required* that the bits be swapped to check
against what is stored in the context.

All of the ints in question are unsigned, so there isn't an issue of
conversion (I beleive gcc -W -Wall -pedantic would have warned if you
tried to do a comparison of different types, anyway).

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help