[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#663752: libc6: getaddrinfo AI_V4MAPPED & AF_INET6 returns AF_INET addresses



Package: libc6
Version: 2.13-27
Severity: normal
Tags: ipv6

getaddrinfo() does not correctly implement the AI_V4MAPPED flag.
When requesting AF_INET6 addresses using the AI_V4MAPPED | AI_ALL
flags in the request, IPv4 addresses are returned as AF_INET, ie.
as standard IPv4 addresses, not IPv6-mapped IPv4 addresses.

A test program is attached that resolves the given hostname and prints
the addresses returned.

To compile:
  gcc gai2.c
To run:
  ./a.out he.net

Observed output:
  AF_INET: [216.218.186.2]:80
  AF_INET6: [2001:470:0:76::2]:80

Expected output (observed on RHEL 5.2, glibc 2.5-24):
  AF_INET6: [::ffff:216.218.186.2]:80
  AF_INET6: [2001:470:0:76::2]:80


-- System Information:
Debian Release: 6.0.4
  APT prefers stable
  APT policy: (990, 'stable'), (500, 'stable-updates'), (500, 'testing')
Architecture: amd64 (x86_64)

Kernel: Linux 3.0.0-1-amd64 (SMP w/2 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_MESSAGES to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
ANSI_X3.4-1968)
Shell: /bin/sh linked to /bin/dash

Versions of packages libc6 depends on:
ii  libc-bin                      2.13-27    Embedded GNU C Library: Binaries
ii  libgcc1                       1:4.6.3-1  GCC support library

libc6 recommends no packages.

Versions of packages libc6 suggests:
ii  debconf [debconf-2.0]         1.5.36.1   Debian configuration management sy
ii  glibc-doc                     2.11.3-2   Embedded GNU C Library: Documentat
pn  locales                       <none>     (no description available)

-- debconf information:
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
	LANGUAGE = (unset),
	LC_ALL = (unset),
	LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_MESSAGES to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
* glibc/upgrade: true
  glibc/disable-screensaver:
  glibc/restart-failed:
* glibc/restart-services: gdm openbsd-inetd exim4 cups cron atd apache2
* libraries/restart-without-asking: true
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <string.h>

int main(int argc, char *argv[]) {
    struct addrinfo hints, *addrs = NULL, *a = NULL;

    if (argc < 2) {
        fprintf(stderr, "Usage: %s <host>\n", argv[0]);
        return 1;
    }

    memset(&hints, 0, sizeof(hints));

    hints.ai_family = AF_INET6;
    hints.ai_flags = AI_V4MAPPED | AI_ALL;
    hints.ai_socktype = SOCK_STREAM;

    int e = getaddrinfo(argv[1], "80", &hints, &addrs);
    if (e) {
        fprintf(stderr, "getaddrinfo failed: %s\n", gai_strerror(e));
        return 2;
    }

    for (a = addrs; a; a = a->ai_next) {
        char host[NI_MAXHOST], port[NI_MAXSERV];

        e = getnameinfo(a->ai_addr, a->ai_addrlen,
                host, sizeof(host),
                port, sizeof(port),
                NI_NUMERICHOST | NI_NUMERICSERV);

        if (e)
            fprintf(stderr, "getnameinfo failed: %s\n", gai_strerror(e));

        printf("%s: [%s]:%s\n",
                a->ai_family == AF_INET ? "AF_INET" :
                a->ai_family == AF_INET6 ? "AF_INET6" :
                a->ai_family == AF_UNSPEC ? "AF_UNSPEC" :
                "?",
                e ? "?" : host,
                e ? "?" : port
                );
    }

    freeaddrinfo(addrs);

    return 0;
}

Reply to: