ascii-chat
Binary v0.16.114-28-gf5913657f
Library lib/v0.3.2-3302-gf5913657f
Video chat in your terminal
Loading...
Searching...
No Matches
endian.h
Go to the documentation of this file.
1
47
48#pragma once
49
51#include <stdint.h>
52
53#ifdef __cplusplus
54extern "C" {
55#endif
56
70#define HOST_TO_NET_U32(val) htonl((val))
71
85#define NET_TO_HOST_U32(val) ntohl((val))
86
100#define HOST_TO_NET_U16(val) htons((val))
101
115#define NET_TO_HOST_U16(val) ntohs((val))
116
131#define CONVERT_ARRAY_HOST_TO_NET_U32(arr, count) \
132 do { \
133 for (size_t i = 0; i < (count); i++) { \
134 (arr)[i] = htonl((arr)[i]); \
135 } \
136 } while (asciichat_macro_block_continue())
137
153#define CONVERT_ARRAY_NET_TO_HOST_U32(arr, count) \
154 do { \
155 for (size_t i = 0; i < (count); i++) { \
156 (arr)[i] = ntohl((arr)[i]); \
157 } \
158 } while (asciichat_macro_block_continue())
159
167static inline uint32_t endian_unpack_u32(uint32_t val) { return ntohl(val); }
168
176static inline uint16_t endian_unpack_u16(uint16_t val) { return ntohs(val); }
177
185static inline uint32_t endian_pack_u32(uint32_t val) { return htonl(val); }
186
194static inline uint16_t endian_pack_u16(uint16_t val) { return htons(val); }
195
209#define HOST_TO_NET_U64(val) htonll((val))
210
224#define NET_TO_HOST_U64(val) ntohll((val))
225
233static inline uint64_t endian_unpack_u64(uint64_t val) { return ntohll(val); }
234
242static inline uint64_t endian_pack_u64(uint64_t val) { return htonll(val); }
243
244#ifdef __cplusplus
245}
246#endif
unsigned short uint16_t
unsigned int uint32_t
unsigned long long uint64_t
#define ntohll(x)
Definition platform.h:52