On 6/9/13 7:20 PM, Michael Rash wrote: > On Jun 09, 2013, Michael Rash wrote: > >> On Jun 09, 2013, Blair Zajac wrote: >> >>> On 6/9/13 3:29 PM, Blair Zajac wrote: >>>> I recalled that PPC is big endian so hacked the below patch in and was >>>> able to get fwknop to work. I wouldn't use the patch for a good commit, >>>> as it doesn't support 64-bit PPC systems and its duplicated across two >>>> files. >>> >>> BTW, this is on Mac OS X 10.5.8 and the OS doesn't define BYTEORDER in a >>> standard header (I don't count ffi/*.h as standard headers): >>> >>> $ find /usr/include -type f | xargs grep BYTEORDER >>> /usr/include/ffi/fficonfig.h:# define BYTEORDER 1234 >>> /usr/include/ffi/fficonfig.h:# define BYTEORDER 1234 >>> /usr/include/ffi/fficonfig.h:# define BYTEORDER 4321 >>> /usr/include/ffi/fficonfig.h:# define BYTEORDER 4321 >>> /usr/include/libkern/_OSByteOrder.h:#ifndef _OS__OSBYTEORDER_H >>> /usr/include/libkern/_OSByteOrder.h:#define _OS__OSBYTEORDER_H >>> /usr/include/libkern/_OSByteOrder.h:#endif /* ! _OS__OSBYTEORDER_H */ >>> /usr/include/libkern/i386/_OSByteOrder.h:#ifndef _OS__OSBYTEORDERI386_H >>> /usr/include/libkern/i386/_OSByteOrder.h:#define _OS__OSBYTEORDERI386_H >>> /usr/include/libkern/i386/_OSByteOrder.h:#endif /* ! >>> _OS__OSBYTEORDERI386_H */ >>> /usr/include/libkern/i386/OSByteOrder.h:#ifndef _OS_OSBYTEORDERI386_H >>> /usr/include/libkern/i386/OSByteOrder.h:#define _OS_OSBYTEORDERI386_H >>> /usr/include/libkern/i386/OSByteOrder.h:#endif /* ! _OS_OSBYTEORDERI386_H */ >>> /usr/include/libkern/machine/OSByteOrder.h:#ifndef _OS_OSBYTEORDERMACHINE_H >>> /usr/include/libkern/machine/OSByteOrder.h:#define _OS_OSBYTEORDERMACHINE_H >>> /usr/include/libkern/machine/OSByteOrder.h:#endif /* ! >>> _OS_OSBYTEORDERMACHINE_H */ >>> /usr/include/libkern/OSByteOrder.h:#ifndef _OS_OSBYTEORDER_H >>> /usr/include/libkern/OSByteOrder.h:#define _OS_OSBYTEORDER_H >>> /usr/include/libkern/OSByteOrder.h:#endif /* ! _OS_OSBYTEORDER_H */ >>> /usr/include/libkern/ppc/OSByteOrder.h:#ifndef _OS_OSBYTEORDERPPC_H >>> /usr/include/libkern/ppc/OSByteOrder.h:#define _OS_OSBYTEORDERPPC_H >>> /usr/include/libkern/ppc/OSByteOrder.h:#endif /* ! _OS_OSBYTEORDERPPC_H */ >>> /usr/include/sys/sysctl.h:#define HW_BYTEORDER 4 /* int: >>> machine byte >>> order */ >> >> Interesting, and thanks for the bug report for PPC systems. Seems like >> fwknop could have a more generic way of making a guess for an endian >> value. There is a section of code in lib/fko_common.h that does some of >> this, but I think it could be extended: >> >> http://www.cipherdyne.org/cgi-bin/gitweb.cgi?p=fwknop.git;a=blob;f=lib/fko_common.h;h=24bb14c1bbc18d44c1927f1af440bf473d533269;hb=refs/heads/master#l91 >> >> For example, does your system have either _BIG_ENDIAN or __BIG_ENDIAN__ >> defined? If so, would the following patch work (which only defines >> BYTEORDER if all other current measures have failed and then forces a >> compile warning if this also fails)?:
Yes, either __BIG_ENDIAN__ or __LITTLE_ENDIAN__ is defined by the compiler with no include files. The following prints either BIG or LITTLE if run through `gcc -E` #ifdef __BIG_ENDIAN__ BIG #endif #ifdef __LITTLE_ENDIAN__ LITTLE #endif > Or, a bit more elegantly: > > diff --git a/lib/fko_common.h b/lib/fko_common.h > index 24bb14c..40f1c5b 100644 > --- a/lib/fko_common.h > +++ b/lib/fko_common.h > @@ -103,6 +103,12 @@ > #else > #error unable to determine BYTEORDER > #endif > +#elif defined(_BIG_ENDIAN) || defined(__BIG_ENDIAN__) > + #define BYTEORDER 4321 > +#elif defined(_LITTLE_ENDIAN) || defined(__LITTLE_ENDIAN__) > + #define BYTEORDER 1234 > +#else > + #error unable to determine BYTEORDER This presumes a 32- bit architecture though, since there's code in lib/sha1.c that checks if BTYEORDER is 12345678 or 87654321. I think one could check for __ppc__ and __i386__ for 32-bit and __ppc64__ and __x86_64__ for 64-bit. If you don't have any of __ppc__, __i386__, __ppc64__ or __x86_64__ defined then one could error. Blair ------------------------------------------------------------------------------ How ServiceNow helps IT people transform IT departments: 1. A cloud service to automate IT design, transition and operations 2. Dashboards that offer high-level views of enterprise services 3. A single system of record for all IT processes http://p.sf.net/sfu/servicenow-d2d-j _______________________________________________ Fwknop-discuss mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/fwknop-discuss
