> Without looking at the code, ahost doesn't seem to identify the address as
> an IPv6 address, but a *name*.
Looked at it and done a fix. It works fine now. A patch:
Index: ahost.c
===================================================================
RCS file: /cvsroot/curl/curl/ares/ahost.c,v
retrieving revision 1.7
diff -u -r1.7 ahost.c
--- ahost.c 6 Oct 2004 07:50:18 -0000 1.7
+++ ahost.c 9 Nov 2005 20:32:31 -0000
@@ -31,11 +31,20 @@
#include <string.h>
#include "ares.h"
#include "ares_dns.h"
+#include "inet_ntop.h"
+#include "inet_net_pton.h"
#ifndef INADDR_NONE
#define INADDR_NONE 0xffffffff
#endif
+#ifndef HAVE_STRUCT_IN6_ADDR
+struct in6_addr
+{
+ unsigned char s6_addr[16];
+};
+#endif
+
static void callback(void *arg, int status, struct hostent *host);
static void usage(void);
@@ -45,7 +54,8 @@
int status, nfds;
fd_set read_fds, write_fds;
struct timeval *tvp, tv;
- struct in_addr addr;
+ struct in_addr addr4;
+ struct in6_addr addr6;
#ifdef WIN32
WORD wVersionRequested = MAKEWORD(1,1);
@@ -66,14 +76,21 @@
/* Initiate the queries, one per command-line argument. */
for (argv++; *argv; argv++)
{
- addr.s_addr = inet_addr(*argv);
- if (addr.s_addr == INADDR_NONE)
- ares_gethostbyname(channel, *argv, AF_INET, callback, *argv);
- else
+ if (ares_inet_pton(AF_INET, *argv, &addr4) == 1)
{
- ares_gethostbyaddr(channel, &addr, sizeof(addr), AF_INET, callback,
+ ares_gethostbyaddr(channel, &addr4, sizeof(addr4), AF_INET, callback,
*argv);
}
+ else if (ares_inet_pton(AF_INET6, *argv, &addr6) == 1)
+ {
+ ares_gethostbyaddr(channel, &addr6, sizeof(addr6), AF_INET6, callback,
+ *argv);
+ }
+ else
+ {
+ /* assume user wants A-records */
+ ares_gethostbyname(channel, *argv, AF_INET, callback, *argv);
+ }
}
/* Wait for all queries to complete. */
@@ -95,7 +112,6 @@
static void callback(void *arg, int status, struct hostent *host)
{
- struct in_addr addr;
char **p;
if (status != ARES_SUCCESS)
@@ -106,8 +122,10 @@
for (p = host->h_addr_list; *p; p++)
{
- memcpy(&addr, *p, sizeof(struct in_addr));
- printf("%-32s\t%s\n", host->h_name, inet_ntoa(addr));
+ char addr_buf[46] = "??";
+
+ ares_inet_ntop(host->h_addrtype, *p, addr_buf, sizeof(addr_buf));
+ printf("%-32s\t%s\n", host->h_name, addr_buf);
}
}
------------------
Okay to commit?
--gv
Received on Thu Nov 10 19:58:31 2005