ares_gethostbyname: Fix AF_UNSPEC support when using an ip address (#204)

fake_hostent() was not supporting AF_UNSPEC, so when an ip address was specified when using AF_UNSPEC it would attempt to do a DNS lookup rather than returning a fake hostent using the ip address.

Fix By: Seraphime Kirkovski (@Seraphime)
pull/94/head^2
Seraphime Kirkovski 4 years ago committed by GitHub
parent 5b246d2077
commit c4764c2f28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      ares_gethostbyname.c

@ -258,7 +258,7 @@ static int fake_hostent(const char *name, int family,
struct in_addr in;
struct ares_in6_addr in6;
if (family == AF_INET || family == AF_INET6)
if (family == AF_INET || family == AF_UNSPEC)
{
/* It only looks like an IP address if it's all numbers and dots. */
int numdots = 0, valid = 1;
@ -281,8 +281,11 @@ static int fake_hostent(const char *name, int family,
else
result = (ares_inet_pton(AF_INET, name, &in) < 1 ? 0 : 1);
if (result)
family = AF_INET;
/*
* Set address family in case of failure,
* as we will try to convert it later afterwards
*/
family = result ? AF_INET : AF_INET6;
}
if (family == AF_INET6)
result = (ares_inet_pton(AF_INET6, name, &in6) < 1 ? 0 : 1);

Loading…
Cancel
Save