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: Loopback ip

From: Ray Satiro via curl-library <curl-library_at_lists.haxx.se>
Date: Sun, 29 May 2022 02:14:06 -0400

On 5/26/2022 10:37 AM, Александр Карелин via curl-library wrote:
> I have one issue when use curl. After performing a http request I call
> method curl_easy_get info with second parameter CURLINFI_LOCAL_IP. And
> every time I get 127.0.0.1 as a result, but my server is on another
> machine with n network. How can it be possible?
>
> And another related question:
> What is the main difference between CURLINFI_LOCAL_IP
> and CURLINFI_PRIMARY_IP parameter?


Try the latest libcurl if you haven't already. Internally
Curl_conninfo_local [1] calls your socket library's getsockname to
retrieve the local ip. CURLINFO_LOCAL_IP [2] is used to retrieve the
local address and CURLINFO_PRIMARY_IP [3] is used to retrieve the remote
address. I don't know why you are seeing 127.0.0.1 as a local address if
the remote address is another machine. The only way I can think of it
happening is if the remote machine redirected back to your machine. I
doubt it's a bug in curl.


[1]: https://github.com/curl/curl/blob/curl-7_83_1/lib/connect.c#L718-L747
[2]: https://curl.se/libcurl/c/CURLINFO_LOCAL_IP.html
[3]: https://curl.se/libcurl/c/CURLINFO_PRIMARY_IP.html


-- 
Unsubscribe: https://lists.haxx.se/listinfo/curl-library
Etiquette:   https://curl.haxx.se/mail/etiquette.html
Received on 2022-05-29