Browse Source

Simplify build system by using standard macro

Most environments have predefined macros that identify the environment
to the source code.  If we use these macros instead of defining our own
then there is one less parameter difference to keep track of with
different builds

cf:
    http://web.archive.org/web/20191012035921/http://nadeausoftware.com/articles/2012/01/c_c_tip_how_use_compiler_predefined_macros_detect_operating_system
    https://sourceforge.net/p/predef/wiki/OperatingSystems/
pull/1134/head
Hamish Coleman 1 year ago
parent
commit
473b89c963
  1. 2
      Makefile
  2. 14
      include/n2n.h
  3. 2
      include/n2n_define.h
  4. 14
      include/n2n_typedefs.h
  5. 6
      include/n2n_wire.h
  6. 2
      include/random_numbers.h
  7. 58
      src/edge.c
  8. 2
      src/edge_management.c
  9. 32
      src/edge_utils.c
  10. 2
      src/edge_utils_win32.c
  11. 2
      src/example_edge_embed.c
  12. 2
      src/example_sn_embed.c
  13. 2
      src/management.c
  14. 2
      src/management.h
  15. 14
      src/n2n.c
  16. 2
      src/network_traffic_filter.c
  17. 2
      src/random_numbers.c
  18. 2
      src/sn_management.c
  19. 14
      src/sn_utils.c
  20. 26
      src/supernode.c
  21. 2
      src/wire.c
  22. 6
      tools/n2n-decode.c
  23. 14
      tools/n2n-portfwd.c
  24. 28
      tools/n2n-route.c
  25. 6
      win32/getopt.c

2
Makefile

@ -169,7 +169,7 @@ LDLIBS+=-lsocket -lnsl
endif endif
ifeq ($(CONFIG_TARGET),mingw) ifeq ($(CONFIG_TARGET),mingw)
CFLAGS+=-I. -I./win32 -DWIN32 CFLAGS+=-I. -I./win32
LDLIBS+=$(abspath win32/n2n_win32.a) LDLIBS+=$(abspath win32/n2n_win32.a)
LDLIBS+=-lnetapi32 -lws2_32 -liphlpapi LDLIBS+=-lnetapi32 -lws2_32 -liphlpapi
N2N_DEPS+=win32/n2n_win32.a N2N_DEPS+=win32/n2n_win32.a

14
include/n2n.h

@ -42,12 +42,12 @@
#include "config.h" /* Visual C++ */ #include "config.h" /* Visual C++ */
/* Moved here to define _CRT_SECURE_NO_WARNINGS before all the including takes place */ /* Moved here to define _CRT_SECURE_NO_WARNINGS before all the including takes place */
#ifdef WIN32 #ifdef _WIN32
#define N2N_CAN_NAME_IFACE 1 #define N2N_CAN_NAME_IFACE 1
#undef N2N_HAVE_DAEMON #undef N2N_HAVE_DAEMON
#undef N2N_HAVE_TCP /* as explained on https://github.com/ntop/n2n/pull/627#issuecomment-782093706 */ #undef N2N_HAVE_TCP /* as explained on https://github.com/ntop/n2n/pull/627#issuecomment-782093706 */
#undef N2N_HAVE_SETUID #undef N2N_HAVE_SETUID
#endif /* WIN32 */ #endif /* _WIN32 */
#include <stdbool.h> #include <stdbool.h>
@ -55,7 +55,7 @@
#include "n2n_define.h" #include "n2n_define.h"
#include "n2n_typedefs.h" #include "n2n_typedefs.h"
#ifdef WIN32 #ifdef _WIN32
#include <winsock2.h> /* for tcp */ #include <winsock2.h> /* for tcp */
#include <lmaccess.h> /* for privilege check in tools/n2n-route */ #include <lmaccess.h> /* for privilege check in tools/n2n-route */
#include <lmapibuf.h> /* for privilege check in tools/n2n-route */ #include <lmapibuf.h> /* for privilege check in tools/n2n-route */
@ -63,9 +63,9 @@
#include <windows.h> /* for privilege check in tools/n2n-route */ #include <windows.h> /* for privilege check in tools/n2n-route */
#include "wintap.h" #include "wintap.h"
#define SHUT_RDWR SD_BOTH /* for tcp */ #define SHUT_RDWR SD_BOTH /* for tcp */
#endif /* #ifdef WIN32 */ #endif /* #ifdef _WIN32 */
#ifndef WIN32 #ifndef _WIN32
#include <netinet/in.h> // for in_addr (ptr only), in_addr_t #include <netinet/in.h> // for in_addr (ptr only), in_addr_t
#include <pwd.h> #include <pwd.h>
#include <stdint.h> // for uint8_t, uint64_t, uint32_t, uint16_t #include <stdint.h> // for uint8_t, uint64_t, uint32_t, uint16_t
@ -89,7 +89,7 @@
#include <openssl/opensslv.h> #include <openssl/opensslv.h>
#include <openssl/crypto.h> #include <openssl/crypto.h>
#endif #endif
#endif /* #ifndef WIN32 */ #endif /* #ifndef _WIN32 */
@ -129,7 +129,7 @@ void _traceEvent (int eventTraceLevel, char* file, int line, char * format, ...)
/* Tuntap API */ /* Tuntap API */
int tuntap_open (struct tuntap_dev *device, char *dev, const char *address_mode, char *device_ip, int tuntap_open (struct tuntap_dev *device, char *dev, const char *address_mode, char *device_ip,
char *device_mask, const char * device_mac, int mtu char *device_mask, const char * device_mac, int mtu
#ifdef WIN32 #ifdef _WIN32
, int metric , int metric
#endif #endif
); );

2
include/n2n_define.h

@ -190,7 +190,7 @@ enum skip_add {SN_ADD = 0, SN_ADD_SKIP = 1, SN_ADD_ADDED = 2};
#define N2N_MULTICAST_PORT 1968 #define N2N_MULTICAST_PORT 1968
#define N2N_MULTICAST_GROUP "224.0.0.68" #define N2N_MULTICAST_GROUP "224.0.0.68"
#ifdef WIN32 #ifdef _WIN32
#define N2N_IFNAMSIZ 64 #define N2N_IFNAMSIZ 64
#else #else
#define N2N_IFNAMSIZ 16 /* 15 chars * NULL */ #define N2N_IFNAMSIZ 16 /* 15 chars * NULL */

14
include/n2n_typedefs.h

@ -21,7 +21,7 @@
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> // for uint8_t and friends #include <stdint.h> // for uint8_t and friends
#ifndef WIN32 #ifndef _WIN32
#include <arpa/inet.h> // for in_addr_t #include <arpa/inet.h> // for in_addr_t
#include <sys/socket.h> // for sockaddr #include <sys/socket.h> // for sockaddr
#endif #endif
@ -84,7 +84,7 @@ typedef unsigned long in_addr_t;
#endif #endif
#endif #endif
#ifdef WIN32 #ifdef _WIN32
#ifndef __LITTLE_ENDIAN__ #ifndef __LITTLE_ENDIAN__
#define __LITTLE_ENDIAN__ 1 #define __LITTLE_ENDIAN__ 1
#endif #endif
@ -231,7 +231,7 @@ typedef char dec_ip_bit_str_t[N2N_NETMASK_STR_SIZE + 4];
typedef char devstr_t[N2N_IFNAMSIZ]; typedef char devstr_t[N2N_IFNAMSIZ];
#ifndef WIN32 #ifndef _WIN32
typedef struct tuntap_dev { typedef struct tuntap_dev {
int fd; int fd;
int if_idx; int if_idx;
@ -243,9 +243,9 @@ typedef struct tuntap_dev {
} tuntap_dev; } tuntap_dev;
#define SOCKET int #define SOCKET int
#else /* #ifndef WIN32 */ #else /* #ifndef _WIN32 */
typedef u_short sa_family_t; typedef u_short sa_family_t;
#endif /* #ifndef WIN32 */ #endif /* #ifndef _WIN32 */
typedef struct speck_context_t he_context_t; typedef struct speck_context_t he_context_t;
@ -574,7 +574,7 @@ typedef struct n2n_tuntap_priv_config {
int mtu; int mtu;
int metric; int metric;
uint8_t daemon; uint8_t daemon;
#ifndef WIN32 #ifndef _WIN32
uid_t userid; uid_t userid;
gid_t groupid; gid_t groupid;
#endif #endif
@ -849,7 +849,7 @@ typedef struct n2n_sn {
int mgmt_sock; /* management socket. */ int mgmt_sock; /* management socket. */
n2n_ip_subnet_t min_auto_ip_net; /* Address range of auto_ip service. */ n2n_ip_subnet_t min_auto_ip_net; /* Address range of auto_ip service. */
n2n_ip_subnet_t max_auto_ip_net; /* Address range of auto_ip service. */ n2n_ip_subnet_t max_auto_ip_net; /* Address range of auto_ip service. */
#ifndef WIN32 #ifndef _WIN32
uid_t userid; uid_t userid;
gid_t groupid; gid_t groupid;
#endif #endif

6
include/n2n_wire.h

@ -25,12 +25,12 @@
#include <stdint.h> #include <stdint.h>
#endif #endif
#if defined(WIN32) #ifdef _WIN32
#include "n2n_win32.h" #include "n2n_win32.h"
#else /* #if defined(WIN32) */ #else /* #ifdef _WIN32 */
#include <netinet/in.h> #include <netinet/in.h>
#include <sys/socket.h> /* AF_INET and AF_INET6 */ #include <sys/socket.h> /* AF_INET and AF_INET6 */
#endif /* #if defined(WIN32) */ #endif /* #ifdef _WIN32 */
#include "sn_selection.h" #include "sn_selection.h"

2
include/random_numbers.h

@ -38,7 +38,7 @@
#include <immintrin.h> /* _rdrand64_step, rdseed4_step */ #include <immintrin.h> /* _rdrand64_step, rdseed4_step */
#endif #endif
#if defined (WIN32) #ifdef _WIN32
#include <wincrypt.h> // HCTYPTPROV, Crypt*-functions #include <wincrypt.h> // HCTYPTPROV, Crypt*-functions
#endif #endif

58
src/edge.c

@ -42,7 +42,7 @@
#include "speck.h" // for speck_init, speck_context_t #include "speck.h" // for speck_init, speck_context_t
#include "uthash.h" // for UT_hash_handle, HASH_ADD, HASH_C... #include "uthash.h" // for UT_hash_handle, HASH_ADD, HASH_C...
#ifdef WIN32 #ifdef _WIN32
#include <winsock2.h> #include <winsock2.h>
#include <ws2tcpip.h> #include <ws2tcpip.h>
#else #else
@ -230,12 +230,12 @@ static void help (int level) {
"[-J <password>] " "[-J <password>] "
"[-P <public key>] " "[-P <public key>] "
"[-R <rule string>] " "[-R <rule string>] "
#ifdef WIN32 #ifdef _WIN32
"\n " "\n "
"[-x <metric>] " "[-x <metric>] "
#endif #endif
"\n\n local options " "\n\n local options "
#ifndef WIN32 #ifndef _WIN32
"[-f] " "[-f] "
#endif #endif
"[-t <management port>] " "[-t <management port>] "
@ -243,7 +243,7 @@ static void help (int level) {
"\n " "\n "
"[-v] " "[-v] "
"[-V] " "[-V] "
#ifndef WIN32 #ifndef _WIN32
"\n " "\n "
"[-u <numerical user id>] " "[-u <numerical user id>] "
"[-g <numerical group id>] " "[-g <numerical group id>] "
@ -266,7 +266,7 @@ static void help (int level) {
"\n [-E] accept multicast MAC addresses" "\n [-E] accept multicast MAC addresses"
"\n [--select-rtt] select supernode by round trip time" "\n [--select-rtt] select supernode by round trip time"
"\n [--select-mac] select supernode by MAC address" "\n [--select-mac] select supernode by MAC address"
#ifndef WIN32 #ifndef _WIN32
"\n [-f] do not fork but run in foreground" "\n [-f] do not fork but run in foreground"
#endif #endif
"\n [-v] make more verbose, repeat as required" "\n [-v] make more verbose, repeat as required"
@ -351,14 +351,14 @@ static void help (int level) {
printf(" | rule format: 'src_ip/n:[s_port,e_port],...\n" printf(" | rule format: 'src_ip/n:[s_port,e_port],...\n"
" | |on same| ...dst_ip/n:[s_port,e_port],...\n" " | |on same| ...dst_ip/n:[s_port,e_port],...\n"
" | | line | ...TCP+/-,UDP+/-,ICMP+/-'\n"); " | | line | ...TCP+/-,UDP+/-,ICMP+/-'\n");
#ifdef WIN32 #ifdef _WIN32
printf(" -x <metric> | set TAP interface metric, defaults to 0 (auto),\n" printf(" -x <metric> | set TAP interface metric, defaults to 0 (auto),\n"
" | e.g. set to 1 for better multiplayer game detection\n"); " | e.g. set to 1 for better multiplayer game detection\n");
#endif #endif
printf ("\n"); printf ("\n");
printf (" LOCAL OPTIONS\n"); printf (" LOCAL OPTIONS\n");
printf (" -------------\n\n"); printf (" -------------\n\n");
#ifndef WIN32 #ifndef _WIN32
printf(" -f | do not fork and run as a daemon, rather run in foreground\n"); printf(" -f | do not fork and run as a daemon, rather run in foreground\n");
#endif #endif
printf(" -t <port> | management UDP port, for multiple edges on a machine,\n" printf(" -t <port> | management UDP port, for multiple edges on a machine,\n"
@ -367,7 +367,7 @@ static void help (int level) {
" ...password <pw> | \n", N2N_MGMT_PASSWORD); " ...password <pw> | \n", N2N_MGMT_PASSWORD);
printf(" -v | make more verbose, repeat as required\n"); printf(" -v | make more verbose, repeat as required\n");
printf(" -V | make less verbose, repeat as required\n"); printf(" -V | make less verbose, repeat as required\n");
#ifndef WIN32 #ifndef _WIN32
printf(" -u <UID> | numeric user ID to use when privileges are dropped\n"); printf(" -u <UID> | numeric user ID to use when privileges are dropped\n");
printf(" -g <GID> | numeric group ID to use when privileges are dropped\n"); printf(" -g <GID> | numeric group ID to use when privileges are dropped\n");
#endif #endif
@ -378,7 +378,7 @@ static void help (int level) {
printf(" N2N_COMMUNITY | community name (ASCII), overwritten by '-c ...'\n"); printf(" N2N_COMMUNITY | community name (ASCII), overwritten by '-c ...'\n");
printf(" N2N_PASSWORD | password (ASCII) for user-password authentication,\n" printf(" N2N_PASSWORD | password (ASCII) for user-password authentication,\n"
" | overwritten by '-J ...'\n"); " | overwritten by '-J ...'\n");
#ifdef WIN32 #ifdef _WIN32
printf ("\n"); printf ("\n");
printf (" AVAILABLE TAP ADAPTERS\n"); printf (" AVAILABLE TAP ADAPTERS\n");
printf (" ----------------------\n\n"); printf (" ----------------------\n\n");
@ -490,7 +490,7 @@ static int setOption (int optkey, char *optargument, n2n_tuntap_priv_config_t *e
break; break;
} }
#ifndef WIN32 #ifndef _WIN32
case 'u': /* unprivileged uid */ { case 'u': /* unprivileged uid */ {
ec->userid = atoi(optargument); ec->userid = atoi(optargument);
break; break;
@ -502,12 +502,12 @@ static int setOption (int optkey, char *optargument, n2n_tuntap_priv_config_t *e
} }
#endif #endif
#ifndef WIN32 #ifndef _WIN32
case 'f' : /* do not fork as daemon */ { case 'f' : /* do not fork as daemon */ {
ec->daemon = 0; ec->daemon = 0;
break; break;
} }
#endif /* #ifndef WIN32 */ #endif /* #ifndef _WIN32 */
case 'm' : /* TUNTAP MAC address */ { case 'm' : /* TUNTAP MAC address */ {
strncpy(ec->device_mac, optargument, N2N_MACNAMSIZ); strncpy(ec->device_mac, optargument, N2N_MACNAMSIZ);
@ -785,7 +785,7 @@ static int setOption (int optkey, char *optargument, n2n_tuntap_priv_config_t *e
} }
break; break;
} }
#ifdef WIN32 #ifdef _WIN32
case 'x': { case 'x': {
conf->metric = atoi(optargument); conf->metric = atoi(optargument);
ec->metric = atoi(optargument); ec->metric = atoi(optargument);
@ -831,7 +831,7 @@ static int loadFromCLI (int argc, char *argv[], n2n_edge_conf_t *conf, n2n_tunta
#ifdef __linux__ #ifdef __linux__
"T:" "T:"
#endif #endif
#ifdef WIN32 #ifdef _WIN32
"x:" "x:"
#endif #endif
, ,
@ -912,7 +912,7 @@ static int loadFromFile (const char *path, n2n_edge_conf_t *conf, n2n_tuntap_pri
/* ************************************** */ /* ************************************** */
#ifndef WIN32 #ifndef _WIN32
static void daemonize () { static void daemonize () {
int childpid; int childpid;
@ -961,8 +961,8 @@ static void daemonize () {
static bool keep_on_running = true; static bool keep_on_running = true;
#if defined(__linux__) || defined(WIN32) #if defined(__linux__) || defined(_WIN32)
#ifdef WIN32 #ifdef _WIN32
BOOL WINAPI term_handler(DWORD sig) BOOL WINAPI term_handler(DWORD sig)
#else #else
static void term_handler(int sig) static void term_handler(int sig)
@ -979,7 +979,7 @@ BOOL WINAPI term_handler(DWORD sig)
} }
keep_on_running = false; keep_on_running = false;
#ifdef WIN32 #ifdef _WIN32
switch (sig) { switch (sig) {
case CTRL_CLOSE_EVENT: case CTRL_CLOSE_EVENT:
case CTRL_LOGOFF_EVENT: case CTRL_LOGOFF_EVENT:
@ -990,7 +990,7 @@ BOOL WINAPI term_handler(DWORD sig)
return(TRUE); return(TRUE);
#endif #endif
} }
#endif /* defined(__linux__) || defined(WIN32) */ #endif /* defined(__linux__) || defined(_WIN32) */
/* *************************************************** */ /* *************************************************** */
@ -1015,13 +1015,13 @@ int main (int argc, char* argv[]) {
uint8_t pktbuf[N2N_SN_PKTBUF_SIZE + sizeof(uint16_t)]; /* buffer + prepended buffer length in case of tcp */ uint8_t pktbuf[N2N_SN_PKTBUF_SIZE + sizeof(uint16_t)]; /* buffer + prepended buffer length in case of tcp */
#ifndef WIN32 #ifndef _WIN32
struct passwd *pw = NULL; struct passwd *pw = NULL;
#endif #endif
#ifdef HAVE_LIBCAP #ifdef HAVE_LIBCAP
cap_t caps; cap_t caps;
#endif #endif
#ifdef WIN32 #ifdef _WIN32
initWin32(); initWin32();
#endif #endif
@ -1031,7 +1031,7 @@ int main (int argc, char* argv[]) {
ec.mtu = DEFAULT_MTU; ec.mtu = DEFAULT_MTU;
ec.daemon = 1; /* By default run in daemon mode. */ ec.daemon = 1; /* By default run in daemon mode. */
#ifndef WIN32 #ifndef _WIN32
if(((pw = getpwnam("n2n")) != NULL) || if(((pw = getpwnam("n2n")) != NULL) ||
((pw = getpwnam("nobody")) != NULL)) { ((pw = getpwnam("nobody")) != NULL)) {
ec.userid = pw->pw_uid; ec.userid = pw->pw_uid;
@ -1039,7 +1039,7 @@ int main (int argc, char* argv[]) {
} }
#endif #endif
#ifdef WIN32 #ifdef _WIN32
ec.tuntap_dev_name[0] = '\0'; ec.tuntap_dev_name[0] = '\0';
ec.metric = 0; ec.metric = 0;
#else #else
@ -1055,7 +1055,7 @@ int main (int argc, char* argv[]) {
rc = loadFromCLI(argc, argv, &conf, &ec); rc = loadFromCLI(argc, argv, &conf, &ec);
else else
#ifdef WIN32 #ifdef _WIN32
// load from current directory // load from current directory
rc = loadFromFile("edge.conf", &conf, &ec); rc = loadFromFile("edge.conf", &conf, &ec);
#else #else
@ -1119,7 +1119,7 @@ int main (int argc, char* argv[]) {
/* Random seed */ /* Random seed */
n2n_srand (n2n_seed()); n2n_srand (n2n_seed());
#ifndef WIN32 #ifndef _WIN32
/* If running suid root then we need to setuid before using the force. */ /* If running suid root then we need to setuid before using the force. */
if(setuid(0) != 0) if(setuid(0) != 0)
traceEvent(TRACE_ERROR, "unable to become root [%u/%s]", errno, strerror(errno)); traceEvent(TRACE_ERROR, "unable to become root [%u/%s]", errno, strerror(errno));
@ -1247,7 +1247,7 @@ int main (int argc, char* argv[]) {
if(tuntap_open(&tuntap, eee->tuntap_priv_conf.tuntap_dev_name, eee->tuntap_priv_conf.ip_mode, if(tuntap_open(&tuntap, eee->tuntap_priv_conf.tuntap_dev_name, eee->tuntap_priv_conf.ip_mode,
eee->tuntap_priv_conf.ip_addr, eee->tuntap_priv_conf.netmask, eee->tuntap_priv_conf.ip_addr, eee->tuntap_priv_conf.netmask,
eee->tuntap_priv_conf.device_mac, eee->tuntap_priv_conf.mtu eee->tuntap_priv_conf.device_mac, eee->tuntap_priv_conf.mtu
#ifdef WIN32 #ifdef _WIN32
, eee->tuntap_priv_conf.metric , eee->tuntap_priv_conf.metric
#endif #endif
) < 0) ) < 0)
@ -1298,7 +1298,7 @@ int main (int argc, char* argv[]) {
eee->sn_wait = 1; eee->sn_wait = 1;
eee->last_register_req = 0; eee->last_register_req = 0;
#ifndef WIN32 #ifndef _WIN32
if(eee->tuntap_priv_conf.daemon) { if(eee->tuntap_priv_conf.daemon) {
setUseSyslog(1); /* traceEvent output now goes to syslog. */ setUseSyslog(1); /* traceEvent output now goes to syslog. */
daemonize(); daemonize();
@ -1340,7 +1340,7 @@ int main (int argc, char* argv[]) {
signal(SIGTERM, term_handler); signal(SIGTERM, term_handler);
signal(SIGINT, term_handler); signal(SIGINT, term_handler);
#endif #endif
#ifdef WIN32 #ifdef _WIN32
SetConsoleCtrlHandler(term_handler, TRUE); SetConsoleCtrlHandler(term_handler, TRUE);
#endif #endif
@ -1365,7 +1365,7 @@ int main (int argc, char* argv[]) {
tuntap_close(&eee->device); tuntap_close(&eee->device);
edge_term(eee); edge_term(eee);
#ifdef WIN32 #ifdef _WIN32
destroyWin32(); destroyWin32();
#endif #endif

2
src/edge_management.c

@ -35,7 +35,7 @@
#include "strbuf.h" // for strbuf_t, STRBUF_INIT #include "strbuf.h" // for strbuf_t, STRBUF_INIT
#include "uthash.h" // for UT_hash_handle, HASH_ITER #include "uthash.h" // for UT_hash_handle, HASH_ITER
#ifdef WIN32 #ifdef _WIN32
#include <winsock2.h> #include <winsock2.h>
#include <ws2tcpip.h> #include <ws2tcpip.h>
#else #else

32
src/edge_utils.c

@ -40,7 +40,7 @@
#include "speck.h" // for speck_128_decrypt, speck_128_enc... #include "speck.h" // for speck_128_decrypt, speck_128_enc...
#include "uthash.h" // for UT_hash_handle, HASH_COUNT, HASH... #include "uthash.h" // for UT_hash_handle, HASH_COUNT, HASH...
#ifdef WIN32 #ifdef _WIN32
#include <winsock2.h> #include <winsock2.h>
#include <ws2tcpip.h> #include <ws2tcpip.h>
#include "edge_utils_win32.h" #include "edge_utils_win32.h"
@ -307,7 +307,7 @@ int supernode_connect (n2n_edge_t *eee) {
// set tcp socket to O_NONBLOCK so connect does not hang // set tcp socket to O_NONBLOCK so connect does not hang
// requires checking the socket for readiness before sending and receving // requires checking the socket for readiness before sending and receving
if(eee->conf.connect_tcp) { if(eee->conf.connect_tcp) {
#ifdef WIN32 #ifdef _WIN32
u_long value = 1; u_long value = 1;
ioctlsocket(eee->sock, FIONBIO, &value); ioctlsocket(eee->sock, FIONBIO, &value);
#else #else
@ -705,7 +705,7 @@ static void register_with_new_peer (n2n_edge_t *eee,
*/ */
if(eee->conf.register_ttl == 1) { if(eee->conf.register_ttl == 1) {
/* We are DMZ host or port is directly accessible. Just let peer to send back the ack */ /* We are DMZ host or port is directly accessible. Just let peer to send back the ack */
#ifndef WIN32 #ifndef _WIN32
} else if(eee->conf.register_ttl > 1) { } else if(eee->conf.register_ttl > 1) {
/* Setting register_ttl usually implies that the edge knows the internal net topology /* Setting register_ttl usually implies that the edge knows the internal net topology
* clearly, we can apply aggressive port prediction to support incoming Symmetric NAT * clearly, we can apply aggressive port prediction to support incoming Symmetric NAT
@ -1086,7 +1086,7 @@ static ssize_t sendto_fd (n2n_edge_t *eee, const void *buf,
traceEvent(level, "sendto(%s) failed (%d) %s", traceEvent(level, "sendto(%s) failed (%d) %s",
sock_to_cstr(sockbuf, n2ndest), sock_to_cstr(sockbuf, n2ndest),
errno, errstr); errno, errstr);
#ifdef WIN32 #ifdef _WIN32
traceEvent(level, "WSAGetLastError(): %u", WSAGetLastError()); traceEvent(level, "WSAGetLastError(): %u", WSAGetLastError());
#endif #endif
@ -1182,7 +1182,7 @@ static void check_join_multicast_group (n2n_edge_t *eee) {
if(!eee->multicast_joined) { if(!eee->multicast_joined) {
struct ip_mreq mreq; struct ip_mreq mreq;
mreq.imr_multiaddr.s_addr = inet_addr(N2N_MULTICAST_GROUP); mreq.imr_multiaddr.s_addr = inet_addr(N2N_MULTICAST_GROUP);
#ifdef WIN32 #ifdef _WIN32
dec_ip_str_t ip_addr; dec_ip_str_t ip_addr;
get_best_interface_ip(eee, &ip_addr); get_best_interface_ip(eee, &ip_addr);
mreq.imr_interface.s_addr = inet_addr(ip_addr); mreq.imr_interface.s_addr = inet_addr(ip_addr);
@ -1194,7 +1194,7 @@ static void check_join_multicast_group (n2n_edge_t *eee) {
traceEvent(TRACE_WARNING, "failed to bind to local multicast group %s:%u [errno %u]", traceEvent(TRACE_WARNING, "failed to bind to local multicast group %s:%u [errno %u]",
N2N_MULTICAST_GROUP, N2N_MULTICAST_PORT, errno); N2N_MULTICAST_GROUP, N2N_MULTICAST_PORT, errno);
#ifdef WIN32 #ifdef _WIN32
traceEvent(TRACE_WARNING, "WSAGetLastError(): %u", WSAGetLastError()); traceEvent(TRACE_WARNING, "WSAGetLastError(): %u", WSAGetLastError());
#endif #endif
} else { } else {
@ -1851,7 +1851,7 @@ static int handle_PACKET (n2n_edge_t * eee,
#if 0 #if 0
#ifndef WIN32 #ifndef _WIN32
static char *get_ip_from_arp (dec_ip_str_t buf, const n2n_mac_t req_mac) { static char *get_ip_from_arp (dec_ip_str_t buf, const n2n_mac_t req_mac) {
@ -2183,7 +2183,7 @@ void edge_read_from_tap (n2n_edge_t * eee) {
tuntap_close(&(eee->device)); tuntap_close(&(eee->device));
tuntap_open(&(eee->device), eee->tuntap_priv_conf.tuntap_dev_name, eee->tuntap_priv_conf.ip_mode, eee->tuntap_priv_conf.ip_addr, tuntap_open(&(eee->device), eee->tuntap_priv_conf.tuntap_dev_name, eee->tuntap_priv_conf.ip_mode, eee->tuntap_priv_conf.ip_addr,
eee->tuntap_priv_conf.netmask, eee->tuntap_priv_conf.device_mac, eee->tuntap_priv_conf.mtu eee->tuntap_priv_conf.netmask, eee->tuntap_priv_conf.device_mac, eee->tuntap_priv_conf.mtu
#ifdef WIN32 #ifdef _WIN32
,eee->tuntap_priv_conf.metric ,eee->tuntap_priv_conf.metric
#endif #endif
); );
@ -2795,14 +2795,14 @@ int fetch_and_eventually_process_data (n2n_edge_t *eee, SOCKET sock,
sender_sock, &ss_size); sender_sock, &ss_size);
if((bread < 0) if((bread < 0)
#ifdef WIN32 #ifdef _WIN32
&& (WSAGetLastError() != WSAECONNRESET) && (WSAGetLastError() != WSAECONNRESET)
#endif #endif
) { ) {
/* For UDP bread of zero just means no data (unlike TCP). */ /* For UDP bread of zero just means no data (unlike TCP). */
/* The fd is no good now. Maybe we lost our interface. */ /* The fd is no good now. Maybe we lost our interface. */
traceEvent(TRACE_ERROR, "recvfrom() failed %d errno %d (%s)", bread, errno, strerror(errno)); traceEvent(TRACE_ERROR, "recvfrom() failed %d errno %d (%s)", bread, errno, strerror(errno));
#ifdef WIN32 #ifdef _WIN32
traceEvent(TRACE_ERROR, "WSAGetLastError(): %u", WSAGetLastError()); traceEvent(TRACE_ERROR, "WSAGetLastError(): %u", WSAGetLastError());
#endif #endif
return -1; return -1;
@ -2821,7 +2821,7 @@ int fetch_and_eventually_process_data (n2n_edge_t *eee, SOCKET sock,
sender_sock, &ss_size); sender_sock, &ss_size);
if((bread <= 0) && (errno)) { if((bread <= 0) && (errno)) {
traceEvent(TRACE_ERROR, "recvfrom() failed %d errno %d (%s)", bread, errno, strerror(errno)); traceEvent(TRACE_ERROR, "recvfrom() failed %d errno %d (%s)", bread, errno, strerror(errno));
#ifdef WIN32 #ifdef _WIN32
traceEvent(TRACE_ERROR, "WSAGetLastError(): %u", WSAGetLastError()); traceEvent(TRACE_ERROR, "WSAGetLastError(): %u", WSAGetLastError());
#endif #endif
supernode_disconnect(eee); supernode_disconnect(eee);
@ -2889,7 +2889,7 @@ int run_edge_loop (n2n_edge_t *eee) {
uint16_t position = 0; uint16_t position = 0;
uint8_t pktbuf[N2N_PKT_BUF_SIZE + sizeof(uint16_t)]; /* buffer + prepended buffer length in case of tcp */ uint8_t pktbuf[N2N_PKT_BUF_SIZE + sizeof(uint16_t)]; /* buffer + prepended buffer length in case of tcp */
#ifdef WIN32 #ifdef _WIN32
struct tunread_arg arg; struct tunread_arg arg;
arg.eee = eee; arg.eee = eee;
HANDLE tun_read_thread = startTunReadThread(&arg); HANDLE tun_read_thread = startTunReadThread(&arg);
@ -2929,7 +2929,7 @@ int run_edge_loop (n2n_edge_t *eee) {
} }
#endif #endif
#ifndef WIN32 #ifndef _WIN32
FD_SET(eee->device.fd, &socket_mask); FD_SET(eee->device.fd, &socket_mask);
max_sock = max(max_sock, eee->device.fd); max_sock = max(max_sock, eee->device.fd);
#endif #endif
@ -2989,7 +2989,7 @@ int run_edge_loop (n2n_edge_t *eee) {
break; break;
} }
#ifndef WIN32 #ifndef _WIN32
if(FD_ISSET(eee->device.fd, &socket_mask)) { if(FD_ISSET(eee->device.fd, &socket_mask)) {
// read an ethernet frame from the TAP socket; write on the IP socket // read an ethernet frame from the TAP socket; write on the IP socket
edge_read_from_tap(eee); edge_read_from_tap(eee);
@ -3055,7 +3055,7 @@ int run_edge_loop (n2n_edge_t *eee) {
send_unregister_super(eee); send_unregister_super(eee);
#ifdef WIN32 #ifdef _WIN32
WaitForSingleObject(tun_read_thread, INFINITE); WaitForSingleObject(tun_read_thread, INFINITE);
#endif #endif
@ -3296,7 +3296,7 @@ int quick_edge_init (char *device_name, char *community_name,
if(tuntap_open(&tuntap, device_name, "static", if(tuntap_open(&tuntap, device_name, "static",
local_ip_address, "255.255.255.0", local_ip_address, "255.255.255.0",
device_mac, DEFAULT_MTU device_mac, DEFAULT_MTU
#ifdef WIN32 #ifdef _WIN32
, 0 , 0
#endif #endif
) < 0) ) < 0)

2
src/edge_utils_win32.c

@ -16,7 +16,7 @@
* *
*/ */
#ifdef WIN32 #ifdef _WIN32
#include <winsock2.h> #include <winsock2.h>

2
src/example_edge_embed.c

@ -59,7 +59,7 @@ int main() {
"255.255.255.0", // Netmask to use "255.255.255.0", // Netmask to use
"DE:AD:BE:EF:01:10", // Set mac address "DE:AD:BE:EF:01:10", // Set mac address
DEFAULT_MTU // MTU to use DEFAULT_MTU // MTU to use
#ifdef WIN32 #ifdef _WIN32
, 0 , 0
#endif #endif
) < 0) ) < 0)

2
src/example_sn_embed.c

@ -21,7 +21,7 @@
#include <stdlib.h> // for exit #include <stdlib.h> // for exit
#include "n2n.h" // for n2n_sn_t, open_socket, run_sn_loop, sn_init #include "n2n.h" // for n2n_sn_t, open_socket, run_sn_loop, sn_init
#ifdef WIN32 #ifdef _WIN32
#include <winsock2.h> #include <winsock2.h>
#else #else
#include <netinet/in.h> // for INADDR_ANY, INADDR_LOOPBACK #include <netinet/in.h> // for INADDR_ANY, INADDR_LOOPBACK

2
src/management.c

@ -12,7 +12,7 @@
#include "management.h" #include "management.h"
#include "n2n.h" // for TRACE_DEBUG, traceEvent #include "n2n.h" // for TRACE_DEBUG, traceEvent
#ifndef WIN32 #ifndef _WIN32
#include <netdb.h> // for getnameinfo, NI_NUMERICHOST, NI_NUMERICSERV #include <netdb.h> // for getnameinfo, NI_NUMERICHOST, NI_NUMERICSERV
#include <sys/socket.h> // for sendto, sockaddr #include <sys/socket.h> // for sendto, sockaddr
#endif #endif

2
src/management.h

@ -16,7 +16,7 @@
#include "n2n_define.h" // for n2n_event_topic #include "n2n_define.h" // for n2n_event_topic
#include "strbuf.h" #include "strbuf.h"
#ifdef WIN32 #ifdef _WIN32
#include <winsock2.h> #include <winsock2.h>
#else #else
#include <sys/socket.h> // for sockaddr, sockaddr_storage, socklen_t #include <sys/socket.h> // for sockaddr, sockaddr_storage, socklen_t

14
src/n2n.c

@ -34,7 +34,7 @@
#include <pthread.h> #include <pthread.h>
#endif #endif
#ifdef WIN32 #ifdef _WIN32
#include <winsock2.h> #include <winsock2.h>
#include <ws2def.h> #include <ws2def.h>
#include <ws2tcpip.h> #include <ws2tcpip.h>
@ -60,7 +60,7 @@ SOCKET open_socket (int local_port, in_addr_t address, int type /* 0 = UDP, TCP
return(-1); return(-1);
} }
#ifndef WIN32 #ifndef _WIN32
/* fcntl(sock_fd, F_SETFL, O_NONBLOCK); */ /* fcntl(sock_fd, F_SETFL, O_NONBLOCK); */
#endif #endif
@ -83,7 +83,7 @@ SOCKET open_socket (int local_port, in_addr_t address, int type /* 0 = UDP, TCP
static int traceLevel = 2 /* NORMAL */; static int traceLevel = 2 /* NORMAL */;
static int useSyslog = 0; static int useSyslog = 0;
#ifndef WIN32 #ifndef _WIN32
static int syslog_opened = 0; static int syslog_opened = 0;
#endif #endif
static FILE *traceFile = NULL; static FILE *traceFile = NULL;
@ -113,7 +113,7 @@ void closeTraceFile () {
if((traceFile != NULL) && (traceFile != stdout)) { if((traceFile != NULL) && (traceFile != stdout)) {
fclose(traceFile); fclose(traceFile);
} }
#ifndef WIN32 #ifndef _WIN32
if(useSyslog && syslog_opened) { if(useSyslog && syslog_opened) {
closelog(); closelog();
syslog_opened = 0; syslog_opened = 0;
@ -161,7 +161,7 @@ void _traceEvent (int eventTraceLevel, char* file, int line, char * format, ...)
buf[strlen(buf) - 1] = '\0'; buf[strlen(buf) - 1] = '\0';
} }
#ifndef WIN32 #ifndef _WIN32
if(useSyslog) { if(useSyslog) {
if(!syslog_opened) { if(!syslog_opened) {
openlog("n2n", LOG_PID, LOG_DAEMON); openlog("n2n", LOG_PID, LOG_DAEMON);
@ -181,7 +181,7 @@ void _traceEvent (int eventTraceLevel, char* file, int line, char * format, ...)
snprintf(out_buf, sizeof(out_buf), "%s [%s:%d] %s%s", theDate, &file[i], line, extra_msg, buf); snprintf(out_buf, sizeof(out_buf), "%s [%s:%d] %s%s", theDate, &file[i], line, extra_msg, buf);
fprintf(traceFile, "%s\n", out_buf); fprintf(traceFile, "%s\n", out_buf);
fflush(traceFile); fflush(traceFile);
#ifndef WIN32 #ifndef _WIN32
} }
#endif #endif
} }
@ -844,7 +844,7 @@ int memxor (uint8_t *destination, const uint8_t *source, size_t len) {
/* *********************************************** */ /* *********************************************** */
#if defined(WIN32) #ifdef _WIN32
int gettimeofday (struct timeval *tp, void *tzp) { int gettimeofday (struct timeval *tp, void *tzp) {
time_t clock; time_t clock;

2
src/network_traffic_filter.c

@ -25,7 +25,7 @@
#include "network_traffic_filter.h" // for create_network_traffic_filter #include "network_traffic_filter.h" // for create_network_traffic_filter
#include "uthash.h" // for UT_hash_handle, HASH_ITER, HASH_DEL #include "uthash.h" // for UT_hash_handle, HASH_ITER, HASH_DEL
#ifdef WIN32 #ifdef _WIN32
#include <winsock2.h> #include <winsock2.h>
#include <ws2tcpip.h> #include <ws2tcpip.h>
#else #else

2
src/random_numbers.c

@ -178,7 +178,7 @@ uint64_t n2n_seed (void) {
#endif #endif
#endif #endif
#ifdef WIN32 #ifdef _WIN32
HCRYPTPROV crypto_provider; HCRYPTPROV crypto_provider;
CryptAcquireContext (&crypto_provider, NULL, NULL, CryptAcquireContext (&crypto_provider, NULL, NULL,
PROV_RSA_FULL, CRYPT_VERIFYCONTEXT); PROV_RSA_FULL, CRYPT_VERIFYCONTEXT);

2
src/sn_management.c

@ -35,7 +35,7 @@
#include "strbuf.h" // for strbuf_t, STRBUF_INIT #include "strbuf.h" // for strbuf_t, STRBUF_INIT
#include "uthash.h" // for UT_hash_handle, HASH_ITER, HASH_COUNT #include "uthash.h" // for UT_hash_handle, HASH_ITER, HASH_COUNT
#ifdef WIN32 #ifdef _WIN32
#include <winsock2.h> #include <winsock2.h>
#else #else
#include <sys/socket.h> // for sendto, socklen_t #include <sys/socket.h> // for sendto, socklen_t

14
src/sn_utils.c

@ -40,7 +40,7 @@
#include "speck.h" // for speck_128_encrypt, speck_context_t #include "speck.h" // for speck_128_encrypt, speck_context_t
#include "uthash.h" // for UT_hash_handle, HASH_ITER, HASH_DEL #include "uthash.h" // for UT_hash_handle, HASH_ITER, HASH_DEL
#ifdef WIN32 #ifdef _WIN32
#include <winsock2.h> #include <winsock2.h>
#include <ws2tcpip.h> #include <ws2tcpip.h>
#else #else
@ -512,7 +512,7 @@ static ssize_t sendto_fd (n2n_sn_t *sss,
if((sent <= 0) && (errno)) { if((sent <= 0) && (errno)) {
char * c = strerror(errno); char * c = strerror(errno);
traceEvent(TRACE_ERROR, "sendto failed (%d) %s", errno, c); traceEvent(TRACE_ERROR, "sendto failed (%d) %s", errno, c);
#ifdef WIN32 #ifdef _WIN32
traceEvent(TRACE_ERROR, "WSAGetLastError(): %u", WSAGetLastError()); traceEvent(TRACE_ERROR, "WSAGetLastError(): %u", WSAGetLastError());
#endif #endif
// if the erroneous connection is tcp, i.e. not the regular sock... // if the erroneous connection is tcp, i.e. not the regular sock...
@ -768,7 +768,7 @@ int sn_init_defaults (n2n_sn_t *sss) {
char *tmp_string; char *tmp_string;
#ifdef WIN32 #ifdef _WIN32
initWin32(); initWin32();
#endif #endif
@ -904,7 +904,7 @@ void sn_term (n2n_sn_t *sss) {
if(sss->community_file) if(sss->community_file)
free(sss->community_file); free(sss->community_file);
#ifdef WIN32 #ifdef _WIN32
destroyWin32(); destroyWin32();
#endif #endif
} }
@ -2642,14 +2642,14 @@ int run_sn_loop (n2n_sn_t *sss) {
sender_sock, &ss_size); sender_sock, &ss_size);
if((bread < 0) if((bread < 0)
#ifdef WIN32 #ifdef _WIN32
&& (WSAGetLastError() != WSAECONNRESET) && (WSAGetLastError() != WSAECONNRESET)
#endif #endif
) { ) {
/* For UDP bread of zero just means no data (unlike TCP). */ /* For UDP bread of zero just means no data (unlike TCP). */
/* The fd is no good now. Maybe we lost our interface. */ /* The fd is no good now. Maybe we lost our interface. */
traceEvent(TRACE_ERROR, "recvfrom() failed %d errno %d (%s)", bread, errno, strerror(errno)); traceEvent(TRACE_ERROR, "recvfrom() failed %d errno %d (%s)", bread, errno, strerror(errno));
#ifdef WIN32 #ifdef _WIN32
traceEvent(TRACE_ERROR, "WSAGetLastError(): %u", WSAGetLastError()); traceEvent(TRACE_ERROR, "WSAGetLastError(): %u", WSAGetLastError());
#endif #endif
*sss->keep_running = false; *sss->keep_running = false;
@ -2688,7 +2688,7 @@ int run_sn_loop (n2n_sn_t *sss) {
if(bread <= 0) { if(bread <= 0) {
traceEvent(TRACE_INFO, "closing tcp connection to [%s]", sock_to_cstr(sockbuf, (n2n_sock_t*)sender_sock)); traceEvent(TRACE_INFO, "closing tcp connection to [%s]", sock_to_cstr(sockbuf, (n2n_sock_t*)sender_sock));
traceEvent(TRACE_DEBUG, "recvfrom() returns %d and sees errno %d (%s)", bread, errno, strerror(errno)); traceEvent(TRACE_DEBUG, "recvfrom() returns %d and sees errno %d (%s)", bread, errno, strerror(errno));
#ifdef WIN32 #ifdef _WIN32
traceEvent(TRACE_DEBUG, "WSAGetLastError(): %u", WSAGetLastError()); traceEvent(TRACE_DEBUG, "WSAGetLastError(): %u", WSAGetLastError());
#endif #endif
close_tcp_connection(sss, conn); close_tcp_connection(sss, conn);

26
src/supernode.c

@ -35,7 +35,7 @@
#include "pearson.h" // for pearson_hash_64 #include "pearson.h" // for pearson_hash_64
#include "uthash.h" // for UT_hash_handle, HASH_ITER, HASH_ADD_STR #include "uthash.h" // for UT_hash_handle, HASH_ITER, HASH_ADD_STR
#ifdef WIN32 #ifdef _WIN32
#include <winsock2.h> #include <winsock2.h>
#include <ws2tcpip.h> #include <ws2tcpip.h>
#else #else
@ -107,7 +107,7 @@ static void help (int level) {
"\n " "\n "
"[--management-password <pw>] " "[--management-password <pw>] "
"[-v] " "[-v] "
#ifndef WIN32 #ifndef _WIN32
"\n " "\n "
"[-u <numerical user id>]" "[-u <numerical user id>]"
"[-g <numerical group id>]" "[-g <numerical group id>]"
@ -168,7 +168,7 @@ static void help (int level) {
printf(" --management_... | management port password, defaults to '%s'\n" printf(" --management_... | management port password, defaults to '%s'\n"
" ...password <pw> | \n", N2N_MGMT_PASSWORD); " ...password <pw> | \n", N2N_MGMT_PASSWORD);
printf(" -v | make more verbose, repeat as required\n"); printf(" -v | make more verbose, repeat as required\n");
#ifndef WIN32 #ifndef _WIN32
printf(" -u <UID> | numeric user ID to use when privileges are dropped\n"); printf(" -u <UID> | numeric user ID to use when privileges are dropped\n");
printf(" -g <GID> | numeric group ID to use when privileges are dropped\n"); printf(" -g <GID> | numeric group ID to use when privileges are dropped\n");
#endif #endif
@ -324,7 +324,7 @@ static int setOption (int optkey, char *_optarg, n2n_sn_t *sss) {
break; break;
} }
#ifndef WIN32 #ifndef _WIN32
case 'u': /* unprivileged uid */ case 'u': /* unprivileged uid */
sss->userid = atoi(_optarg); sss->userid = atoi(_optarg);
break; break;
@ -425,7 +425,7 @@ static int loadFromCLI (int argc, char * const argv[], n2n_sn_t *sss) {
#if defined(N2N_HAVE_DAEMON) #if defined(N2N_HAVE_DAEMON)
"f" "f"
#endif #endif
#ifndef WIN32 #ifndef _WIN32
"u:g:" "u:g:"
#endif #endif
, ,
@ -567,8 +567,8 @@ static void dump_registrations (int signo) {
static bool keep_running = true; static bool keep_running = true;
#if defined(__linux__) || defined(WIN32) #if defined(__linux__) || defined(_WIN32)
#ifdef WIN32 #ifdef _WIN32
BOOL WINAPI term_handler (DWORD sig) BOOL WINAPI term_handler (DWORD sig)
#else #else
static void term_handler(int sig) static void term_handler(int sig)
@ -585,11 +585,11 @@ BOOL WINAPI term_handler (DWORD sig)
} }
keep_running = false; keep_running = false;
#ifdef WIN32 #ifdef _WIN32
return(TRUE); return(TRUE);
#endif #endif
} }
#endif /* defined(__linux__) || defined(WIN32) */ #endif /* defined(__linux__) || defined(_WIN32) */
/* *************************************************** */ /* *************************************************** */
@ -597,7 +597,7 @@ BOOL WINAPI term_handler (DWORD sig)
int main (int argc, char * const argv[]) { int main (int argc, char * const argv[]) {
int rc; int rc;
#ifndef WIN32 #ifndef _WIN32
struct passwd *pw = NULL; struct passwd *pw = NULL;
#endif #endif
struct peer_info *scan, *tmp; struct peer_info *scan, *tmp;
@ -615,7 +615,7 @@ int main (int argc, char * const argv[]) {
rc = loadFromCLI(argc, argv, &sss_node); rc = loadFromCLI(argc, argv, &sss_node);
} else } else
#ifdef WIN32 #ifdef _WIN32
// load from current directory // load from current directory
rc = loadFromFile("supernode.conf", &sss_node); rc = loadFromFile("supernode.conf", &sss_node);
#else #else
@ -689,7 +689,7 @@ int main (int argc, char * const argv[]) {
HASH_ITER(hh, sss_node.federation->edges, scan, tmp) HASH_ITER(hh, sss_node.federation->edges, scan, tmp)
scan->socket_fd = sss_node.sock; scan->socket_fd = sss_node.sock;
#ifndef WIN32 #ifndef _WIN32
/* /*
* If no uid/gid is specified on the commandline, use the uid/gid of the * If no uid/gid is specified on the commandline, use the uid/gid of the
* first found out of user "n2n" or "nobody" * first found out of user "n2n" or "nobody"
@ -734,7 +734,7 @@ int main (int argc, char * const argv[]) {
signal(SIGINT, term_handler); signal(SIGINT, term_handler);
signal(SIGHUP, dump_registrations); signal(SIGHUP, dump_registrations);
#endif #endif
#ifdef WIN32 #ifdef _WIN32
SetConsoleCtrlHandler(term_handler, TRUE); SetConsoleCtrlHandler(term_handler, TRUE);
#endif #endif

2
src/wire.c

@ -33,7 +33,7 @@
#include "n2n.h" // for n2n_sock_t, n2n_common_t, n2n_auth_t, n2n_RE... #include "n2n.h" // for n2n_sock_t, n2n_common_t, n2n_auth_t, n2n_RE...
#include "n2n_wire.h" // for decode_PACKET, decode_PEER_INFO, decode_QUER... #include "n2n_wire.h" // for decode_PACKET, decode_PEER_INFO, decode_QUER...
#ifdef WIN32 #ifdef _WIN32
#include <winsock2.h> #include <winsock2.h>
#include <ws2tcpip.h> #include <ws2tcpip.h>
#else #else

6
tools/n2n-decode.c

@ -58,7 +58,7 @@ static void help() {
/* *************************************************** */ /* *************************************************** */
#ifdef WIN32 #ifdef _WIN32
BOOL WINAPI term_handler(DWORD sig) BOOL WINAPI term_handler(DWORD sig)
#else #else
static void term_handler(int sig) static void term_handler(int sig)
@ -75,7 +75,7 @@ static void term_handler(int sig)
} }
running = 0; running = 0;
#ifdef WIN32 #ifdef _WIN32
return(TRUE); return(TRUE);
#endif #endif
} }
@ -349,7 +349,7 @@ int main(int argc, char* argv[]) {
return(5); return(5);
} }
#ifdef WIN32 #ifdef _WIN32
SetConsoleCtrlHandler(term_handler, TRUE); SetConsoleCtrlHandler(term_handler, TRUE);
#else #else
signal(SIGTERM, term_handler); signal(SIGTERM, term_handler);

14
tools/n2n-portfwd.c

@ -33,7 +33,7 @@
#include "n2n_port_mapping.h" // for n2n_del_port_mapping, n2n_set_port_map... #include "n2n_port_mapping.h" // for n2n_del_port_mapping, n2n_set_port_map...
#include "random_numbers.h" // for n2n_rand, n2n_seed, n2n_srand #include "random_numbers.h" // for n2n_rand, n2n_seed, n2n_srand
#ifdef WIN32 #ifdef _WIN32
#include <winsock.h> #include <winsock.h>
#include <ws2tcpip.h> #include <ws2tcpip.h>
#else #else
@ -49,7 +49,7 @@
#define INFO_INTERVAL 5 #define INFO_INTERVAL 5
// REVISIT: may become obsolete // REVISIT: may become obsolete
#ifdef WIN32 #ifdef _WIN32
#ifndef STDIN_FILENO #ifndef STDIN_FILENO
#define STDIN_FILENO _fileno(stdin) #define STDIN_FILENO _fileno(stdin)
#endif #endif
@ -75,13 +75,13 @@ void set_term_handler(const void *handler) {
signal(SIGTERM, handler); signal(SIGTERM, handler);
signal(SIGINT, handler); signal(SIGINT, handler);
#endif #endif
#ifdef WIN32 #ifdef _WIN32
SetConsoleCtrlHandler(handler, TRUE); SetConsoleCtrlHandler(handler, TRUE);
#endif #endif
} }
#ifdef WIN32 #ifdef _WIN32
BOOL WINAPI term_handler (DWORD sig) { BOOL WINAPI term_handler (DWORD sig) {
#else #else
static void term_handler (int sig) { static void term_handler (int sig) {
@ -98,7 +98,7 @@ static void term_handler (int sig) {
} }
keep_running = false; keep_running = false;
#ifdef WIN32 #ifdef _WIN32
return TRUE; return TRUE;
#endif #endif
} }
@ -113,7 +113,7 @@ SOCKET connect_to_management_port (n2n_portfwd_conf_t *ppp) {
SOCKET ret; SOCKET ret;
struct sockaddr_in sock_addr; struct sockaddr_in sock_addr;
#if defined(WIN32) #ifdef _WIN32
// Windows requires a call to WSAStartup() before it can work with sockets // Windows requires a call to WSAStartup() before it can work with sockets
WORD wVersionRequested; WORD wVersionRequested;
WSADATA wsaData; WSADATA wsaData;
@ -184,7 +184,7 @@ int get_port_from_json (uint16_t *port, json_object_t *json, char *key, int tag,
// PLATFORM-DEPENDANT CODE // PLATFORM-DEPENDANT CODE
#if !defined(WIN32) #ifndef _WIN32
// taken from https://web.archive.org/web/20170407122137/http://cc.byexamples.com/2007/04/08/non-blocking-user-input-in-loop-without-ncurses/ // taken from https://web.archive.org/web/20170407122137/http://cc.byexamples.com/2007/04/08/non-blocking-user-input-in-loop-without-ncurses/
int _kbhit () { int _kbhit () {

28
tools/n2n-route.c

@ -38,7 +38,7 @@
#include <linux/rtnetlink.h> // for RTA_DATA, rtmsg, RTA_GATEWAY, RTA_NEXT #include <linux/rtnetlink.h> // for RTA_DATA, rtmsg, RTA_GATEWAY, RTA_NEXT
#endif #endif
#ifdef WIN32 #ifdef _WIN32
#include <winsock.h> #include <winsock.h>
#include <ws2tcpip.h> #include <ws2tcpip.h>
#else #else
@ -51,7 +51,7 @@
#include <sys/socket.h> // for send, socket, AF_INET, recv, connect #include <sys/socket.h> // for send, socket, AF_INET, recv, connect
#endif #endif
#if defined (__linux__) || defined(WIN32) /* currently, Linux and Windows only */ #if defined (__linux__) || defined(_WIN32) /* currently, Linux and Windows only */
#define WITH_ADDRESS 1 #define WITH_ADDRESS 1
@ -74,7 +74,7 @@
#define AUTO_DETECT 1 #define AUTO_DETECT 1
// REVISIT: may become obsolete // REVISIT: may become obsolete
#ifdef WIN32 #ifdef _WIN32
#ifndef STDIN_FILENO #ifndef STDIN_FILENO
#define STDIN_FILENO _fileno(stdin) #define STDIN_FILENO _fileno(stdin)
#endif #endif
@ -117,7 +117,7 @@ int is_privileged (void) {
return euid == 0; return euid == 0;
#elif defined(WIN32) #elif defined(_WIN32)
// taken from https://stackoverflow.com/a/10553065 // taken from https://stackoverflow.com/a/10553065
int result; int result;
DWORD rc; DWORD rc;
@ -148,13 +148,13 @@ void set_term_handler(const void *handler) {
signal(SIGPIPE, SIG_IGN); signal(SIGPIPE, SIG_IGN);
signal(SIGTERM, handler); signal(SIGTERM, handler);
signal(SIGINT, handler); signal(SIGINT, handler);
#elif defined(WIN32) #elif defined(_WIN32)
SetConsoleCtrlHandler(handler, TRUE); SetConsoleCtrlHandler(handler, TRUE);
#endif #endif
} }
#if !defined(WIN32) #ifndef _WIN32
static void term_handler (int sig) { static void term_handler (int sig) {
#else #else
BOOL WINAPI term_handler (DWORD sig) { BOOL WINAPI term_handler (DWORD sig) {
@ -171,7 +171,7 @@ BOOL WINAPI term_handler (DWORD sig) {
} }
keep_running = false; keep_running = false;
#if defined(WIN32) #ifdef _WIN32
return TRUE; return TRUE;
#endif #endif
} }
@ -317,7 +317,7 @@ find_default_gateway_end:
closesocket(sock); closesocket(sock);
return ret; return ret;
#elif defined(WIN32) #elif defined(_WIN32)
// taken from (and modified) // taken from (and modified)
// https://docs.microsoft.com/en-us/windows/win32/api/iphlpapi/nf-iphlpapi-createipforwardentry // https://docs.microsoft.com/en-us/windows/win32/api/iphlpapi/nf-iphlpapi-createipforwardentry
@ -376,7 +376,7 @@ find_default_gateway_end:
// PLATFORM-DEPENDANT CODE // PLATFORM-DEPENDANT CODE
#if defined(WIN32) #ifdef _WIN32
DWORD get_interface_index (struct in_addr addr) { DWORD get_interface_index (struct in_addr addr) {
// taken from (and modified) // taken from (and modified)
// https://docs.microsoft.com/en-us/windows/win32/api/iphlpapi/nf-iphlpapi-createipforwardentry // https://docs.microsoft.com/en-us/windows/win32/api/iphlpapi/nf-iphlpapi-createipforwardentry
@ -496,7 +496,7 @@ void handle_route (n2n_route_t* in_route, int verb) {
closesocket(sock); closesocket(sock);
#elif defined(WIN32) #elif defined(_WIN32)
// REVISIT: use 'CreateIpForwardEntry()' and 'DeleteIpForwardEntry()' [iphlpapi.h] // REVISIT: use 'CreateIpForwardEntry()' and 'DeleteIpForwardEntry()' [iphlpapi.h]
char c_net_addr[32]; char c_net_addr[32];
char c_gateway[32]; char c_gateway[32];
@ -573,7 +573,7 @@ SOCKET connect_to_management_port (n2n_route_conf_t *rrr) {
SOCKET ret; SOCKET ret;
struct sockaddr_in sock_addr; struct sockaddr_in sock_addr;
#if defined(WIN32) #ifdef _WIN32
// Windows requires a call to WSAStartup() before it can work with sockets // Windows requires a call to WSAStartup() before it can work with sockets
WORD wVersionRequested; WORD wVersionRequested;
WSADATA wsaData; WSADATA wsaData;
@ -643,7 +643,7 @@ int get_addr_from_json (struct in_addr *addr, json_object_t *json, char *key, in
// PLATFORM-DEPENDANT CODE // PLATFORM-DEPENDANT CODE
#if !defined(WIN32) #ifndef _WIN32
// taken from https://web.archive.org/web/20170407122137/http://cc.byexamples.com/2007/04/08/non-blocking-user-input-in-loop-without-ncurses/ // taken from https://web.archive.org/web/20170407122137/http://cc.byexamples.com/2007/04/08/non-blocking-user-input-in-loop-without-ncurses/
int _kbhit () { int _kbhit () {
@ -1088,7 +1088,7 @@ end_route_tool:
} }
#else /* if defined(__linux__) || defined(WIN32) -- currently, Linux and Windows only */ #else /* if defined(__linux__) || defined(_WIN32) -- currently, Linux and Windows only */
int main (int argc, char* argv[]) { int main (int argc, char* argv[]) {
@ -1100,4 +1100,4 @@ int main (int argc, char* argv[]) {
} }
#endif /* if defined (__linux__) || defined(WIN32) -- currently, Linux and Windows only */ #endif /* if defined (__linux__) || defined(_WIN32) -- currently, Linux and Windows only */

6
win32/getopt.c

@ -58,7 +58,7 @@
#endif #endif
#include <stdio.h> #include <stdio.h>
#ifdef WIN32 #ifdef _WIN32
#include <string.h> #include <string.h>
#endif #endif
@ -171,7 +171,7 @@ static char *nextchar;
for unrecognized options. */ for unrecognized options. */
#ifndef DARWIN #ifndef DARWIN
#ifdef WIN32 #ifdef _WIN32
int opterr = 0; int opterr = 0;
#else #else
int opterr = 1; int opterr = 1;
@ -231,7 +231,7 @@ static char *posixly_correct;
# define my_index strchr # define my_index strchr
#else #else
#ifndef WIN32 #ifndef _WIN32
# if HAVE_STRING_H # if HAVE_STRING_H
# include <string.h> # include <string.h>
# else # else

Loading…
Cancel
Save