Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 282081 - sys-libs/glibc (?) getaddrinfo() doesn't return addresses RFC-3484 compliant when using NULL as node
Summary: sys-libs/glibc (?) getaddrinfo() doesn't return addresses RFC-3484 compliant ...
Status: RESOLVED UPSTREAM
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Core system (show other bugs)
Hardware: All Linux
: High normal (vote)
Assignee: Gentoo Toolchain Maintainers
URL: http://sourceware.org/bugzilla/show_b...
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-08-20 10:00 UTC by Marco Meier
Modified: 2012-06-09 05:01 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
gai_bug.c (gai_bug.c,824 bytes, text/plain)
2011-03-15 13:41 UTC, Hans Nieser
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Marco Meier 2009-08-20 10:00:04 UTC
Using some code like

    /* ... */
    hint.ai_flags = AI_PASSIVE | AI_ADDRCONFIG;
    getaddrinfo(NULL, serv, &hint, &res);

returns IPv4 addresses first, and then IPv4 ones. According to RFC-3484 this should be vice-versa. It only happens when using NULL as node, with an actual hostname it works as expected.

Reproducible: Always




 # emerge --info 
Portage 2.1.6.13 (default/linux/x86/2008.0/desktop, gcc-4.1.2, glibc-2.9_p20081201-r2, 2.6.28-gentoo i686)
=================================================================
System uname: Linux-2.6.28-gentoo-i686-AMD_Athlon-tm-_64_X2_Dual_Core_Processor_5200+-with-glibc2.0
Timestamp of tree: Thu, 20 Aug 2009 00:45:02 +0000
distcc 3.1 i686-pc-linux-gnu [disabled]
ccache version 2.4 [enabled]
app-shells/bash:     3.2_p39
dev-java/java-config: 1.3.7-r1, 2.1.7
dev-lang/python:     2.5.4-r3
dev-util/ccache:     2.4-r7
dev-util/cmake:      2.6.4
sys-apps/baselayout: 1.12.11.1
sys-apps/sandbox:    1.6-r2
sys-devel/autoconf:  2.13, 2.63
sys-devel/automake:  1.5, 1.7.9-r1, 1.8.5-r3, 1.9.6-r2, 1.10.2
sys-devel/binutils:  2.18-r3
sys-devel/gcc-config: 1.4.1
sys-devel/libtool:   1.5.26
virtual/os-headers:  2.6.27-r2
ACCEPT_KEYWORDS="x86"
CBUILD="i686-pc-linux-gnu"
CFLAGS="-O3 -mtune=athlon64 -pipe"
CHOST="i686-pc-linux-gnu"
CONFIG_PROTECT="/etc /usr/kde/3.5/env /usr/kde/3.5/share/config /usr/kde/3.5/shutdown /usr/share/config"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/env.d /etc/env.d/java/ /etc/fonts/fonts.conf /etc/gconf /etc/php/apache2-php5/ext-active/ /etc/php/cgi-php5/ext-active/ /etc/php/cli-php5/ext-active/ /etc/revdep-rebuild /etc/sandbox.d /etc/terminfo /etc/texmf/language.dat.d /etc/texmf/language.def.d /etc/texmf/updmap.d /etc/texmf/web2c /etc/udev/rules.d"
CXXFLAGS="-O3 -mtune=athlon64 -pipe"
DISTDIR="/mnt/data/portage/dist"
FEATURES="ccache distlocks fixpackages parallel-fetch protect-owned sandbox sfperms strict unmerge-orphans userfetch"
GENTOO_MIRRORS="ftp://mirror.netcologne.de/gentoo/ ftp://ftp.join.uni-muenster.de/pub/linux/distributions/gentoo ftp://sunsite.informatik.rwth-aachen.de/pub/Linux/gentoo ftp://ftp.join.uni-muenster.de/pub/linux/distributions/gentoo ftp://gentoo.mirror.dkm.cz/pub/gentoo/"
LANG="en_US.ISO-8859-15"
LC_ALL="en_US.ISO-8859-15"
LDFLAGS="-Wl,-O1"
LINGUAS="en de"
MAKEOPTS="-j3"
PKGDIR="/usr/portage/packages"
PORTAGE_CONFIGROOT="/"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --compress --force --whole-file --delete --stats --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages"
PORTAGE_TMPDIR="/mnt/data/portage/build"
PORTDIR="/usr/portage"
SYNC="rsync://rsync.europe.gentoo.org/gentoo-portage"
USE="3dfx 3dnow 3dnowext X a52 aac aalib acl acpi alsa ao apache2 audiofile bash-completion bcmath berkdb bluetooth branding bzip2 cairo calendar caps cdda cddax cddb cdparanoia cdr cli cracklib crypt cups curl curlwrappers dbus dga directfb dri dts dvd dvdnav dvdr dvdread eds emboss encode esd evo exif expat fam ffmpeg filepro firefox flac flatfile fortran ftp gd gdbm geoip gif glut gnome gnustep gnutls gpm gstreamer gtk gtk2 guile hal iconv idn imagemagick imap imlib ipv6 isdnlog jack java jpeg ldap lesstif libnotify lirc lm_sensors lzo mad matroska mcal memlimit mhash mikmod milter mime mmap mmng mmx motif mp3 mp4 mpeg mpi mplayer mudflap musepack musicbrainz mysql mysqli nas ncurses neXt nis nls nntp nptl nptlonly nsplugin ogg opengl openmp pam pcre pdf perl php png posix ppds pppd python qt3 qt3support qt4 quicktime rar rdesktop readline reflection samba scanner sdl session slang sndfile snmp sox spell spl sse sse2 ssl startup-notification stream svg svga sysfs tcl tcltk tcpd threads tiff tk tokenizer truetype unicode upnp usb v4l vcd vdr vhosts vidix vim-syntax vorbis wifi win32codecs wxwindows x264 x86 xine xinerama xml xorg xosd xpm xulrunner xv xvid zlib zvbi" ALSA_CARDS="ali5451 als4000 atiixp atiixp-modem bt87x ca0106 cmipci emu10k1 emu10k1x ens1370 ens1371 es1938 es1968 fm801 hda-intel intel8x0 intel8x0m maestro3 trident usb-audio via82xx via82xx-modem ymfpci" ALSA_PCM_PLUGINS="adpcm alaw asym copy dmix dshare dsnoop empty extplug file hooks iec958 ioplug ladspa lfloat linear meter mmap_emul mulaw multi null plug rate route share shm softvol" APACHE2_MODULES="actions alias auth_basic auth_digest authn_anon authn_dbd authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache dav dav_fs dav_lock dbd deflate dir disk_cache env expires ext_filter file_cache filter headers ident imagemap include info log_config logio mem_cache mime mime_magic negotiation proxy proxy_ajp proxy_balancer proxy_connect proxy_http rewrite setenvif so speling status unique_id userdir usertrack vhost_alias" ELIBC="glibc" INPUT_DEVICES="keyboard mouse evdev" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LINGUAS="en de" USERLAND="GNU" VIDEO_CARDS="nvidia nv v4l"
Unset:  CPPFLAGS, CTARGET, EMERGE_DEFAULT_OPTS, FFLAGS, INSTALL_MASK, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS, PORTDIR_OVERLAY
Comment 1 Marco Meier 2009-08-20 20:27:26 UTC
(In reply to comment #0)

of course i meant "returns IPv4 addresses first, and then IPv6 ones."
Comment 2 SpanKY gentoo-dev 2010-06-08 04:24:38 UTC
please post a self contained test case as an attachment for us to research with
Comment 3 Hans Nieser 2011-03-15 12:44:27 UTC
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
Comment 4 Hans Nieser 2011-03-15 13:41:23 UTC
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
Comment 5 SpanKY gentoo-dev 2012-06-09 05:01:10 UTC
thanks ... moved upstream