Summary: | sys-libs/glibc (?) getaddrinfo() doesn't return addresses RFC-3484 compliant when using NULL as node | ||
---|---|---|---|
Product: | Gentoo Linux | Reporter: | Marco Meier <mmeier> |
Component: | [OLD] Core system | Assignee: | Gentoo Toolchain Maintainers <toolchain> |
Status: | RESOLVED UPSTREAM | ||
Severity: | normal | CC: | hans |
Priority: | High | ||
Version: | unspecified | ||
Hardware: | All | ||
OS: | Linux | ||
URL: | http://sourceware.org/bugzilla/show_bug.cgi?id=14211 | ||
See Also: | http://sourceware.org/bugzilla/show_bug.cgi?id=14211 | ||
Whiteboard: | |||
Package list: | Runtime testing required: | --- | |
Attachments: | gai_bug.c |
Description
Marco Meier
2009-08-20 10:00:04 UTC
(In reply to comment #0) of course i meant "returns IPv4 addresses first, and then IPv6 ones." please post a self contained test case as an attachment for us to research with I've ran into this bug (if it is one) as well, while trying to implement an address-family agnostic network server using the example code on http://www.akkadia.org/drepper/userapi-ipv6.html as a guide. As the comments for the server example code say, the code depends on IPv6 addresses being sorted first by getaddrinfo (as RFC 3484 supposedly specifies) to work around an issue with the Linux kernel where it won't let you listen on a IPv4 and IPv6 socket using the same port. With IPv6 results sorted first, it will try binding to the IPv6 result first, then IPv4. the IPv4 socket will then fail to bind with EADDRINUSE on Linux, but the IPv6 socket will be able to receive connections from IPv4 as V4-mapped addresses anyway, so all is well. Right now the example code doesn't work, because with the IPv4 address being returned first, it will bind to it, and then binding to the IPv6 address fails, and so only IPv4 connections work. Any application that is written using Drepper's guide should be affected by this, but considering how old this bug report is, it doesn't seem to have affected many applications.. A simple 'workaround' seems to be to just specify AF_INET6 in the hints.ai_family field, and just let it bind to the IPv6 socket only. I'm not sure what kind of problems this potentially has (i.e. on a system with IPv6 disabled). Alternatively you could run through the results twice, ignoring all except IPv6 at first, then run through the rest ignoring IPv6. (essentially doing the sorting yourself to ensure IPv6 is handled first) That said, the getaddrinfo manpage suggests it is meant to follow RFC 3484, and that IPv6 results should be returned first so I guess this could be considered a bug. I'll attach some trimmed down example code Created attachment 265963 [details]
gai_bug.c
Here's a small test-case, when compiled and run on a FreeBSD system it does:
$ gcc gai_bug.c && ./a.out 4242
this is an IPv6 result
this is an IPv4 result
as expected. But on gentoo with glibc-2.13-r1 it does:
$ gcc gai_bug.c && ./a.out 4242
this is an IPv4 result
this is an IPv6 result
thanks ... moved upstream |