This is the mail archive of the mailing list for the glibc project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: gethostbyname() triggering duplicate DNS A queries when CNAMEresponse is received

On 29 June 2012 04:41, Jeroen van Bemmel <> wrote:
> After further investigation, it turns out it is not gethostbyname() which is showing this behavior, but rather getaddrinfo()
> Using wget ( wget-1.12-4.fc16.x86_64 ) on a Fedora 16 machine ( Linux TouchPC.bemnet 3.4.2-1.fc16.x86_64 #1 SMP Thu Jun 14 20:17:26 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux ) with latest glibc glibc-2.14.90-24.fc16.7.x86_64 I can easily reproduce this:
> in console 1: tcpdump -vvv -n -i eth0 udp port 53
> in console 2: wget -4

With AF_UNSPEC, you would see 2 queries with getaddrinfo, one IPv6 and
one IPv4. With AF_INET, you should see two queries, one lookup and one
reverse lookup, so in neither of the cases should you see two IPv4
requests for the same domain name unless the first server was
unreachable -- that doesn't seem to be your problem though. If you
cannot see this with a self-contained program like the following, then
you're likely seeing the behaviour of the program in the tcpdump, not

#include <sys/socket.h>
#include <netdb.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <string.h>

int main()
        const char *host = "";
        struct addrinfo hints;
        struct addrinfo *result = NULL, *rp;
        const char *port = "80";
        int err = 0;

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

        hints.ai_family = AF_INET;
        hints.ai_socktype = SOCK_STREAM;
        hints.ai_flags = AI_CANONNAME;

        if ((err = getaddrinfo(host, port, &hints, &result)) < 0) {
                fprintf(stderr, "Lookup: unable to create socket for
%s:%s:: \n",
                        host, port, gai_strerror(err));
                return 1;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]