Browse Source

Refine #669: Bind to loopback for local resolver

pull/671/head
Max Lv 8 years ago
parent
commit
a9b85a5216
1 changed files with 12 additions and 0 deletions
  1. 12
      src/resolv.c

12
src/resolv.c

@ -46,6 +46,7 @@
#include "resolv.h" #include "resolv.h"
#include "utils.h" #include "utils.h"
#include "netutils.h"
/* /*
* Implement DNS resolution interface using libudns * Implement DNS resolution interface using libudns
@ -107,6 +108,17 @@ int resolv_init(struct ev_loop *loop, char **nameservers, int nameserver_num, in
FATAL("Failed to open DNS resolver socket"); FATAL("Failed to open DNS resolver socket");
} }
if (nameserver_num == 1 && nameservers != NULL) {
if (strncmp("127.0.0.1", nameservers[0], 9)
|| strncmp("::1", nameservers[0], 3)) {
if (verbose) {
LOGI("bind UDP resolver to %s", nameservers[0]);
}
if (bind_to_address(sockfd, nameservers[0]) == -1)
ERROR("bind_to_address");
}
}
#ifdef __MINGW32__ #ifdef __MINGW32__
setnonblocking(sockfd); setnonblocking(sockfd);
#else #else

Loading…
Cancel
Save