ascii-chat 0.11.33
Video chat in your terminal
Loading...
Searching...
No Matches
endian.h
Go to the documentation of this file.
1
48#pragma once
49
50#include <stdint.h>
51#include "../platform/network.h"
52
66#define HOST_TO_NET_U32(val) htonl((val))
67
81#define NET_TO_HOST_U32(val) ntohl((val))
82
96#define HOST_TO_NET_U16(val) htons((val))
97
111#define NET_TO_HOST_U16(val) ntohs((val))
112
127#define CONVERT_ARRAY_HOST_TO_NET_U32(arr, count) \
128 do { \
129 for (size_t i = 0; i < (count); i++) { \
130 (arr)[i] = htonl((arr)[i]); \
131 } \
132 } while (0)
133
149#define CONVERT_ARRAY_NET_TO_HOST_U32(arr, count) \
150 do { \
151 for (size_t i = 0; i < (count); i++) { \
152 (arr)[i] = ntohl((arr)[i]); \
153 } \
154 } while (0)
155
163static inline uint32_t endian_unpack_u32(uint32_t val) {
164 return ntohl(val);
165}
166
174static inline uint16_t endian_unpack_u16(uint16_t val) {
175 return ntohs(val);
176}
177
185static inline uint32_t endian_pack_u32(uint32_t val) {
186 return htonl(val);
187}
188
196static inline uint16_t endian_pack_u16(uint16_t val) {
197 return htons(val);
198}
199
213#define HOST_TO_NET_U64(val) htonll((val))
214
228#define NET_TO_HOST_U64(val) ntohll((val))
229
237static inline uint64_t endian_unpack_u64(uint64_t val) {
238 return ntohll(val);
239}
240
248static inline uint64_t endian_pack_u64(uint64_t val) {
249 return htonll(val);
250}
unsigned short uint16_t
Definition common.h:57
unsigned int uint32_t
Definition common.h:58
unsigned long long uint64_t
Definition common.h:59
#define ntohll(x)