CURLINFO_LOCAL_IP(3)

πŸ’… CURLINFO_LOCAL_IP(3) β€” like, the libcurl manual, but make it make sense

okay so bestie, welcome to the CURLINFO_LOCAL_IP page of the libcurl gang πŸ¦‹ this is a Library Functions Manual entry and honestly? it's lowkey one of the cutest little info-getters out there. let's get into it ✨


✨ NAME ✨

CURLINFO_LOCAL_IP β€” the local IP address of your last connection, periodt πŸŽ€


✨ SYNOPSIS ✨

#include <curl/curl.h>

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

✨ DESCRIPTION ✨

so here's the vibe πŸ’œ you pass in a pointer to a char pointer, and it gets filled with a pointer to a null-terminated string holding the IP address of the local end of the most recent connection done with this curl handle. that's your side of the conversation, the you-address, the main character address πŸ‘‘

this string may be IPv6 when that's enabled β€” so don't be shocked when it's giving ::1 energy instead of the classic quad-dot look 🌈

⚠️ okay this part is important, listen up: you get a pointer to a memory area that gets reused at the next request. so if you actually want to keep that string, you gotta copy it yourself fr fr 😭 don't just stash the pointer and wander off.

and ngl, the ip pointer is either NULL or it points at private memory. you must not free it πŸ™ˆ it gets freed automatically when you call curl_easy_cleanup(3) on the corresponding curl handle. so like, hands off, the library's got it 🫢


✨ PROTOCOLS ✨

this functionality affects quic and tcp 🧚 so if you're on some other transport, don't come for her, she's not doing that πŸ’€


✨ EXAMPLE ✨

here's the whole thing, bestie, copy-paste ready ⭐

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_LOCAL_IP, &ip) && ip) {
    printf("Local IP: %s\n", ip);
  }

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

look at that check β€” result == CURLE_OK, then the !curl_easy_getinfo(...), then && ip to make sure it's actually not NULL. that's the iconic trifecta πŸ’… and yes, curl_easy_cleanup(curl); at the end, always cleanup, no skipping πŸ”₯


✨ AVAILABILITY ✨

added in curl 7.21.0 🌸 so she's been around a minute, she's a legend at this point πŸ‘‘


✨ 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 whole saga 😭

✨ SEE ALSO ✨


and that's the whole page, bestie!! now go get that local IP and slay πŸ¦‹πŸ’–

this libcurl page was brought to you by libcurl, dated 2026-10-12 β€” mwah, catch you in the next manpage βœ¨πŸŽ€πŸ’œ

πŸ“¦ where this page comes from