Fix: Add portable tc_htonl/tc_htons/tc_ntohl/tc_ntohs macros, replace winsock2-incompatible hton*/nto* in NAT test files
This commit is contained in:
1 parent
3dd8fa4085
commit
aafa0cfcab
4 files changed
+71
-65
No files matched your search
@@ -153,6 +153,12 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
// Portable byte-order: no winsock2, no struct in_addr, pure C
|
||||
static inline uint16_t tc_htons(uint16_t x) { return (uint16_t)(((x & 0xFFU) << 8) | ((x & 0xFF00U) >> 8)); }
|
||||
static inline uint32_t tc_htonl(uint32_t x) { return (((x & 0x000000FFU) << 24) | ((x & 0x0000FF00U) << 8) | ((x & 0x00FF0000U) >> 8) | ((x & 0xFF000000U) >> 24)); }
|
||||
#define tc_ntohs(x) tc_htons(x)
|
||||
#define tc_ntohl(x) tc_htonl(x)
|
||||
|
||||
// Generate cryptographically secure random bytes
|
||||
// Returns 0 on success, -1 on error
|
||||
int random_bytes(uint8_t *buffer, size_t len);
|
||||
|
||||
Reference in new issue
Block a user