2003-09-26 Jeffrey Stedfast * e-host-utils.c (e_gethostbyaddr_r): IPv6 implementation rewritten to use getnameinfo() which is the proper function to use in this case. Fixes bug #46006. Index: e-host-utils.c =================================================================== RCS file: /cvs/gnome/evolution/e-util/e-host-utils.c,v retrieving revision 1.14 diff -u -r1.14 e-host-utils.c --- e-util/e-host-utils.c 29 Apr 2003 02:14:37 -0000 1.14 +++ e-util/e-host-utils.c 26 Sep 2003 15:51:10 -0000 @@ -291,34 +291,18 @@ char *buf, size_t buflen, int *herr) { #ifdef ENABLE_IPv6 - struct addrinfo hints, *res; - const char *name; int retval, len; - if ((name = inet_ntop (type, addr, buf, buflen)) == NULL) { - if (errno == ENOSPC) - return ERANGE; - - return -1; - } - - memset (&hints, 0, sizeof (struct addrinfo)); - hints.ai_flags = AI_CANONNAME; - hints.ai_family = type == AF_INET6 ? PF_INET6 : PF_INET; - hints.ai_socktype = 0; - hints.ai_protocol = 0; - - if ((retval = getaddrinfo (name, NULL, &hints, &res)) != 0) { + if ((retval = getnameinfo (addr, addrlen, buf, buflen, NULL, 0, NI_NAMEREQD)) != 0) { *herr = ai_to_herr (retval); return -1; } - len = ALIGN (strlen (res->ai_canonname) + 1); - if (buflen < IPv6_BUFLEN_MIN + len + res->ai_addrlen + sizeof (char *)) + len = ALIGN (strlen (buf) + 1); + if (buflen < IPv6_BUFLEN_MIN + len + addrlen + sizeof (char *)) return ERANGE; /* h_name */ - strcpy (buf, res->ai_canonname); host->h_name = buf; buf += len; @@ -328,16 +312,8 @@ buf += sizeof (char *); /* h_addrtype and h_length */ - host->h_length = res->ai_addrlen; - if (res->ai_family == PF_INET6) { - host->h_addrtype = AF_INET6; - - addr = (char *) &((struct sockaddr_in6 *) res->ai_addr)->sin6_addr; - } else { - host->h_addrtype = AF_INET; - - addr = (char *) &((struct sockaddr_in *) res->ai_addr)->sin_addr; - } + host->h_length = addrlen; + host->h_addrtype = type; memcpy (buf, addr, host->h_length); addr = buf; @@ -347,8 +323,6 @@ ((char **) buf)[0] = addr; ((char **) buf)[1] = NULL; host->h_addr_list = (char **) buf; - - freeaddrinfo (res); return 0; #else /* No support for IPv6 addresses */