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 π₯
CURLINFO_LOCAL_IP(3)CURLINFO_LOCAL_PORT(3)CURLINFO_PRIMARY_PORT(3)curl_easy_getinfo(3)curl_easy_setopt(3)
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
- 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