CURLINFO_PRIMARY_IP(3)

🌸 NAME 🌸

hiii bestie πŸ’… welcome to the CURLINFO_PRIMARY_IP(3) page, straight out of the Library Functions Manual. Today’s vibe: CURLINFO_PRIMARY_IP β€” IP address of last connection ✨


πŸŽ€ SYNOPSIS πŸŽ€

#include <curl/curl.h>

CURLcode curl_easy_getinfo(CURL *handle, CURLINFO_PRIMARY_IP, char **ip);

πŸ’– DESCRIPTION πŸ’–

okay so picture this: you pass in a pointer to a char pointer, and it receives the pointer to a null-terminated string holding the IP address of the most recent connection done with this curl handle. iconic, right? πŸ¦‹

This string may be IPv6 when that is enabled β€” she’s flexible πŸ’β€β™€οΈ. But heads up: you get a pointer to a memory area that is reused at next request, so you need to copy the string if you want to keep the information. no cap, copy it if you’re attached 🫢

The ip pointer is NULL or points to private memory. You must not free it β€” do not do it, bestie, I’m serious 😭. The memory gets freed automatically when you call curl_easy_cleanup(3) on the corresponding curl handle. the cleanup handles it, periodt πŸ’…


🌈 PROTOCOLS 🌈

This functionality affects all supported protocols ⭐


✨ EXAMPLE ✨

int main(void)
{
  char *ip;
  CURLcode result;
  CURL *curl = curl_easy_init();

  curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");

  /* Perform the transfer */
  result = curl_easy_perform(curl);
  /* Check for errors */
  if((result == CURLE_OK) &&
     !curl_easy_getinfo(curl, CURLINFO_PRIMARY_IP, &ip) && ip) {
    printf("IP: %s\n", ip);
  }

  /* always cleanup */
  curl_easy_cleanup(curl);
}

🧚 AVAILABILITY 🧚

Added in curl 7.19.0 β€” vintage but still slaying πŸ’œ


πŸ‘‘ RETURN VALUE πŸ‘‘

curl_easy_getinfo(3) returns a CURLcode indicating success or error.

CURLE_OK (0) means everything was OK, non-zero means an error occurred β€” see libcurl-errors(3) for the full tea πŸ“


πŸ”₯ SEE ALSO πŸ”₯


mwah πŸ’‹ this page is brought to you by libcurl, dated 2026-10-12, and the footer energy is CURLINFO_PRIMARY_IP(3) 🌟

πŸ“¦ where this page comes from