Subject: Re: [Patch] localhost (feedback)

Re: [Patch] localhost (feedback)

From: Greg Christopher <>
Date: Tue, 26 Apr 2011 22:36:43 -0700 (PDT)

From: Kenny To
Sent: Friday, March 25, 2011 5:48 PM
To: 'Greg Christopher'
Subject: RE: [Patch] localhost


Feel free to forward this to the c-ares developers.

I compiled the latest curl and c-ares on Visual Studio 2008 with the 2 patches
and fixes applied. First I tested with the mock GetUnicastIpAddressTable by
making a few changes:
2) Remove the SOCKADDR_INET union definition which was already present in
3) Use ares_inet_pton instead of inet_pton in GetUnicastIpAddressTable because
ws2tcpip.h wasn't included.
4) Replace placeholder addresses in GetUnicastIpAddressTable...namely change the
first IPv4 address from "" to "".

This worked, and curl connected to without querying DNS.

I also recompiled curl with -DENABLE_IPV6 and confirmed that we end up getting
the first IPv6 address back, "::1:2:3:4". I didn't get to exercise the logic of
preferring AF_INET6 to AF_INET because it seems that instead of passing
AF_UNSPEC, curl makes two calls with AF_INET and then AF_INET6 and decides for
itself which to choose.

Finally, I tested with the real GetUnicastIpAddressTable by compiling with
-DNTDDI_VERSION=0x06000000 -D_WIN32_WINNT=0x0600, including iphlpapi.h, linking
iphlpapi.lib, and removing -DARES_WIN32_LOCALHOST_TESTING. This worked as well,
and again curl connected to

My one concern is that GetUnicastIpAddressTable is only available on Windows
Vista and later. The main issue is this could make cares.dll fail to load on
Windows XP systems. A minor issue is that in the rare case where someone on
Windows XP removes the localhost entry from the hosts file, they wouldn't
benefit from this change even if cares.dll was made safe to load by
delay-loading GetUnicastIpAddressTable and FreeMibTable. Could there be another
way to do this which doesn't require Windows Vista?

Received on 2011-04-27