cURL / Mailing Lists / curl-library / Single Mail

curl-library

libcurl with IPv6 support enabled on Windows

From: Kai Sommerfeld <Kai.Sommerfeld_at_sun.com>
Date: Tue, 04 Jan 2005 14:00:15 +0100

Hi,

  I'm trying build libcurl with IPv6 support enabled on Windows

For this, I added "#define ENABLE_IPV6 1" to config-win32.h

I'm doing a "nmake -f Makefile.vc6 cfg=release-dll" to build
libcurl.dll... and getting unresolved externals:

    Creating library libcurl.lib and object libcurl.exp
ftp.obj : error LNK2019: unresolved external symbol
__imp__freeaddrinfo_at_4 referenced in function _ftp_use_port
hostip6.obj : error LNK2001: unresolved external symbol
__imp__freeaddrinfo_at_4
ftp.obj : error LNK2019: unresolved external symbol
__imp__getaddrinfo_at_16 referenced in function _ftp_use_port
hostthre.obj : error LNK2001: unresolved external symbol
__imp__getaddrinfo_at_16
ftp.obj : error LNK2019: unresolved external symbol
__imp__getnameinfo_at_28 referenced in function _ftp_use_port
libcurl.dll : fatal error LNK1120: 3 unresolved externals
NMAKE : fatal error U1077: 'link.exe' : return code '0x460'
Stop.

The missing functions are available in ws2_32.lib. This lib is missing
in the respective sections of Makefile.vc6. Adding ws2_32.lib fixes the
unresolved externals.

BUT... after having done this I noticed that the produced libcurl.dll
will work fine on Windows XP but can't even be loaded on Windows 2000.
getaddrinfo and other functions cannot be found in ws2_32.dll. The
reason for this issue can be found in lib/setup.h

--- lib/setup.h ------- snipp ---------
#ifdef WIN32

...

#if (defined(ENABLE_IPV6) || defined(CURLDEBUG)) && defined(_MSC_VER) && \
     (!defined(_WIN32_WINNT) || _WIN32_WINNT < 0x0500)
/*
  * Needed to pull in the real getaddrinfo() and not the inline version
  * in <wspiAPI.H> which doesn't support IPv6 (IPv4 only). <wspiAPI.H> is
  * included from <ws2tcpip.h> for <= 0x0500 SDKs.
  */
#undef _WIN32_WINNT
#define _WIN32_WINNT 0x0501
#endif

...
--- lib/setup.h ------- snipp ---------

Looking at the comment in the code above I was wondering whether the
statement that the inline versions do not support IPv6 is true. From
what I see in my copy of wspiAPI.h (oldest is from msvc 6.03) is that
the inline functions are implemented the way that the default behavior
is indeed IPv4 only. But at the first call of a function in question
(like getaddrinfo) the inline implementation looks for some dlls (for
example ws2_32.dll), loads them if found and looks for the exported
function in question. If found, inline implementation will always
forward to that function. If not found, the IPv4-only fallback
implementation will be used. Thus, on systems where IPv6 is present
(like XP), getaddrinfo and friends will automatically be really IPv6
enabled, on systems without IPv6 support they will just be IPv4
versions. AND ... and IMO this is what those inline wrappers have been
invented for, one library can be used on both old and new systems.

Giving this, I'm wondering what the code in setup.h is actually good
for. Shouldn't it just be removed? I'd see no problems with this.

- Kai.
Received on 2005-01-04