ascii-chat
0.6.0
Real-time terminal-based video chat with ASCII art conversion
Loading...
Searching...
No Matches
endian.h
Go to the documentation of this file.
1
48
#pragma once
49
50
#include <stdint.h>
51
52
#ifdef _WIN32
53
#include <winsock2.h>
54
#else
55
#include <netinet/in.h>
56
#endif
57
71
#define HOST_TO_NET_U32(val) htonl((val))
72
86
#define NET_TO_HOST_U32(val) ntohl((val))
87
101
#define HOST_TO_NET_U16(val) htons((val))
102
116
#define NET_TO_HOST_U16(val) ntohs((val))
117
132
#define CONVERT_ARRAY_HOST_TO_NET_U32(arr, count) \
133
do { \
134
for (size_t i = 0; i < (count); i++) { \
135
(arr)[i] = htonl((arr)[i]); \
136
} \
137
} while (0)
138
154
#define CONVERT_ARRAY_NET_TO_HOST_U32(arr, count) \
155
do { \
156
for (size_t i = 0; i < (count); i++) { \
157
(arr)[i] = ntohl((arr)[i]); \
158
} \
159
} while (0)
160
168
static
inline
uint32_t
endian_unpack_u32(
uint32_t
val) {
169
return
ntohl(val);
170
}
171
179
static
inline
uint16_t
endian_unpack_u16(
uint16_t
val) {
180
return
ntohs(val);
181
}
182
190
static
inline
uint32_t
endian_pack_u32(
uint32_t
val) {
191
return
htonl(val);
192
}
193
201
static
inline
uint16_t
endian_pack_u16(
uint16_t
val) {
202
return
htons(val);
203
}
uint16_t
unsigned short uint16_t
Definition
common.h:57
uint32_t
unsigned int uint32_t
Definition
common.h:58
lib
util
endian.h
Generated by
1.9.8