curl / Mailing Lists / curl-library / Single Mail


Re: Retrieve all addresses mapped to specific host, not just one IP

From: Daniel Stenberg via curl-library <>
Date: Sat, 11 Aug 2018 13:47:55 +0200 (CEST)

On Sat, 11 Aug 2018, myLC--- via curl-library wrote:

> I would like to know how we can retrieve all the IP addresses which are
> mapped to a host.

That list is not provided by libcurl. It will get that list internally and use
that to connect to the host but the only address it offers through the API is
the single IP it ended up using.

However, I wouldn't be opposed somehow exposing the whole list if someone
would like to work on it.

> The "inbound" network implementation (TR) of C++ (Boost ASIO) returns an
> iterator upon having resolved a hostname. If I'm correct, the implementation
> chooses the IP randomly when connecting.

A "correct" client would use getaddrinfo() to get the list and that function
is supposed to return the addresses in the "preferred" order so its not
exactly even if it may appear so.

> Likewise, it tries the entire list of IPs before giving up. I haven't
> checked out libcurl's source- code, but I'm guessing that you will do
> something similar.

libcurl goes through the list one by one until one works, yes. But it also
does both IPv4 and IPv6 in parallel (so called happy eyeballs) and picks the
one that connects first.

Received on 2018-08-11