summaryrefslogtreecommitdiff
path: root/ares_gethostbyname.c
diff options
context:
space:
mode:
authorSteinar H. Gunderson <sesse@google.com>2009-08-27 09:53:55 (GMT)
committerSteinar H. Gunderson <sesse@google.com>2009-08-27 09:53:55 (GMT)
commitcef560e871533a197acfdc5106481105ef244194 (patch)
treea5708158cc5d2d4b48bfb4aa343a5aa97124fcf3 /ares_gethostbyname.c
parentc3872cb5dc9a29c4ec2c8863f661df7a8626ce11 (diff)
downloadc-ares-cef560e871533a197acfdc5106481105ef244194.zip
c-ares-cef560e871533a197acfdc5106481105ef244194.tar.gz
c-ares-cef560e871533a197acfdc5106481105ef244194.tar.bz2
Support lookup of IPv4 literals in ares_gethostbyname(), even when the address family is set to AF_INET6.
Diffstat (limited to 'ares_gethostbyname.c')
-rw-r--r--ares_gethostbyname.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/ares_gethostbyname.c b/ares_gethostbyname.c
index 1ef25c7..d708dfb 100644
--- a/ares_gethostbyname.c
+++ b/ares_gethostbyname.c
@@ -245,15 +245,16 @@ static int fake_hostent(const char *name, int family, ares_host_callback callbac
struct in_addr in;
struct in6_addr in6;
- if (family == AF_INET)
+ if (family == AF_INET || family == AF_INET6)
{
/* It only looks like an IP address if it's all numbers and dots. */
- int numdots = 0;
+ int numdots = 0, valid = 1;
const char *p;
for (p = name; *p; p++)
{
if (!ISDIGIT(*p) && *p != '.') {
- return 0;
+ valid = 0;
+ break;
} else if (*p == '.') {
numdots++;
}
@@ -262,12 +263,15 @@ static int fake_hostent(const char *name, int family, ares_host_callback callbac
/* if we don't have 3 dots, it is illegal
* (although inet_addr doesn't think so).
*/
- if (numdots != 3)
+ if (numdots != 3 || !valid)
result = 0;
else
result = ((in.s_addr = inet_addr(name)) == INADDR_NONE ? 0 : 1);
+
+ if (result)
+ family = AF_INET;
}
- else if (family == AF_INET6)
+ if (family == AF_INET6)
result = (ares_inet_pton(AF_INET6, name, &in6) < 1 ? 0 : 1);
if (!result)