GNURLINFO_PRIMARY_IP(3)
π GNURLINFO_PRIMARY_IP(3) π
okay so welcome to the curl_easy_getinfo options corner of the manual, bestie β this page is all about GNURLINFO_PRIMARY_IP(3) and it's lowkey iconic. vibe check: passed.
πΈ NAME πΈ
CURLINFO_PRIMARY_IP β get IP address of last connection. that's the name section, short and slay.
β¨ SYNOPSIS β¨
include the header, call the function, and the vibes are literally:
#include <gnurl/curl.h>
CURLcode curl_easy_getinfo(CURL *handle, CURLINFO_PRIMARY_IP, char **ip);
π¦ DESCRIPTION π¦
okay bestie, here's the tea: you pass a pointer to a char pointer to receive the pointer to a null-terminated string holding the IP address of the most recent connection done with this curl handle. this string may be IPv6 when that is enabled.
note that you get a pointer to a memory area that will be re-used at next request so you need to copy the string if you want to keep the information. highkey important, fr fr.
β οΈ important, bestie: theippointer will beNULLor pointing to private memory you MUST NOT free β it gets freed when you callcurl_easy_cleanup(3)on the correspondingCURLhandle. do not do it.
π PROTOCOLS π
All network based ones β every network-based protocol, periodt.
π EXAMPLE π
here's the example, and yes, copy it exactly β no creative rewrites, bestie:
{
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_PRIMARY_IP, &ip) && ip) {
printf("IP: %s\n", ip);
}
/* always cleanup */
curl_easy_cleanup(curl);
}
β AVAILABILITY β
Added in 7.19.0 β vintage but still iconic.
π RETURN VALUE π
Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not. that's it, no cap.
π₯ SEE ALSO π₯
go check out these besties: curl_easy_getinfo(3), curl_easy_setopt(3), CURLINFO_PRIMARY_PORT(3), CURLINFO_LOCAL_IP(3), <-- yes, the original list had a lil trailing comma, so iconic.
xoxo, your Unix bestie π this is GNURLINFO_PRIMARY_IP(3) from libcurl 7.44.0, dated 12 Sep 2015 β mwah π
π¦ where this page comes from
- nixos 26.05: libgnurl 7.72.0
- nixpkgs unstable: libgnurl 7.72.0
- Copyright (C) 1998 - 2015, 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