This is the mail archive of the
libc-help@sourceware.org
mailing list for the glibc project.
gethostbyname() triggering duplicate DNS A queries when CNAMEresponse is received
- From: Jeroen van Bemmel <jvb127 at gmail dot com>
- To: libc-help at sourceware dot org
- Date: Thu, 28 Jun 2012 14:42:08 -0600
- Subject: gethostbyname() triggering duplicate DNS A queries when CNAMEresponse is received
Hi,
When creating a network visualization tool I noticed that multiple
identical DNS queries were being generated on a CentOS machine
( Linux version 2.6.18-274.3.1.el5 (mockbuild@builder10.centos.org)
(gcc version 4.1.2 20080704) with glibc-2.5-81.el5_8.2 )
Specifically, this happens when I ping a hostname for which a CNAME
record is available in DNS. The sequence I get is the following:
1. DNS Query A hostname
2. DNS response with 2 replies: CNAME someotherhost, someotherhost A
<ipv4 address of someotherhost>
3. DNS Query A hostname (different transaction id)
4. DNS response with 2 replies: CNAME someotherhost, someotherhost A
<ipv4 address of someotherhost>
Query #3 happens about 1ms after having received the response #2
I wrote a small wrapper library to catch calls to "gethostbyname",
returning a fixed response for "hostname". I then verified that
LD_PRELOAD <mywrapperlibrary> ping hostname calls gethostbyname() once
and no longer generates any DNS traffic on the network.
Based on the above, it looks like a single call to gethostbyname() can
trigger 2 identical DNS requests, which is undesired behaviour.
Has anyone else observed this before, any ideas on what might be going on here?
Thanks,
Jeroen