GNURLINFO_LOCAL_IP(3)
hey bestie π welcome to GNURLINFO_LOCAL_IP(3), straight out of the curl_easy_getinfo options manual β and no cap, this one is a little lookup queen for finding the local IP address of your last connection. Letβs get into it β¨
πΈ NAME πΈ
CURLINFO_LOCAL_IP β get the local IP address of the last connection. periodt π
β¨ SYNOPSIS β¨
okay so you include this header and call it like this, exactly:
#include <gnurl/curl.h>
CURLcode curl_easy_getinfo(CURL *handle, CURLINFO_LOCAL_IP, char **ip);
π¦ DESCRIPTION π¦
Pass a pointer to a char pointer so you can receive the pointer to a null-terminated string holding the IP address of the local end of the most recent connection done with this curl handle. This string may be IPv6 when that is enabled π
Important vibe check: you get a pointer to a memory area that will be re-used at the next request, so you need to copy the string if you want to keep the information. Like, if youβre obsessed with that IP and want it to stay yours, copy it π
The ip pointer will be NULL or pointing to private memory you MUST NOT free β it gets freed when you call curl_easy_cleanup(3) on the corresponding CURL handle. So do not touch the free button on that one, bestie, fr fr π
π PROTOCOLS π
All β¨
π EXAMPLE π
Hereβs the code vibe, with everything exactly where it belongs:
{
char *ip;
curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");
/* Perform the request, res will get the return code */
res = curl_easy_perform(curl);
/* Check for errors */
if((res == CURLE_OK) &&
!curl_easy_getinfo(curl, CURLINFO_LOCAL_IP, &ip) && ip) {
printf("Local IP: %s\n", ip);
}
/* always cleanup */
curl_easy_cleanup(curl);
}
β AVAILABILITY β
Added in 7.21.0 β yes, thatβs the exact version, iykyk π«Ά
π RETURN VALUE π
Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not. Simple as that, bestie π
π SEE ALSO π
go peek at these:
xoxo, your Unix bestie π this iconic page is brought to you by libcurl 7.44.0, dated 12 Sep 2015, and itβs literally GNURLINFO_LOCAL_IP(3) β slay β¨
π¦ where this page comes from
- nixos 26.05: libgnurl 7.72.0
- nixpkgs unstable: libgnurl 7.72.0
- Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms