Always call res_init() before getaddrinfo().
authorGuus Sliepen <guus@tinc-vpn.org>
Mon, 9 Feb 2015 14:16:36 +0000 (15:16 +0100)
committerGuus Sliepen <guus@tinc-vpn.org>
Mon, 9 Feb 2015 14:16:36 +0000 (15:16 +0100)
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.

src/have.h
src/net.c
src/net_setup.c
src/netutl.c

index 80f405e..9dc3b04 100644 (file)
 #include <netinet/if_ether.h>
 #endif
 
+#ifdef HAVE_ARPA_NAMESER_H
+#include <arpa/nameser.h>
+#endif
+
+#ifdef HAVE_RESOLV_H
+#include <resolv.h>
+#endif
+
+#ifdef STATUS
+#undef STATUS
+#endif
+
 #ifdef HAVE_MINGW
 #define SLASH "\\"
 #else
index 5b32bd4..1ce8071 100644 (file)
--- a/src/net.c
+++ b/src/net.c
 #include "subnet.h"
 #include "xalloc.h"
 
-#ifdef HAVE_RESOLV_H
-#include <resolv.h>
-#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
index 1ae5edf..7f51fe4 100644 (file)
@@ -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);
 
index 989a152..3ea5d4a 100644 (file)
@@ -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) {