From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9731 invoked by alias); 26 Aug 2013 06:29:45 -0000 Mailing-List: contact glibc-bugs-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: glibc-bugs-owner@sourceware.org Received: (qmail 9709 invoked by uid 48); 26 Aug 2013 06:29:42 -0000 From: "siddhesh at redhat dot com" To: glibc-bugs@sourceware.org Subject: [Bug nscd/15890] New: GETAI(AF_UNSPEC) does not return both IPv6 and IPv4 addresses on first request from /etc/hosts Date: Mon, 26 Aug 2013 06:29:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: glibc X-Bugzilla-Component: nscd X-Bugzilla-Version: unspecified X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: siddhesh at redhat dot com X-Bugzilla-Status: NEW X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: siddhesh at redhat dot com X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter cc Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://sourceware.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2013-08/txt/msg00149.txt.bz2 http://sourceware.org/bugzilla/show_bug.cgi?id=15890 Bug ID: 15890 Summary: GETAI(AF_UNSPEC) does not return both IPv6 and IPv4 addresses on first request from /etc/hosts Product: glibc Version: unspecified Status: NEW Severity: normal Priority: P2 Component: nscd Assignee: siddhesh at redhat dot com Reporter: siddhesh at redhat dot com CC: drepper.fsp at gmail dot com GETAI only returns the IPv4 result via nscd on first request via getaddrinfo (PF_UNSPEC) if the host is resolved from /etc/hosts (localhost for example). One may run `nscd -i hosts` and then call getaddrinfo to work around this. How to reproduce: Sample program: /* * Sorry about the state of this code. It's a quick hack to debug case 00836659 * (nscd caching problem). */ #include #include #include #include #include #include #include #ifndef NI_MAXHOST #define NI_MAXHOST 1025 #endif int main(int argc, char *argv[]) { struct addrinfo *result; struct addrinfo hints = {0}; struct addrinfo *res; int error; char *host = argv[1]; if (argc > 2) { if (strcasecmp(argv[1], "AF_INET6") == 0) hints.ai_family = AF_INET6; if (strcasecmp(argv[1], "AF_INET") == 0) hints.ai_family = AF_INET; host = argv[2]; } printf("Hints family=%d\n", hints.ai_family); /* resolve the domain name into a list of addresses */ error = getaddrinfo(host, NULL, &hints, &result); if (error != 0) { if (error == EAI_SYSTEM) { perror("getaddrinfo"); } else { fprintf(stderr, "error in getaddrinfo: %s\n", gai_strerror(error)); } exit(EXIT_FAILURE); } /* loop over all returned results and do inverse lookup */ for (res = result; res != NULL; res = res->ai_next) { char hostname[NI_MAXHOST] = ""; char buf[130] = {0}; error = getnameinfo(res->ai_addr, res->ai_addrlen, hostname, NI_MAXHOST, NULL, 0, 0); if (error != 0) { fprintf(stderr, "error in getnameinfo: %s\n", gai_strerror(error)); continue; } if (*hostname != '\0') { if (res->ai_family == AF_INET) inet_ntop(res->ai_family, &((struct sockaddr_in *)res->ai_addr)->sin_addr, buf, sizeof(buf)); if (res->ai_family == AF_INET6) inet_ntop(res->ai_family, &((struct sockaddr_in6 *)res->ai_addr)->sin6_addr, buf, sizeof(buf)); printf("host=%s, family=%d addr=%s\n", hostname, res->ai_family, buf); } } freeaddrinfo(result); printf("\n"); return 0; } Delete nscd cache, Build and run program: # service nscd stop # rm -f /var/db/nscd/* # service nscd start # gcc foo.c # ./a.out localhost Actual Result: Hints family=0 host=localhost, family=2 addr=127.0.0.1 host=localhost, family=2 addr=127.0.0.1 host=localhost, family=2 addr=127.0.0.1 Expected Result: Hints family=0 host=localhost, family=10 addr=::1 host=localhost, family=10 addr=::1 host=localhost, family=10 addr=::1 host=localhost, family=2 addr=127.0.0.1 host=localhost, family=2 addr=127.0.0.1 host=localhost, family=2 addr=127.0.0.1 This is because res+_hconf is not initialized in aicache.c. -- You are receiving this mail because: You are on the CC list for the bug.