From c4764c2f28a99600fd41fe1b19c460fd6a7a4710 Mon Sep 17 00:00:00 2001 From: Seraphime Kirkovski Date: Thu, 27 Aug 2020 14:31:17 +0300 Subject: [PATCH] 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) --- ares_gethostbyname.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/ares_gethostbyname.c b/ares_gethostbyname.c index ecd03e79..ac19afbd 100644 --- a/ares_gethostbyname.c +++ b/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);