Libcurl: force ipv4 or ipv6

McEnroe picture McEnroe · Jul 17, 2012 · Viewed 8.8k times · Source

How do I force libcurl to access a server running in dual stack mode over either ipv4 or ipv6? It shouldn't be hard to do using IPs addresses, but I'm looking for something that works with DNS ...

Answer

Sam picture Sam · Jul 17, 2012

You bet. The config CURLOPT_IPRESOLVE which can be set to CURL_IPRESOLVE_V4 or CURL_IPRESOLVE_V6.

A more robust solution, if you can control DNS in anyway, is to make an A record for the v4 address and a separate AAAA record for the v6 address. This would let you pick the network you want to poll this system by, regardless of DNS resolution. But CURL can do what you want, just fine.