Hi,
I discovered that if you do a lookup of an IPv4 literal (like
"127.0.0.1") with address family set to AF_INET6, ares_gethostbyname()
won't find anything, although it _will_ do proper fallback from v6 to
v4 for regular DNS host names (and it will resolve IPv4 literals for
AF_INET, and IPv6 literals for AF_INET6). This seems pretty
inconsistent, so I pulled together a patch. Please take a look -- I'll
submit it during the weekend if nobody complains.
Index: ipv6-wip/google3/third_party/ares/ares_gethostbyname.c
===================================================================
--- ipv6-wip.orig/google3/third_party/ares/ares_gethostbyname.c 2009-08-21
17:06:16.000000000 +0200
+++ ipv6-wip/google3/third_party/ares/ares_gethostbyname.c 2009-08-21
17:06:21.000000000 +0200
@@ -232,15 +232,16 @@ static int fake_hostent(const char *name
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++;
}
@@ -249,12 +250,15 @@ static int fake_hostent(const char *name
/* 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)
Thanks!
/* Steinar */
-- Software Engineer, Google SwitzerlandReceived on 2009-08-21