curl / Mailing Lists / curl-users / Single Mail
Buy commercial curl support from WolfSSL. We help you work out your issues, debug your libcurl applications, use the API, port to new platforms, add new features and more. With a team lead by the curl founder himself.

curl: (45) bind failed with errno 22: Invalid argument

From: Alex <alexey_at_nsk21.ru>
Date: Fri, 07 Jun 2019 11:32:02 +0000

Hello,

Error
An error curl: (45) bind failed with errno 22: Invalid argument occurs
whenever we specify IPv4 from local interface as a source address trying
to connect to a site which have both IPv4 and IPv6.

Steps to reproduce
Pick up a domain which resolves both to IPv4 and IPv6:

# host canhazip.com
canhazip.com has address 104.16.222.38
canhazip.com has address 104.16.223.38
canhazip.com has IPv6 address 2606:4700::6810:de26
canhazip.com has IPv6 address 2606:4700::6810:df26

The request:

# curl --interface 1.2.3.4 https://canhazip.com/
curl: (45) bind failed with errno 22: Invalid argument

can be fixed with -4 flag:

# curl --interface 1.2.3.4 -4 https://canhazip.com/
1.2.3.4

OS
Tested with CentOS 7:

default version cURL: curl-7.29.0-51.el7.x86_64and from a git
repository: curl 7.65.1-DEV (x86_64-unknown-linux-gnu)
libcurl/7.65.1-DEV OpenSSL/1.0.2k-fips zlib/1.2.7
Results are the same.

Expected behavior:
Whenever a source IPv4 is specified cURL should auto add -4 flag, i.e.:

curl_easy_setopt(easyhandle, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);

The same with IPv6, whenever a source IPv6 is specified cURL should auto
add -6 flag, i.e.

curl_easy_setopt(easyhandle, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V6);

Regards,
Alex.

-----------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-users
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2019-06-07