curl / Mailing Lists / curl-library / 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.

Re: IP address of failed/tried connections?

From: Ray Satiro via curl-library <curl-library_at_cool.haxx.se>
Date: Thu, 2 Jan 2020 00:34:21 -0500

On 1/1/2020 10:48 PM, Arthur Murray via curl-library wrote:
> I would like to get the IP#(s) of both successful and failed
> connections after "curl_easy_perform". For example: If I try to:
>
> curl_easy_setopt(curl, CURLOPT_URL,"http://www.google.com:999");
> res = curl_easy_perform(curl);
>
> It will timeout for port 999 but both of these getinfo entries are empty:
>
> curl_easy_getinfo(curl, CURLINFO_PRIMARY_IP, &ip);
> curl_easy_getinfo(curl, CURLINFO_ACTIVESOCKET, &sockfd);
>
> How do I programmatically get the tried IPs? (curl -v shows "Trying
> [IP#]...", but I'm not looking for debug strings)
>
> Hostnames resolve to many IP #s, different ones at different times of
> day and from different geo locations. How can my software access and
> use them from libcurl?

libcurl saves that information only if a connection is made [1]. You may
not be looking for debug strings but CURLINFO_TEXT is the fastest way I
can think of to do what you're asking [2][3][4][5]. Either that or you
modify libcurl for your own purposes to do it. (I don't think there's
any interest to add such a feature upstream, but I'm sure I'll be
shortly corrected if there is).

Note libcurl may attempt two connections at once and then goes with the
fastest connection in what is known as "happy eyeballs". happy eyeballs
occurs if one ip address is ipv4 and the other is ipv6, however iirc due
to a bug old versions of libcurl allowed happy eyeballs of two ip
addresses of same family if only that family was present.

[1]: https://github.com/curl/curl/blob/curl-7_67_0/lib/connect.c#L913
[2]: https://curl.haxx.se/libcurl/c/CURLOPT_DEBUGFUNCTION.html
[3]: https://github.com/curl/curl/blob/curl-7_67_0/lib/connect.c#L1129
[4]: https://github.com/curl/curl/blob/curl-7_67_0/lib/connect.c#L938-L940
[5]: https://github.com/curl/curl/blob/curl-7_67_0/lib/url.c#L1393-L1399

-------------------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2020-01-02