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;
2) however, the other versions are potentially of use when extracting
known-to-be-little-endian values from packets (and if there's ever an
SMB decoder in Ethereal, it'll be extracting a lot of
known-to-be-little-endian values from packets...);
3) "LITTLE_ENDIAN" and "BIG_ENDIAN" need to have different values in
order to make tests such as
#if BYTE_ORDER == LITTLE_ENDIAN
and
#if BYTE_ORDER == BIG_ENDIAN
work.
One might, instead, just want to use #ifdef WORDS_BIGENDIAN....
*** packet.h 1998/10/03 08:30:40 1.10
--- packet.h 1998/10/03 08:59:56
***************
*** 32,38 ****
* Handy for
*/
- #if BYTE_ORDER == LITTLE_ENDIAN
#define pntohs(p) ((guint16) \
((guint16)*((guint8 *)p+0)<<8| \
(guint16)*((guint8 *)p+1)<<0))
--- 32,37 ----
***************
*** 41,56 ****
(guint32)*((guint8 *)p+1)<<16| \
(guint32)*((guint8 *)p+2)<<8| \
(guint32)*((guint8 *)p+3)<<0)
- #else /* BIG_ENDIAN */
- #define pntohs(p) ((guint16) \
- ((guint16)*((guint8 *)p+1)<<8| \
- (guint16)*((guint8 *)p+0)<<0))
! #define pntohl(p) ((guint32)*((guint8 *)p+3)<<24| \
! (guint32)*((guint8 *)p+2)<<16| \
! (guint32)*((guint8 *)p+1)<<8| \
! (guint32)*((guint8 *)p+0)<<0)
! #endif /* LITTLE_ENDIAN */
/* Useful when highlighting regions inside a dissect_*() function. With this
* macro, you can highlight from the start of the packet to the end of the
--- 40,55 ----
(guint32)*((guint8 *)p+1)<<16| \
(guint32)*((guint8 *)p+2)<<8| \
(guint32)*((guint8 *)p+3)<<0)
! /* Similar routines, but for extracting little-endian data. */
! #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)
/* Useful when highlighting regions inside a dissect_*() function. With this
* macro, you can highlight from the start of the packet to the end of the
*** ethereal.h 1998/09/27 04:09:29 1.4
--- ethereal.h 1998/10/03 09:00:37
***************
*** 48,54 ****
/* Byte ordering */
#ifndef BYTE_ORDER
! #define LITTLE_ENDIAN 1234
#define BIG_ENDIAN 1234
#ifdef WORDS_BIGENDIAN
#define BYTE_ORDER BIG_ENDIAN
--- 48,54 ----
/* Byte ordering */
#ifndef BYTE_ORDER
! #define LITTLE_ENDIAN 4321
#define BIG_ENDIAN 1234
#ifdef WORDS_BIGENDIAN
#define BYTE_ORDER BIG_ENDIAN