Permalink
Browse files

Fix bug in DNS resolution - results were ignored (since 8179a1f).

  • Loading branch information...
1 parent e0b284d commit 290f19972e9f7b74f818ae211cb535e32f1f314f @darkk committed Apr 9, 2012
Showing with 5 additions and 5 deletions.
  1. +5 −5 parser.c
View
@@ -295,30 +295,30 @@ static int vp_in_addr(parser_context *context, void *addr, const char *token)
memcpy(addr, &ia, sizeof(ia));
}
else {
- struct addrinfo *addr, hints;
+ struct addrinfo *ainfo, hints;
int err;
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_INET; /* IPv4-only */
hints.ai_socktype = SOCK_STREAM; /* I want to have one address once and ONLY once, that's why I specify socktype and protocol */
hints.ai_protocol = IPPROTO_TCP;
hints.ai_flags = AI_ADDRCONFIG; /* I don't need IPv4 addrs without IPv4 connectivity */
- err = getaddrinfo(token, NULL, &hints, &addr);
+ err = getaddrinfo(token, NULL, &hints, &ainfo);
if (err == 0) {
int count, taken;
struct addrinfo *iter;
struct sockaddr_in *resolved_addr;
- for (iter = addr, count = 0; iter; iter = iter->ai_next, ++count)
+ for (iter = ainfo, count = 0; iter; iter = iter->ai_next, ++count)
;
taken = rand() % count;
- for (iter = addr; taken > 0; iter = iter->ai_next, --taken)
+ for (iter = ainfo; taken > 0; iter = iter->ai_next, --taken)
;
resolved_addr = (struct sockaddr_in*)iter->ai_addr;
assert(resolved_addr->sin_family == iter->ai_family && iter->ai_family == AF_INET);
if (count != 1)
log_error(LOG_WARNING, "%s resolves to %d addresses, using %s",
token, count, inet_ntoa(resolved_addr->sin_addr));
memcpy(addr, &resolved_addr->sin_addr, sizeof(ia));
- freeaddrinfo(addr);
+ freeaddrinfo(ainfo);
}
else {
if (err == EAI_SYSTEM)

0 comments on commit 290f199

Please sign in to comment.