cURL / Mailing Lists / curl-library / Single Mail

curl-library

[PATCH] libcurl binding to IPv6 address

From: Robert Iakobashvili <coroberti_at_gmail.com>
Date: Tue, 6 Mar 2007 11:29:58 +0200

CURL VERSION:
7.16.1

HOST MACHINE and OPERATING SYSTEM:
 linux, debian with debian kernel 2.6.18

COMPILER:
gcc version 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)

CURL CONFIGURATION:
configure --prefix $(CURL_BUILD) \
        --disable-thread \ # the same problem is for --enable-thread
        --enable-ipv6 \
        --with-random=/dev/urandom \
        --with-ssl=/usr/include/openssl \
        --enable-shared=no \
        CFLAGS="-g"

AREA/CLASS/EXAMPLE AFFECTED:
Binding to IPv6 address of CURL-handle

DOES THE PROBLEM AFFECT:
        COMPILATION? No
        LINKING? No
        EXECUTION? Yes
        OTHER (please specify)?

    SYNOPSIS:
When IPv6 address used in
curl_easy_setopt (handle, CURLOPT_INTERFACE, addr)
is an IPv6 address added to interface as the secondary IP,
libcurl fails with a message "couldn't find my own IP address".

    DESCRIPTION:
The curl_easy_setopt used are:

CURLOPT_IPRESOLVE with CURL_IPRESOLVE_V6
CURLOPT_INTERFACE with "2001:db8:fff5:6::101"
CURLOPT_NOSIGNAL
CURLOPT_URL with urls
http://[::1]/apache2-default/index.html or
http://ip6-localhost/apache2-default/index.html

CURLOPT_DNS_CACHE_TIMEOUT with -1
CURLOPT_VERBOSE with 1
CURLOPT_DEBUGFUNCTION with client_tracing_function
CURLOPT_DEBUGDATA, cctx;

REPRODUCE:
Option1:
Add on linux to an interface secondary IPv6 address by, e.g.
#ip addr 2001:db8:fff5:6::101/64 dev eth0
Bind CURL handle to the address using CURLOPT_INTERFACE option
Use the handle to fetch a url

Option2:
Fetch the latest curl-loader version from its svn.
Comment out patch curl-ipv6-bind.patch in Makefile
Correct the url in conf-examples/ipv6.conf to be the url
you wish to use and,
run:
# ./curl-loader -f ./conf-examples/ipv6.conf -v
Look at lubcurl errors in ipv6.log file

RESOLUTION/WORKAROUND:
Apply the patch against curl-7.16.1, which fixes the problem.
-------------------------------------------------
diff -Naru curl-7.16.1/lib/connect.c curl-7.16.1-mod/lib/connect.c
--- curl-7.16.1/lib/connect.c 2006-12-22 15:30:54.000000000 +0200
+++ curl-7.16.1-mod/lib/connect.c 2007-03-06 13:58:34.000000000 +0200
@@ -261,7 +261,9 @@
     char myhost[256] = "";
     in_addr_t in;
     int rc;
- bool was_iface = FALSE;
+ char ipv6_addr[16];
+ bool was_iface = FALSE;
+ int in6 = -1;

     /* First check if the given name is an IP address */
     in=inet_addr(data->set.device);
@@ -342,7 +344,11 @@
 #endif

     in=inet_addr(myhost);
- if (CURL_INADDR_NONE == in) {
+
+#ifdef ENABLE_IPV6
+ in6 = inet_pton (AF_INET6, myhost, (void *)&ipv6_addr);
+#endif
+ if (CURL_INADDR_NONE == in && -1 == in6) {
       failf(data,"couldn't find my own IP address (%s)", myhost);
       return CURLE_HTTP_PORT_FAILED;
     } /* end of inet_addr */
----------------------------------------------------------------------------

Thank you for attention.

-- 
Sincerely,
Robert Iakobashvili,
coroberti %x40 gmail %x2e com
...................................................................
Navigare necesse est, vivere non est necesse
...................................................................
http://sourceforge.net/projects/curl-loader
A powerful open-source HTTP/S, FTP/S traffic
generating, loading and testing tool.
Received on 2007-03-06