From 682555ffde3e43c4e75cd2f0c22efef8c6b95c26 Mon Sep 17 00:00:00 2001 From: thomasysliu Date: Tue, 3 Mar 2026 05:37:26 +0800 Subject: [PATCH] Update for MINGW windows build (#1232) Add missing header stdlib.h, iphlpapi.h Force type casting for CryptGenRandom, setsockopt, strncpy ifdef for getenv proto type --- include/portable_endian.h | 2 ++ src/random_numbers.c | 2 +- src/sn_utils.c | 2 +- src/win32/edge_utils_win32.c | 2 +- src/win32/getopt.c | 4 ++++ src/win32/wintap.c | 2 -- tools/n2n-route.c | 1 + 7 files changed, 10 insertions(+), 5 deletions(-) diff --git a/include/portable_endian.h b/include/portable_endian.h index 6b18236..4d3ce1d 100644 --- a/include/portable_endian.h +++ b/include/portable_endian.h @@ -142,6 +142,8 @@ #elif defined(__WINDOWS__) +# include + # if BYTE_ORDER == LITTLE_ENDIAN # define htobe16(x) _byteswap_ushort(x) diff --git a/src/random_numbers.c b/src/random_numbers.c index 67a1b98..1f0c7f1 100644 --- a/src/random_numbers.c +++ b/src/random_numbers.c @@ -182,7 +182,7 @@ uint64_t n2n_seed (void) { HCRYPTPROV crypto_provider; CryptAcquireContext (&crypto_provider, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT); - CryptGenRandom (crypto_provider, 8, &seed); + CryptGenRandom (crypto_provider, 8, (unsigned char*)&seed); CryptReleaseContext (crypto_provider, 0); ret += seed; #endif diff --git a/src/sn_utils.c b/src/sn_utils.c index 13ac267..5e80932 100644 --- a/src/sn_utils.c +++ b/src/sn_utils.c @@ -545,7 +545,7 @@ static ssize_t sendto_sock(n2n_sn_t *sss, // if the connection is tcp, i.e. not the regular sock... if((socket_fd >= 0) && (socket_fd != sss->sock)) { - setsockopt(socket_fd, IPPROTO_TCP, TCP_NODELAY, &value, sizeof(value)); + setsockopt(socket_fd, IPPROTO_TCP, TCP_NODELAY, (void *)&value, sizeof(value)); value = 1; #ifdef LINUX setsockopt(socket_fd, IPPROTO_TCP, TCP_CORK, &value, sizeof(value)); diff --git a/src/win32/edge_utils_win32.c b/src/win32/edge_utils_win32.c index d110573..ac09199 100644 --- a/src/win32/edge_utils_win32.c +++ b/src/win32/edge_utils_win32.c @@ -128,7 +128,7 @@ int get_best_interface_ip (n2n_edge_t * eee, dec_ip_str_t *ip_addr){ traceEvent(TRACE_DEBUG, "IP Address: %s\n", pAdapter->IpAddressList.IpAddress.String); traceEvent(TRACE_DEBUG, "IP Mask: %s\n", pAdapter->IpAddressList.IpMask.String); traceEvent(TRACE_DEBUG, "Gateway: %s\n", pAdapter->GatewayList.IpAddress.String); - strncpy(ip_addr, pAdapter->IpAddressList.IpAddress.String, sizeof(*ip_addr)); + strncpy((char *)ip_addr, pAdapter->IpAddressList.IpAddress.String, sizeof(*ip_addr)); } } else { traceEvent(TRACE_WARNING, "GetAdaptersInfo failed with error: %d\n", dwRetVal); diff --git a/src/win32/getopt.c b/src/win32/getopt.c index 3e51545..cf2367f 100644 --- a/src/win32/getopt.c +++ b/src/win32/getopt.c @@ -435,7 +435,11 @@ _getopt_initialize (argc, argv, optstring) nextchar = NULL; +#ifdef getenv posixly_correct = getenv ("POSIXLY_CORRECT"); +#else + posixly_correct = getenv (); +#endif /* Determine how to handle the ordering of options and nonoptions. */ diff --git a/src/win32/wintap.c b/src/win32/wintap.c index 21ab977..cc658bc 100644 --- a/src/win32/wintap.c +++ b/src/win32/wintap.c @@ -3,9 +3,7 @@ */ #include "defs.h" -#ifndef _WIN64 #include -#endif #include "n2n.h" #include "n2n_win32.h" diff --git a/tools/n2n-route.c b/tools/n2n-route.c index 8ff14b5..28cbf04 100644 --- a/tools/n2n-route.c +++ b/tools/n2n-route.c @@ -41,6 +41,7 @@ #ifdef _WIN32 #include #include +#include #else #include // for inet_pton #include // for if_indextoname