26 #include <arpa/inet.h>
39 #ifndef LT_BYTESWAP_H_
40 #define LT_BYTESWAP_H_
70 #if __BYTE_ORDER == __BIG_ENDIAN
71 #define bswap_host_to_be64(num) ((uint64_t)(num))
72 #define bswap_host_to_le64(num) byteswap64(num)
73 #define bswap_host_to_be32(num) ((uint32_t)(num))
74 #define bswap_host_to_le32(num) byteswap32(num)
75 #define bswap_host_to_be16(num) ((uint16_t)(num))
76 #define bswap_host_to_le16(num) byteswap16(num)
78 #define bswap_be_to_host64(num) ((uint64_t)(num))
79 #define bswap_le_to_host64(num) byteswap64(num)
80 #define bswap_be_to_host32(num) ((uint32_t)(num))
81 #define bswap_le_to_host32(num) byteswap32(num)
82 #define bswap_be_to_host16(num) ((uint16_t)(num))
83 #define bswap_le_to_host16(num) byteswap16(num)
88 #elif __BYTE_ORDER == __LITTLE_ENDIAN
89 #define bswap_host_to_be64(num) (byteswap64(num))
90 #define bswap_host_to_le64(num) ((uint64_t)(num))
91 #define bswap_host_to_be32(num) (htonl(num))
92 #define bswap_host_to_le32(num) ((uint32_t)(num))
93 #define bswap_host_to_be16(num) (htons(num))
94 #define bswap_host_to_le16(num) ((uint16_t)(num))
96 #define bswap_be_to_host64(num) (byteswap64(num))
97 #define bswap_le_to_host64(num) ((uint64_t)(num))
98 #define bswap_be_to_host32(num) (ntohl(num))
99 #define bswap_le_to_host32(num) ((uint32_t)(num))
100 #define bswap_be_to_host16(num) (ntohs(num))
101 #define bswap_le_to_host16(num) ((uint16_t)(num))
104 #error "Unknown byte order"
uint32_t byteswap32(uint32_t num)
Byteswaps a 32-bit value.
Definition: byteswap.c:35
uint64_t byteswap64(uint64_t num)
Byteswaps a 64-bit value.
Definition: byteswap.c:29
uint16_t byteswap16(uint16_t num)
Byteswaps a 16-bit value.
Definition: byteswap.c:43