Endianness and comparing IP's
Quoted 9 lines · drscholl
Quoted 6 lines
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,
sheesh...
Quoted 7 lines
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 thegethostbyname()call), so its *required* that the bits be swapped to check against what is stored in the context.
fair enough. (I did admit it might be a red-herring ;-)
Quoted 3 lines
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).
probably (but it wouldn't be difficult to check that anyway).
What is the code for the BSWAP32 macro?
...and what asm does it produce?
(or does it use __asm() statements?)
(or are you convinced it is OK?)
Iain.
** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/
Quoted 5 lines · Iain Sandoe
Quoted 3 lines
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).
probably (but it wouldn't be difficult to check that anyway).
Yes, I did verify that they are all unsigned int, not just relying on that. :-)
Quoted 3 lines
What is the code for the BSWAP32 macro?
...and what asm does it produce?
(or does it use__asm()statements?)
/* convert the bytes of a 32-bit integer to little endian */ #define BSWAP32(c) ((c>>24)&0xff)|((c>>8)&0xff00)|((c<<8)&0xff0000)|(c<<24)
Quoted 1 line
(or are you convinced it is OK?)
Seems to work fine under Solaris, otherwise nobody would be able to download anything because the IP address would be reversed.
** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/