diff options
author | Ulrich Drepper <drepper@gmail.com> | 2011-06-21 17:03:38 -0400 |
---|---|---|
committer | Ulrich Drepper <drepper@gmail.com> | 2011-06-21 17:03:38 -0400 |
commit | c0244a9dedce43a4b950d91451b16a7cf5408476 (patch) | |
tree | 49e776a11f30fbe72341d873f071145983701c2d /sysdeps/posix/getaddrinfo.c | |
parent | c5e3c2ae59cc8c5d3ad5e1adfd099c726baad862 (diff) | |
download | glibc-c0244a9dedce43a4b950d91451b16a7cf5408476.tar.gz glibc-c0244a9dedce43a4b950d91451b16a7cf5408476.tar.xz glibc-c0244a9dedce43a4b950d91451b16a7cf5408476.zip |
Fix IPv6-only lookups through getaddrinfo
A recent patch introduced a problem where IPv6 lookups happily returned IPv4 addresses.
Diffstat (limited to 'sysdeps/posix/getaddrinfo.c')
-rw-r--r-- | sysdeps/posix/getaddrinfo.c | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/sysdeps/posix/getaddrinfo.c b/sysdeps/posix/getaddrinfo.c index d68ac839a5..3a2737e2cb 100644 --- a/sysdeps/posix/getaddrinfo.c +++ b/sysdeps/posix/getaddrinfo.c @@ -871,16 +871,44 @@ gaih_inet (const char *name, const struct gaih_service *service, } } - no_inet6_data = no_data; - if (status == NSS_STATUS_SUCCESS) { + assert (!no_data); + no_data = 1; + if ((req->ai_flags & AI_CANONNAME) != 0 && canon == NULL) canon = (*pat)->name; while (*pat != NULL) - pat = &((*pat)->next); + { + if ((*pat)->family == AF_INET + && req->ai_family == AF_INET6 + && (req->ai_flags & AI_V4MAPPED) != 0) + { + uint32_t *pataddr = (*pat)->addr; + (*pat)->family = AF_INET6; + pataddr[3] = pataddr[0]; + pataddr[2] = htonl (0xffff); + pataddr[1] = 0; + pataddr[0] = 0; + pat = &((*pat)->next); + no_data = 0; + } + else if ((*pat)->family == AF_UNSPEC + || (*pat)->family == req->ai_family) + { + pat = &((*pat)->next); + + no_data = 0; + if (req->ai_family == AF_INET6) + got_ipv6 = true; + } + else + *pat = ((*pat)->next); + } } + + no_inet6_data = no_data; } else { |