网络大小端转换函数
//*****************************************************************************
//
// htonl/ntohl - big endian/little endian byte swapping macros for
// 32-bit (long) values
//
//*****************************************************************************
#ifndef htonl
static uint32_t
htonl(uint32_t a)
{
return ((a >> 24) & 0x000000ff) |
((a >> 8) & 0x0000ff00) |
((a << 8) & 0x00ff0000) |
((a << 24) & 0xff000000);
}
#endif
#ifndef ntohl
#define ntohl(a) htonl((a))
#endif
//*****************************************************************************
//
// htons/ntohs - big endian/little endian byte swapping macros for
// 16-bit (short) values
//
//*****************************************************************************
#ifndef htons
static uint16_t
htons(uint16_t a)
{
return ((a >> 8) & 0x00ff) | ((a << 8) & 0xff00);
}
#endif
#ifndef ntohs
#define ntohs(a) htons((a))
#endif