-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
Closed
Labels
Description
CURLINFO_PRIMARY_IP is empty if a connection attempt fails, e.g. due to a timeout. However, the IP would be useful to diagnose connection problems, especially in case a server name resolves to multiple IPs. As a workaround, one can search for "Trying ..." in the debug output, which should always be present if connection problems arise.
If this is the intended behavior, please clarify the documentation at https://curl.haxx.se/libcurl/c/CURLINFO_PRIMARY_IP.html to read "get IP address of the last successful connection"
reproduce with following trivial hack of examples/getinfo.c
#include <stdio.h>
#include <curl/curl.h>
int main(void)
{
CURL *curl;
CURLcode res;
char *ct;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "http://blackhole.webpagetest.org/");
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 3);
res = curl_easy_perform(curl);
if(CURLE_OK == res) {
/* ask for the content-type */
res = curl_easy_getinfo(curl, CURLINFO_CONTENT_TYPE, &ct);
if((CURLE_OK == res) && ct)
printf("We received Content-Type: %s\n", ct);
}
res = curl_easy_getinfo(curl, CURLINFO_PRIMARY_IP, &ct);
if((CURLE_OK == res) && ct)
printf("IP: %s\n", ct);
/* always cleanup */
curl_easy_cleanup(curl);
}
return 0;
}