The keyboard of Laurent Deniel wrote:
>
> Guy Harris wrote:
> >
> > 1) "pntohs()" and "pntohl()", if they work by extracting individual
> > bytes and shifting-and-ORing them (which is how they work), are
> > independent of the byte order of the underlying machine - there's no
> > need for separate versions for big-endian and little-endian machines;
> >
>
> This is wrong.
>
Oups, sorry, I should not write things like this long after my bed time ;-)
#define pntohs(p) ((guint16) \
((guint16)*((guint8 *)p+0)<<8| \
(guint16)*((guint8 *)p+1)<<0))
#define pntohl(p) ((guint32)*((guint8 *)p+0)<<24| \
(guint32)*((guint8 *)p+1)<<16| \
(guint32)*((guint8 *)p+2)<<8| \
(guint32)*((guint8 *)p+3)<<0)
Those macros are correct when used to extract BIG_ENDIAN numbers to
a host representation (whatever the host endianness is).
#define pletohs(p) ((guint16) \
((guint16)*((guint8 *)p+1)<<8| \
(guint16)*((guint8 *)p+0)<<0))
#define pletohl(p) ((guint32)*((guint8 *)p+3)<<24| \
(guint32)*((guint8 *)p+2)<<16| \
(guint32)*((guint8 *)p+1)<<8| \
(guint32)*((guint8 *)p+0)<<0)
Those macros can be added to extract LITTLE_ENDIAN numbers to
a host representation (whatever the host endianness is).
> > 3) "LITTLE_ENDIAN" and "BIG_ENDIAN" need to have different values in
> > order to make tests such as
> >
> ok
>
Yes this should also be fixed.
Laurent.
--
Laurent DENIEL | E-mail: deniel@xxxxxxxxxxx
Paris, FRANCE | deniel@xxxxxxxxxxxxxxxxxxxxxxxxxxxx
| WWW : http://www.worldnet.fr/~deniel
All above opinions are personal, unless stated otherwise.