E47D CURLINFO_PRIMARY_IP empty if connection fails · Issue #2126 · curl/curl · GitHub
[go: up one dir, main page]

Skip to content

CURLINFO_PRIMARY_IP empty if connection fails #2126

@rcanavan

Description

@rcanavan

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;
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0