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
- fedora 44: libcurl-devel 8.18.0-14.fc44 Β· curl
- fedora 44: libcurl-devel 8.18.0-14.fc44 Β· curl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms