How to Curl Using Ipv6 Address

Using CURLOPT_CONNECT_TO with an IPv6 address

There was a bug in libcurl (before 7.58.0) which made it take IPv6 addresses and attempt to use them for CURLOPT_CONNECT_TO, even if it was built without support for IPv6!

This was addressed in curl 7.58.0 and from then on it makes libcurl return an error if this is attempted!

Assign specific IPv6 address of subnet to cURL

cURL cannot bind to 2a01:4f8:XXXX:YYYY::3 because 2a01:4f8:XXXX:YYYY::3 is not an IP local address assigned to any interface. Hosts can only receive packets on addresses that are assigned to them, and, accordingly, you can only bind to those addresses.

As you described, if you do add 2a01:4f8:XXXX:YYYY::3 as an address on the interface using ip addr add, it works. That is to be expected.

I don't know of a way to assign a large group of addresses to the local system without having to add them one by one. There is a trick but it only works for some operating systems (perhaps only Linux) and only for IPv4 and only for the loopback interface.

PHP curl failing to resolve IPv6-only URL

Your expectations of CURLOPT_IPRESOLVE are correct, that is indeed what it is supposed to do. However you seem to have used a wrong constant for the value. From the manual:

CURLOPT_IPRESOLVE: Allows an application to select what kind of IP
addresses to use when resolving host names. This is only interesting
when using host names that resolve addresses using more than one
version of IP, possible values are CURL_IPRESOLVE_WHATEVER,
CURL_IPRESOLVE_V4, CURL_IPRESOLVE_V6, by default
CURL_IPRESOLVE_WHATEVER.

I can't find the constant you use (CURL_VERSION_IPV6) in the manual, so IIRC then PHP will interpret it as the string "CURL_VERSION_IPV6" which won't work.



Related Topics



Leave a reply



Submit