#ifndef __BYTESEX_H #define __BYTESEX_H static inline u_int16_t __attribute__((const)) bswap16(u_int16_t x) { return (u_int16_t)( (((u_int16_t)(x) & (u_int16_t)0x00ffU) << 8) | (((u_int16_t)(x) & (u_int16_t)0xff00U) >> 8)); } static inline u_int32_t __attribute__((const)) bswap32(u_int32_t x) { return (u_int32_t)( (((u_int32_t)(x) & (u_int32_t)0x000000ffUL) << 24) | (((u_int32_t)(x) & (u_int32_t)0x0000ff00UL) << 8) | (((u_int32_t)(x) & (u_int32_t)0x00ff0000UL) >> 8) | (((u_int32_t)(x) & (u_int32_t)0xff000000UL) >> 24)); } #if __BYTE_ORDER == __BIG_ENDIAN #define le_32(x) bswap32(x) #define le_16(x) bswap16(x) #define be_32(x) (x) #define be_16(x) (x) #elif __BYTE_ORDER == __LITTLE_ENDIAN #define le_32(x) (x) #define le_16(x) (x) #define be_32(x) bswap32(x) #define be_16(x) bswap16(x) #else #error "What in hells name?!" #endif #endif /* __BYTESEX_H */