What IP version libcurl is prioritizing by default

Viewed 109

I am using the default resolve option of libcurl

curl_easy_setopt(curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_WHATEVER);

When the libcurl resolve the host addresses and get both IPv4 addresses and IPv6 addresses, what address will be use libcurl first IPv4 or IPv6? what is the algorithm used by libcurl to choose what ip address to use first?

is there a way to force libcurl to use first all ipv6 addresses, and if they fails then go to the ipv4 address?

1 Answers

No order is specified. I suppose, the order of DNS response is used.

This goes a bit more smart. Connection to a host with several IP resolved is not performed if an alive connection to that host can be reused.

is there a way to force libcurl to use first all ipv6 addresses, and if they fails then go to the ipv4 address?

Use corresponding options for CURLOPT_IPRESOLVE. Use next after first failed. The specific option tries all available IP addresses of the same family.

Related