how is the byteorder stuff supposed to work?

Carter Bullard carter at qosient.com
Wed Mar 14 15:25:41 EDT 2007


Need  a problem to solve.  I don't think this is a problem
Carter


On Mar 14, 2007, at 1:49 PM, Christoph Badura wrote:

> Hey Carter,
>
> while looking for potential byte order issues I found the following  
> code
> in include/compat.h:
>
> #if defined(CYGWIN)
> #define _LITTLE_ENDIAN
> #define USE_IPV6
> #else
>
> #if (__FreeBSD__)
> #if defined(BYTE_ORDER)
> #define __BYTE_ORDER    BYTE_ORDER
> #endif
> #if defined(LITTLE_ENDIAN)
> #define __LITTLE_ENDIAN LITTLE_ENDIAN
> #endif
> #if defined(BIG_ENDIAN)
> #define __BIG_ENDIAN    BIG_ENDIAN
> #endif
> #endif
>
> #if !defined(_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN)
> #if __BYTE_ORDER == __LITTLE_ENDIAN
> #define _LITTLE_ENDIAN
> #else
> #define _BIG_ENDIAN
> #endif
> #endif
> #endif
>
> and later you have a lot of places that check for "#ifdef  
> _LITTLE_ENDIAN"
> all over the source code.
>
> I don't understand how that is supposed to work.
>
> First there is the problem of you re-defining symbols in the  
> implementation
> namespace that you aren't supposed to touch (the ones with a single  
> underscore
> in front).
>
> Second both NetBSD (what I am using) and FreeBSD *always* define  
> _LITTLE_ENDIAN
> and _BIG_ENDIAN in system header files (sys/endian.h and machine/ 
> endian.h, but
> pulling in sys/types.h or arpa/inet.h does the job).
>
> So, _LITTLE_ENDIAN is always defined on those machines, even if  
> they are
> big-endian machines, like e.g. NetBSD/macppc or FreeBSD/sparc. So,  
> later
> testing "#ifdef _LITTLE_ENDIAN" is going to give the wrong answer.
>
> Maybe you want to use ARGUS_LITTLE_ENDIAN and ARGUS_BIG_ENDIAN and  
> change
> the above code like so:
>
> #if defined(CYGWIN)
> #define ARGUS_LITTLE_ENDIAN
> #define USE_IPV6
> #else
>
> #if defined(__FreeBSD__) || defined(__NetBSD__)
> #ifndef _BYTE_ORDER
> #error can't determine machine byte order
> #endif
> #define __BYTE_ORDER    _BYTE_ORDER
> #define __LITTLE_ENDIAN _LITTLE_ENDIAN
> #define __BIG_ENDIAN    _BIG_ENDIAN
> #endif
>
> #if __BYTE_ORDER == __LITTLE_ENDIAN
> #define ARGUS_LITTLE_ENDIAN
> #else
> #define ARGUS_BIG_ENDIAN
> #endif
>
> and change all the uses of "#ifdef _LITTLE_ENDIAN" accordingly.
>
> --chris
>

Carter Bullard
CEO/President
QoSient, LLC
150 E. 57th Street Suite 12D
New York, New York 10022

+1 212 588-9133 Phone
+1 212 588-9134 Fax


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://pairlist1.pair.net/pipermail/argus/attachments/20070314/690fc4e3/attachment.html>


More information about the argus mailing list