Skip to content

Commit

Permalink
Concentrate more windows wierdness in one place - allowing proper ord…
Browse files Browse the repository at this point in the history
…ering of crazy defs and includes
  • Loading branch information
hamishcoleman committed Aug 3, 2023
1 parent 65359c7 commit f791531
Show file tree
Hide file tree
Showing 14 changed files with 42 additions and 36 deletions.
3 changes: 1 addition & 2 deletions src/edge.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@
#include "uthash.h" // for UT_hash_handle, HASH_ADD, HASH_C...

#ifdef _WIN32
#include <winsock2.h>
#include <ws2tcpip.h>
#include "win32/defs.h"
#else
#include <arpa/inet.h> // for inet_addr, inet_ntop
#include <netinet/in.h> // for INADDR_ANY, INADDR_NONE, ntohl
Expand Down
3 changes: 1 addition & 2 deletions src/edge_management.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@
#include "uthash.h" // for UT_hash_handle, HASH_ITER

#ifdef _WIN32
#include <winsock2.h>
#include <ws2tcpip.h>
#include "win32/defs.h"
#else
#include <arpa/inet.h> // for inet_ntoa
#include <netinet/in.h> // for in_addr, htonl, in_addr_t
Expand Down
3 changes: 1 addition & 2 deletions src/edge_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@
#include "uthash.h" // for UT_hash_handle, HASH_COUNT, HASH...

#ifdef _WIN32
#include <winsock2.h>
#include <ws2tcpip.h>
#include "win32/defs.h"
#include "win32/edge_utils_win32.h"
#else
#include <arpa/inet.h> // for inet_ntoa, inet_addr, inet_ntop
Expand Down
4 changes: 3 additions & 1 deletion src/management.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
#include "management.h"
#include "n2n.h" // for TRACE_DEBUG, traceEvent

#ifndef _WIN32
#ifdef _WIN32
#include "win32/defs.h"
#else
#include <netdb.h> // for getnameinfo, NI_NUMERICHOST, NI_NUMERICSERV
#include <sys/socket.h> // for sendto, sockaddr
#endif
Expand Down
3 changes: 1 addition & 2 deletions src/n2n.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@
#endif

#ifdef _WIN32
#include <winsock2.h>
#include "win32/defs.h"
#include <ws2def.h>
#include <ws2tcpip.h>
#else
#include <arpa/inet.h> // for inet_ntop
#include <netdb.h> // for addrinfo, freeaddrinfo, gai_strerror
Expand Down
3 changes: 1 addition & 2 deletions src/network_traffic_filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
#include "uthash.h" // for UT_hash_handle, HASH_ITER, HASH_DEL

#ifdef _WIN32
#include <winsock2.h>
#include <ws2tcpip.h>
#include "win32/defs.h"
#else
#include <arpa/inet.h> // for inet_ntoa, inet_addr
#include <netinet/in.h> // for in_addr, in_addr_t, ntohs, ntohl
Expand Down
2 changes: 1 addition & 1 deletion src/sn_management.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#include "uthash.h" // for UT_hash_handle, HASH_ITER, HASH_COUNT

#ifdef _WIN32
#include <winsock2.h>
#include "win32/defs.h"
#else
#include <sys/socket.h> // for sendto, socklen_t
#endif
Expand Down
3 changes: 1 addition & 2 deletions src/sn_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@
#include "uthash.h" // for UT_hash_handle, HASH_ITER, HASH_DEL

#ifdef _WIN32
#include <winsock2.h>
#include <ws2tcpip.h>
#include "win32/defs.h"
#else
#include <arpa/inet.h> // for inet_addr, inet_ntoa
#include <netinet/in.h> // for ntohl, in_addr_t, sockaddr_in, INADDR...
Expand Down
3 changes: 1 addition & 2 deletions src/supernode.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@
#include "uthash.h" // for UT_hash_handle, HASH_ITER, HASH_ADD_STR

#ifdef _WIN32
#include <winsock2.h>
#include <ws2tcpip.h>
#include "win32/defs.h"
#else
#include <arpa/inet.h> // for inet_addr
#include <netinet/in.h> // for ntohl, INADDR_ANY, INADDR_NONE, in_addr_t
Expand Down
27 changes: 27 additions & 0 deletions src/win32/defs.h
Original file line number Diff line number Diff line change
@@ -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 <winsock2.h>
#include <ws2tcpip.h>

#endif
4 changes: 2 additions & 2 deletions src/win32/edge_utils_win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*
*/

#include <winsock2.h>
#include "defs.h"
#include <iphlpapi.h>

#include "edge_utils_win32.h"
Expand All @@ -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));
Expand Down
15 changes: 0 additions & 15 deletions src/win32/n2n_win32.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <inttypes.h>
#endif /* #if defined(__MINGW32__) */


#include <winsock2.h>
#include <windows.h>
#include <ws2def.h>
Expand Down
2 changes: 1 addition & 1 deletion src/win32/wintap.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
(C) 2007-22 - Luca Deri <deri@ntop.org>
*/

#include "defs.h"
#ifndef _WIN64
#include <winsock2.h>
#include <iphlpapi.h>
#endif

Expand Down
3 changes: 1 addition & 2 deletions src/wire.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@
#include "n2n_wire.h" // for decode_PACKET, decode_PEER_INFO, decode_QUER...

#ifdef _WIN32
#include <winsock2.h>
#include <ws2tcpip.h>
#include "win32/defs.h"
#else
#include <netinet/in.h> // for sockaddr_in, sockaddr_in6, in6_addr, in_addr
#include <sys/socket.h> // for AF_INET, AF_INET6, SOCK_STREAM, SOCK_DGRAM
Expand Down

0 comments on commit f791531

Please sign in to comment.