diff --git a/src/edge.c b/src/edge.c index e1b868a..f8b7bdc 100644 --- a/src/edge.c +++ b/src/edge.c @@ -43,8 +43,7 @@ #include "uthash.h" // for UT_hash_handle, HASH_ADD, HASH_C... #ifdef _WIN32 -#include -#include +#include "win32/defs.h" #else #include // for inet_addr, inet_ntop #include // for INADDR_ANY, INADDR_NONE, ntohl diff --git a/src/edge_management.c b/src/edge_management.c index 4884525..27d9ca9 100644 --- a/src/edge_management.c +++ b/src/edge_management.c @@ -36,8 +36,7 @@ #include "uthash.h" // for UT_hash_handle, HASH_ITER #ifdef _WIN32 -#include -#include +#include "win32/defs.h" #else #include // for inet_ntoa #include // for in_addr, htonl, in_addr_t diff --git a/src/edge_utils.c b/src/edge_utils.c index 2f784df..9592e51 100644 --- a/src/edge_utils.c +++ b/src/edge_utils.c @@ -41,8 +41,7 @@ #include "uthash.h" // for UT_hash_handle, HASH_COUNT, HASH... #ifdef _WIN32 -#include -#include +#include "win32/defs.h" #include "win32/edge_utils_win32.h" #else #include // for inet_ntoa, inet_addr, inet_ntop diff --git a/src/management.c b/src/management.c index 0aa73b3..a36f084 100644 --- a/src/management.c +++ b/src/management.c @@ -12,7 +12,9 @@ #include "management.h" #include "n2n.h" // for TRACE_DEBUG, traceEvent -#ifndef _WIN32 +#ifdef _WIN32 +#include "win32/defs.h" +#else #include // for getnameinfo, NI_NUMERICHOST, NI_NUMERICSERV #include // for sendto, sockaddr #endif diff --git a/src/n2n.c b/src/n2n.c index 938fbb1..5d48ebf 100644 --- a/src/n2n.c +++ b/src/n2n.c @@ -35,9 +35,8 @@ #endif #ifdef _WIN32 -#include +#include "win32/defs.h" #include -#include #else #include // for inet_ntop #include // for addrinfo, freeaddrinfo, gai_strerror diff --git a/src/network_traffic_filter.c b/src/network_traffic_filter.c index ec840a0..04703cd 100644 --- a/src/network_traffic_filter.c +++ b/src/network_traffic_filter.c @@ -26,8 +26,7 @@ #include "uthash.h" // for UT_hash_handle, HASH_ITER, HASH_DEL #ifdef _WIN32 -#include -#include +#include "win32/defs.h" #else #include // for inet_ntoa, inet_addr #include // for in_addr, in_addr_t, ntohs, ntohl diff --git a/src/sn_management.c b/src/sn_management.c index 7b3abe4..00f8773 100644 --- a/src/sn_management.c +++ b/src/sn_management.c @@ -36,7 +36,7 @@ #include "uthash.h" // for UT_hash_handle, HASH_ITER, HASH_COUNT #ifdef _WIN32 -#include +#include "win32/defs.h" #else #include // for sendto, socklen_t #endif diff --git a/src/sn_utils.c b/src/sn_utils.c index f6092fe..62ca053 100644 --- a/src/sn_utils.c +++ b/src/sn_utils.c @@ -41,8 +41,7 @@ #include "uthash.h" // for UT_hash_handle, HASH_ITER, HASH_DEL #ifdef _WIN32 -#include -#include +#include "win32/defs.h" #else #include // for inet_addr, inet_ntoa #include // for ntohl, in_addr_t, sockaddr_in, INADDR... diff --git a/src/supernode.c b/src/supernode.c index 8d39a4c..831dbc0 100644 --- a/src/supernode.c +++ b/src/supernode.c @@ -36,8 +36,7 @@ #include "uthash.h" // for UT_hash_handle, HASH_ITER, HASH_ADD_STR #ifdef _WIN32 -#include -#include +#include "win32/defs.h" #else #include // for inet_addr #include // for ntohl, INADDR_ANY, INADDR_NONE, in_addr_t diff --git a/src/win32/defs.h b/src/win32/defs.h new file mode 100644 index 0000000..b2fd3bb --- /dev/null +++ b/src/win32/defs.h @@ -0,0 +1,27 @@ +/* + * Basic definitions needed for any windows compile + * + */ + +#ifndef _WIN32_DEFS_H_ +#define _WIN32_DEFS_H_ + +#ifndef _CRT_SECURE_NO_WARNINGS +#define _CRT_SECURE_NO_WARNINGS +#endif + +#define WIN32_LEAN_AND_MEAN + +#ifndef _WIN64 +/* needs to be defined before winsock gets included */ +#undef _WIN32_WINNT +#define _WIN32_WINNT 0x501 + +const char *subst_inet_ntop (int, const void *, char *, int); +#define inet_ntop subst_inet_ntop +#endif + +#include +#include + +#endif diff --git a/src/win32/edge_utils_win32.c b/src/win32/edge_utils_win32.c index 1ce6f21..d110573 100644 --- a/src/win32/edge_utils_win32.c +++ b/src/win32/edge_utils_win32.c @@ -16,7 +16,7 @@ * */ -#include +#include "defs.h" #include #include "edge_utils_win32.h" @@ -28,7 +28,7 @@ * This function was not included in windows until after Windows XP */ -const char *inet_ntop (int af, const void *src, char *dst, socklen_t size) { +const char *subst_inet_ntop (int af, const void *src, char *dst, int size) { if(af == AF_INET) { struct sockaddr_in in; memset(&in, 0, sizeof(in)); diff --git a/src/win32/n2n_win32.h b/src/win32/n2n_win32.h index e1a0104..6d6d5ba 100644 --- a/src/win32/n2n_win32.h +++ b/src/win32/n2n_win32.h @@ -7,21 +7,6 @@ #ifndef _N2N_WIN32_H_ #define _N2N_WIN32_H_ -#ifndef _CRT_SECURE_NO_WARNINGS -#define _CRT_SECURE_NO_WARNINGS -#endif - -#define WIN32_LEAN_AND_MEAN - -#if defined(__MINGW32__) -/* should be defined here and before winsock gets included */ -#ifndef _WIN32_WINNT -#define _WIN32_WINNT 0x501 //Otherwise the linker doesnt find getaddrinfo -#endif /* #ifndef _WIN32_WINNT */ -#include -#endif /* #if defined(__MINGW32__) */ - - #include #include #include diff --git a/src/win32/wintap.c b/src/win32/wintap.c index 4b2aa03..21ab977 100644 --- a/src/win32/wintap.c +++ b/src/win32/wintap.c @@ -2,8 +2,8 @@ (C) 2007-22 - Luca Deri */ +#include "defs.h" #ifndef _WIN64 -#include #include #endif diff --git a/src/wire.c b/src/wire.c index 995efe8..537ae15 100644 --- a/src/wire.c +++ b/src/wire.c @@ -34,8 +34,7 @@ #include "n2n_wire.h" // for decode_PACKET, decode_PEER_INFO, decode_QUER... #ifdef _WIN32 -#include -#include +#include "win32/defs.h" #else #include // for sockaddr_in, sockaddr_in6, in6_addr, in_addr #include // for AF_INET, AF_INET6, SOCK_STREAM, SOCK_DGRAM