#include unsigned short my_htons( unsigned short hostshort ) { return( ((hostshort >> 8) & 0xff) | (hostshort & 0xff) << 8 ); } unsigned long my_htonl( unsigned long hostlong ) { return( ((hostlong >> 24) & 0xff) | ((hostlong >> 16) & 0xff) << 8 | ((hostlong >> 8) & 0xff) << 16 | (hostlong & 0xff) << 24 ); } /* ############################## */ #define SWAPNC_16(w) (\ (((w) & 0x000000FFUL) << 8) |\ (((w) & 0x0000FF00UL) >> 8)\ ) #define SWAPNC_32(w) (\ (((w) & 0x000000FFUL) << 24) |\ (((w) & 0x0000FF00UL) << 8) |\ (((w) & 0x00FF0000UL) >> 8) |\ (((w) & 0xFF000000UL) >> 24)\ ) #define SWAPNC_64(w) (\ (((w) & 0x00000000000000FFULL) << 56) |\ (((w) & 0x000000000000FF00ULL) << 40) |\ (((w) & 0x0000000000FF0000ULL) << 24) |\ (((w) & 0x00000000FF000000ULL) << 8) |\ (((w) & 0x000000FF00000000ULL) >> 8) |\ (((w) & 0x0000FF0000000000ULL) >> 24) |\ (((w) & 0x00FF000000000000ULL) >> 40) |\ (((w) & 0xFF00000000000000ULL) >> 56)\ ) uint16_t use_SWAPNC_16(uint16_t data) { return SWAPNC_16(data); } uint32_t use_SWAPNC_32(uint32_t data) { return SWAPNC_32(data); } uint64_t use_SWAPNC_64(uint64_t data) { return SWAPNC_64(data); } /* ############################## */ void encode_bigend_u16(uint16_t value, void *vdest) { uint8_t *bytes = (uint8_t *)vdest; bytes[0] = value >> 8; bytes[1] = value; } void encode_bigend_u32(uint32_t value, void *vdest) { uint8_t *bytes = (uint8_t *)vdest; bytes[0] = value >> 24; bytes[1] = value >> 16; bytes[2] = value >> 8; bytes[3] = value; } void encode_bigend_u64(uint64_t value, void *vdest) { uint8_t *bytes = (uint8_t *)vdest; bytes[0] = value >> 56; bytes[1] = value >> 48; bytes[2] = value >> 40; bytes[3] = value >> 32; bytes[4] = value >> 24; bytes[5] = value >> 16; bytes[6] = value >> 8; bytes[7] = value; }