summaryrefslogtreecommitdiff
path: root/libc/inet
diff options
context:
space:
mode:
authorEd W <lists@wildgooses.com>2012-04-16 23:27:55 +0100
committerBernhard Reutner-Fischer <rep.dot.nop@gmail.com>2012-04-17 11:06:27 +0200
commit97214b87d6317d75e9a7f6dd69148724c2675e4b (patch)
treec14028a261d1fedcf9020a9dded637a65fa7936d /libc/inet
parentf6f98ad8665811e0d30ee130fc65d965aee6be04 (diff)
inet: adjust handling of cacnonname in getaddrinfo
Posix says that canonname should use the text representation of an IP address when a numerical nodename given See: http://pubs.opengroup.org/onlinepubs/9699919799/functions/getaddrinfo.html Signed-off-by: Ed Wildgoose <lists@wildgooses.com> Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
Diffstat (limited to 'libc/inet')
-rw-r--r--libc/inet/getaddrinfo.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/libc/inet/getaddrinfo.c b/libc/inet/getaddrinfo.c
index e7511f6c4..fe0d942d9 100644
--- a/libc/inet/getaddrinfo.c
+++ b/libc/inet/getaddrinfo.c
@@ -628,13 +628,20 @@ gaih_inet(const char *name, const struct gaih_service *service,
char buffer[sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255")];
while (at2 != NULL) {
- if (req->ai_flags & AI_CANONNAME) {
+ c = inet_ntop(at2->family, at2->addr, buffer, sizeof(buffer));
+ if (c) {
+ namelen = strlen(c) + 1;
+ } else if (req->ai_flags & AI_CANONNAME) {
struct hostent *h = NULL;
int herrno;
struct hostent th;
size_t tmpbuflen = 512;
char *tmpbuf;
+ /* Hint says numeric, but address is not */
+ if (req->ai_flags & AI_NUMERICHOST)
+ return -EAI_NONAME;
+
do {
tmpbuflen *= 2;
tmpbuf = alloca(tmpbuflen);
@@ -656,9 +663,7 @@ gaih_inet(const char *name, const struct gaih_service *service,
return -EAI_SYSTEM;
}
- if (h == NULL)
- c = inet_ntop(at2->family, at2->addr, buffer, sizeof(buffer));
- else
+ if (h != NULL)
c = h->h_name;
if (c == NULL)