This is the mail archive of the libc-help@sourceware.org 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


Hi Siddhesh,

Thanks for following up. So this is where it gets interesting:

- I changed your program to look for "www.gmail.com" and compile with gcc -O2
- then, when I execute it, I get queries for both A and AAAA records, even though hints.ai_family = AF_INET

- I then set the port to NULL and removed the AI_CANONNAME flag, to replicate the call that wget makes
- then I get the same result as I reported below, i.e. a duplicate A query

It seems there are two issues:
1. getaddrinfo() triggers duplicate A queries when hints.ai_flags == 0
2. getaddrinfo() triggers both an A and an AAAA query when hints.ai_flags == AI_CANONNAME (even though hints.ai_family == AF_INET)

Could it be that the structure / alignment of fields in addrinfo differs between the caller and callee (libc) ? I should note that I am using an x86_64 platform...Hmmm

I then compiled your modified program using "-m32" to generate a 32-bit program, and... voila, issue solved!

So, there is an issue with getaddrinfo() when used in x86_64 programs -> with the 64-bit library versions of glibc

On my Fedora 16 machine:
32-bit: /lib/libresolv.so.2
64-bit: /lib64/libresolv.so.2

I tried debug tracing into glibc, and ended up in gaih_inet() - but it seemed like the debuginfo installed via yum did not match the code being executed (?)

Regards,
Jeroen

On Fri, 29 Jun 2012 08:38:36 +0530
Siddhesh Poyarekar <siddhesh.poyarekar@gmail.com> wrote:

> On 29 June 2012 04:41, Jeroen van Bemmel <jvb127@gmail.com> 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 http://www.gmail.com/
> >
> 
> 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
> libc:
> 
> #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 = "google.co.in";
>         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;
>         }
> }
> 
> 
> --
> Siddhesh
> http://siddhesh.in


-- 
Jeroen van Bemmel <jvb127@gmail.com>


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