You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
2.0 KiB

  1. From 290f19972e9f7b74f818ae211cb535e32f1f314f Mon Sep 17 00:00:00 2001
  2. From: Leonid Evdokimov <leon@darkk.net.ru>
  3. Date: Tue, 10 Apr 2012 00:57:26 +0400
  4. Subject: [PATCH 01/12] Fix bug in DNS resolution - results were ignored (since
  5. 8179a1ff).
  6. ---
  7. parser.c | 10 +++++-----
  8. 1 file changed, 5 insertions(+), 5 deletions(-)
  9. diff --git a/parser.c b/parser.c
  10. index 85d3533..6198828 100644
  11. --- a/parser.c
  12. +++ b/parser.c
  13. @@ -295,22 +295,22 @@ static int vp_in_addr(parser_context *context, void *addr, const char *token)
  14. memcpy(addr, &ia, sizeof(ia));
  15. }
  16. else {
  17. - struct addrinfo *addr, hints;
  18. + struct addrinfo *ainfo, hints;
  19. int err;
  20. memset(&hints, 0, sizeof(hints));
  21. hints.ai_family = AF_INET; /* IPv4-only */
  22. hints.ai_socktype = SOCK_STREAM; /* I want to have one address once and ONLY once, that's why I specify socktype and protocol */
  23. hints.ai_protocol = IPPROTO_TCP;
  24. hints.ai_flags = AI_ADDRCONFIG; /* I don't need IPv4 addrs without IPv4 connectivity */
  25. - err = getaddrinfo(token, NULL, &hints, &addr);
  26. + err = getaddrinfo(token, NULL, &hints, &ainfo);
  27. if (err == 0) {
  28. int count, taken;
  29. struct addrinfo *iter;
  30. struct sockaddr_in *resolved_addr;
  31. - for (iter = addr, count = 0; iter; iter = iter->ai_next, ++count)
  32. + for (iter = ainfo, count = 0; iter; iter = iter->ai_next, ++count)
  33. ;
  34. taken = rand() % count;
  35. - for (iter = addr; taken > 0; iter = iter->ai_next, --taken)
  36. + for (iter = ainfo; taken > 0; iter = iter->ai_next, --taken)
  37. ;
  38. resolved_addr = (struct sockaddr_in*)iter->ai_addr;
  39. assert(resolved_addr->sin_family == iter->ai_family && iter->ai_family == AF_INET);
  40. @@ -318,7 +318,7 @@ static int vp_in_addr(parser_context *context, void *addr, const char *token)
  41. log_error(LOG_WARNING, "%s resolves to %d addresses, using %s",
  42. token, count, inet_ntoa(resolved_addr->sin_addr));
  43. memcpy(addr, &resolved_addr->sin_addr, sizeof(ia));
  44. - freeaddrinfo(addr);
  45. + freeaddrinfo(ainfo);
  46. }
  47. else {
  48. if (err == EAI_SYSTEM)
  49. --
  50. 1.9.1