From d7654397a814fda211e4b2dab375dae69d9e101f Mon Sep 17 00:00:00 2001 From: fengdaolong Date: Tue, 8 Dec 2020 22:46:40 +0800 Subject: [PATCH] Fix the problem of running edge, IP or domain name resolution failure under Windows system. (#527) --- src/edge.c | 7 +++++++ src/edge_utils.c | 3 --- src/n2n.c | 2 +- src/sn_utils.c | 4 ++++ win32/wintap.c | 5 +++++ win32/wintap.h | 1 + 6 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/edge.c b/src/edge.c index f0db3cb..fd87374 100644 --- a/src/edge.c +++ b/src/edge.c @@ -771,6 +771,9 @@ int main(int argc, char* argv[]) { #ifdef HAVE_LIBCAP cap_t caps; #endif +#ifdef WIN32 + initWin32(); +#endif /* Defaults */ edge_init_conf_defaults(&conf); @@ -955,6 +958,10 @@ int main(int argc, char* argv[]) { tuntap_close(&eee->device); edge_term(eee); +#ifdef WIN32 + destroyWin32(); +#endif + return(rc); } diff --git a/src/edge_utils.c b/src/edge_utils.c index a1dc9b6..0b3c571 100644 --- a/src/edge_utils.c +++ b/src/edge_utils.c @@ -191,9 +191,6 @@ n2n_edge_t* edge_init(const n2n_edge_conf_t *conf, int *rv) { goto edge_init_error; } -#ifdef WIN32 - initWin32(); -#endif memcpy(&eee->conf, conf, sizeof(*conf)); eee->curr_sn = eee->conf.supernodes; diff --git a/src/n2n.c b/src/n2n.c index a1af4f1..f3a2828 100644 --- a/src/n2n.c +++ b/src/n2n.c @@ -277,7 +277,7 @@ int supernode2sock(n2n_sock_t * sn, const n2n_sn_name_t addrIn) { freeaddrinfo(ainfo); /* free everything allocated by getaddrinfo(). */ ainfo = NULL; } else { - traceEvent(TRACE_WARNING, "Failed to resolve supernode host %s", supernode_host); + traceEvent(TRACE_WARNING, "Failed to resolve supernode host %s, %d: %s", supernode_host, nameerr, gai_strerror(nameerr)); rv = -2; } diff --git a/src/sn_utils.c b/src/sn_utils.c index 28666a3..5a02627 100644 --- a/src/sn_utils.c +++ b/src/sn_utils.c @@ -351,6 +351,10 @@ void sn_term(n2n_sn_t *sss) } free(re); } + +#ifdef WIN32 + destroyWin32(); +#endif } /** Determine the appropriate lifetime for new registrations. diff --git a/win32/wintap.c b/win32/wintap.c index 48a10cf..2a48608 100644 --- a/win32/wintap.c +++ b/win32/wintap.c @@ -20,6 +20,11 @@ void initWin32() { } } + +void destroyWin32() { + WSACleanup(); +} + struct win_adapter_info { HANDLE handle; char adapterid[1024]; diff --git a/win32/wintap.h b/win32/wintap.h index 443d941..138e4bc 100644 --- a/win32/wintap.h +++ b/win32/wintap.h @@ -64,6 +64,7 @@ #define TAP_COMPONENT_ID "tap0801" extern void initWin32(); +extern void destroyWin32(); extern void win_print_available_adapters(); #endif \ No newline at end of file