Fix: Define tc_htonl/tc_htons as macros before winsock2.h to avoid struct-in_addr redefinition
This commit is contained in:
1 parent
8cb05da11c
commit
6284a95267
1 file changed
+8
-1
@@ -6,6 +6,12 @@
|
||||
#define PLATFORM_COMPAT_H
|
||||
|
||||
#ifdef _WIN32
|
||||
// Portable byte-order: must be first, before winsock2.h defines anything
|
||||
#define tc_htons(x) ((uint16_t)(((uint16_t)(x) & 0xFFU) << 8) | (((uint16_t)(x) & 0xFF00U) >> 8))
|
||||
#define tc_htonl(x) ((((uint32_t)(x) & 0x000000FFU) << 24) | (((uint32_t)(x) & 0x0000FF00U) << 8) | (((uint32_t)(x) & 0x00FF0000U) >> 8) | (((uint32_t)(x) & 0xFF000000U) >> 24))
|
||||
#define tc_ntohs(x) tc_htons(x)
|
||||
#define tc_ntohl(x) tc_htonl(x)
|
||||
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
#include <windows.h>
|
||||
@@ -153,11 +159,12 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
// Portable byte-order: no winsock2, no struct in_addr, pure C
|
||||
#ifndef tc_htons
|
||||
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)
|
||||
#endif
|
||||
|
||||
// Generate cryptographically secure random bytes
|
||||
// Returns 0 on success, -1 on error
|
||||
|
||||
Reference in new issue
Block a user