From: Guus Sliepen Date: Mon, 9 Feb 2015 14:16:36 +0000 (+0100) Subject: Always call res_init() before getaddrinfo(). X-Git-Tag: release-1.1pre12~205 X-Git-Url: https://tinc-vpn.org/git/browse?a=commitdiff_plain;h=0b310bf406dbe58afe37fa31156b9ea47599d7be;p=tinc Always call res_init() before getaddrinfo(). Unfortunately, glibc assumes that /etc/resolv.conf is a static file that never changes. Even on servers, /etc/resolv.conf might be a dynamically generated file, and we never know when it changes. So just call res_init() every time, so glibc uses up-to-date nameserver information. --- diff --git a/src/have.h b/src/have.h index 80f405e9..9dc3b04c 100644 --- a/src/have.h +++ b/src/have.h @@ -198,6 +198,18 @@ #include #endif +#ifdef HAVE_ARPA_NAMESER_H +#include +#endif + +#ifdef HAVE_RESOLV_H +#include +#endif + +#ifdef STATUS +#undef STATUS +#endif + #ifdef HAVE_MINGW #define SLASH "\\" #else diff --git a/src/net.c b/src/net.c index 5b32bd40..1ce8071d 100644 --- a/src/net.c +++ b/src/net.c @@ -36,10 +36,6 @@ #include "subnet.h" #include "xalloc.h" -#ifdef HAVE_RESOLV_H -#include -#endif - int contradicting_add_edge = 0; int contradicting_del_edge = 0; static int sleeptime = 10; @@ -313,9 +309,6 @@ static void sighup_handler(void *data) { static void sigalrm_handler(void *data) { logger(DEBUG_ALWAYS, LOG_NOTICE, "Got %s signal", strsignal(((signal_t *)data)->signum)); -#ifdef HAVE_DECL_RES_INIT - res_init(); -#endif retry(); } #endif diff --git a/src/net_setup.c b/src/net_setup.c index 1ae5edf8..7f51fe4b 100644 --- a/src/net_setup.c +++ b/src/net_setup.c @@ -663,6 +663,9 @@ static bool add_listen_address(char *address, bool bindto) { hint.ai_protocol = IPPROTO_TCP; hint.ai_flags = AI_PASSIVE; +#ifdef HAVE_DECL_RES_INIT + res_init(); +#endif int err = getaddrinfo(address && *address ? address : NULL, port, &hint, &ai); free(address); diff --git a/src/netutl.c b/src/netutl.c index 989a1526..3ea5d4a2 100644 --- a/src/netutl.c +++ b/src/netutl.c @@ -39,6 +39,9 @@ struct addrinfo *str2addrinfo(const char *address, const char *service, int sock hint.ai_family = addressfamily; hint.ai_socktype = socktype; +#ifdef HAVE_DECL_RES_INIT + res_init(); +#endif err = getaddrinfo(address, service, &hint, &ai); if(err) {