From a7ba0d908da23cdf79bf353eb7f8b00192cc11b8 Mon Sep 17 00:00:00 2001 From: Dominick Meglio Date: Fri, 8 Apr 2005 15:41:31 +0000 Subject: Made ares_gethostbyaddr support IPv6 by specifying AF_INET6 as the family --- ares/ares__get_hostent.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'ares/ares__get_hostent.c') diff --git a/ares/ares__get_hostent.c b/ares/ares__get_hostent.c index 0b043423e..29df0dd98 100644 --- a/ares/ares__get_hostent.c +++ b/ares/ares__get_hostent.c @@ -31,11 +31,13 @@ #include "ares.h" #include "ares_private.h" -int ares__get_hostent(FILE *fp, struct hostent **host) +int ares__get_hostent(FILE *fp, int family, struct hostent **host) { char *line = NULL, *p, *q, *canonical, **alias; int status, linesize, end_at_hostname, naliases; struct in_addr addr; + struct in6_addr addr6; + int addrlen = sizeof(struct in_addr); struct hostent *hostent = NULL; while ((status = ares__read_line(fp, &line, &linesize)) == ARES_SUCCESS) @@ -56,6 +58,17 @@ int ares__get_hostent(FILE *fp, struct hostent **host) *p = 0; addr.s_addr = inet_addr(line); if (addr.s_addr == INADDR_NONE) + { + if (ares_inet_pton(AF_INET6, line, &addr6) > 0) + { + if (family != AF_INET6) + continue; + addrlen = sizeof(struct in6_addr); + } + else + continue; + } + else if (family != AF_INET) continue; /* Get the canonical hostname. */ @@ -100,7 +113,7 @@ int ares__get_hostent(FILE *fp, struct hostent **host) hostent->h_addr_list = malloc(2 * sizeof(char *)); if (!hostent->h_addr_list) break; - hostent->h_addr_list[0] = malloc(sizeof(struct in_addr)); + hostent->h_addr_list[0] = malloc(addrlen); if (!hostent->h_addr_list[0]) break; hostent->h_aliases = malloc((naliases + 1) * sizeof(char *)); @@ -134,9 +147,12 @@ int ares__get_hostent(FILE *fp, struct hostent **host) } hostent->h_aliases[naliases] = NULL; - hostent->h_addrtype = AF_INET; - hostent->h_length = sizeof(struct in_addr); - memcpy(hostent->h_addr_list[0], &addr, sizeof(struct in_addr)); + hostent->h_addrtype = family; + hostent->h_length = addrlen; + if (family == AF_INET) + memcpy(hostent->h_addr_list[0], &addr, addrlen); + else if (family == AF_INET6) + memcpy(hostent->h_addr_list[0], &addr6, addrlen); hostent->h_addr_list[1] = NULL; *host = hostent; free(line); -- cgit v1.2.3