From e6c851d27654aa17f8337b9900668e278da011d2 Mon Sep 17 00:00:00 2001 From: ygg Date: Fri, 17 Jul 2020 14:21:27 +0800 Subject: [PATCH] add sleep() for fix compile error on windows --- include/edge_utils_win32.h | 6 +++++- include/n2n.h | 9 +++++---- src/edge.c | 10 +++++----- src/edge_utils.c | 8 ++++---- win32/n2n_win32.h | 4 +++- 5 files changed, 22 insertions(+), 15 deletions(-) diff --git a/include/edge_utils_win32.h b/include/edge_utils_win32.h index 569dc29..c4efc74 100644 --- a/include/edge_utils_win32.h +++ b/include/edge_utils_win32.h @@ -21,9 +21,12 @@ #ifdef WIN32 +#define WIN32_LEAN_AND_MEAN + #include #include + /* Multicast peers discovery disabled due to https://github.com/ntop/n2n/issues/65 */ #define SKIP_MULTICAST_PEERS_DISCOVERY @@ -34,7 +37,8 @@ struct tunread_arg { extern HANDLE startTunReadThread(struct tunread_arg *arg); -#endif + +#endif /* WIN32 */ #endif /* _EDGE_UTILS_WIN32_H_ */ diff --git a/include/n2n.h b/include/n2n.h index c9bca16..0c78643 100644 --- a/include/n2n.h +++ b/include/n2n.h @@ -65,7 +65,7 @@ #include #include #include -#include +#include #ifndef WIN32 #include @@ -248,7 +248,7 @@ typedef struct n2n_edge_callbacks { /* ***************************************************** */ -typedef struct n2n_priv_config { +typedef struct n2n_tuntap_priv_config { char tuntap_dev_name[N2N_IFNAMSIZ]; char ip_mode[N2N_IF_MODE_SIZE]; char ip_addr[N2N_NETMASK_STR_SIZE]; @@ -261,7 +261,7 @@ typedef struct n2n_priv_config { uid_t userid; gid_t groupid; #endif -} n2n_priv_config_t; +} n2n_tuntap_priv_config_t; /* *************************************************** */ @@ -299,7 +299,6 @@ struct n2n_edge_stats { }; struct n2n_edge { - n2n_priv_config_t priv_conf; n2n_edge_conf_t conf; /* Status */ @@ -336,6 +335,8 @@ struct n2n_edge { /* Statistics */ struct n2n_edge_stats stats; + /* Tuntap config */ + n2n_tuntap_priv_config_t tuntap_priv_conf; }; typedef struct sn_stats diff --git a/src/edge.c b/src/edge.c index d74dc53..c9716b9 100644 --- a/src/edge.c +++ b/src/edge.c @@ -273,7 +273,7 @@ static void setPayloadEncryption( n2n_edge_conf_t *conf, int cipher) { /* *************************************************** */ -static int setOption(int optkey, char *optargument, n2n_priv_config_t *ec, n2n_edge_conf_t *conf) { +static int setOption(int optkey, char *optargument, n2n_tuntap_priv_config_t *ec, n2n_edge_conf_t *conf) { /* traceEvent(TRACE_NORMAL, "Option %c = %s", optkey, optargument ? optargument : ""); */ switch(optkey) { @@ -536,7 +536,7 @@ static const struct option long_options[] = /* *************************************************** */ /* read command line options */ -static int loadFromCLI(int argc, char *argv[], n2n_edge_conf_t *conf, n2n_priv_config_t *ec) { +static int loadFromCLI(int argc, char *argv[], n2n_edge_conf_t *conf, n2n_tuntap_priv_config_t *ec) { u_char c; while((c = getopt_long(argc, argv, @@ -573,7 +573,7 @@ static char *trim(char *s) { /* *************************************************** */ /* parse the configuration file */ -static int loadFromFile(const char *path, n2n_edge_conf_t *conf, n2n_priv_config_t *ec) { +static int loadFromFile(const char *path, n2n_edge_conf_t *conf, n2n_tuntap_priv_config_t *ec) { char buffer[4096], *line, *key, *value; u_int line_len, opt_name_len; FILE *fd; @@ -791,7 +791,7 @@ int main(int argc, char* argv[]) { tuntap_dev tuntap; /* a tuntap device */ n2n_edge_t *eee; /* single instance for this program */ n2n_edge_conf_t conf; /* generic N2N edge config */ - n2n_priv_config_t ec; /* config used for standalone program execution */ + n2n_tuntap_priv_config_t ec; /* config used for standalone program execution */ #ifndef WIN32 struct passwd *pw = NULL; #endif @@ -893,7 +893,7 @@ int main(int argc, char* argv[]) { traceEvent(TRACE_ERROR, "Failed in edge_init"); exit(1); } - memcpy(&(eee->priv_conf), &ec, sizeof(ec)); + memcpy(&(eee->tuntap_priv_conf), &ec, sizeof(ec)); #ifndef WIN32 if(ec.daemon) { diff --git a/src/edge_utils.c b/src/edge_utils.c index e6cd84f..ff6a1dc 100644 --- a/src/edge_utils.c +++ b/src/edge_utils.c @@ -1503,11 +1503,11 @@ void edge_read_from_tap(n2n_edge_t * eee) { { traceEvent(TRACE_WARNING, "read()=%d [%d/%s]", (signed int)len, errno, strerror(errno)); - traceEvent(TRACE_WARNING, "TAP I/O operation aborted, restart after 10 seconds."); - sleep(10); + traceEvent(TRACE_WARNING, "TAP I/O operation aborted, restart later."); + sleep(3); tuntap_close(&(eee->device)); - tuntap_open(&(eee->device), eee->priv_conf.tuntap_dev_name, eee->priv_conf.ip_mode, eee->priv_conf.ip_addr, - eee->priv_conf.netmask, eee->priv_conf.device_mac, eee->priv_conf.mtu); + 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); } else { diff --git a/win32/n2n_win32.h b/win32/n2n_win32.h index 64bff4a..bd21791 100644 --- a/win32/n2n_win32.h +++ b/win32/n2n_win32.h @@ -11,6 +11,8 @@ #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 @@ -106,6 +108,6 @@ typedef struct tuntap_dev { } tuntap_dev; #define index(a, b) strchr(a, b) - +#define sleep(x) Sleep(x * 1000) #endif