CURLINFO_PRIMARY_IP.3 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. .\" generated by cd2nroff 0.1 from CURLINFO_PRIMARY_IP.md
  2. .TH CURLINFO_PRIMARY_IP 3 "2025-01-17" libcurl
  3. .SH NAME
  4. CURLINFO_PRIMARY_IP \- get IP address of last connection
  5. .SH SYNOPSIS
  6. .nf
  7. #include <curl/curl.h>
  8. CURLcode curl_easy_getinfo(CURL *handle, CURLINFO_PRIMARY_IP, char **ip);
  9. .fi
  10. .SH DESCRIPTION
  11. Pass a pointer to a char pointer to receive the pointer to a null\-terminated
  12. string holding the IP address of the most recent connection done with this
  13. \fBcurl\fP handle. This string may be IPv6 when that is enabled. Note that you
  14. get a pointer to a memory area that is reused at next request so you need to
  15. copy the string if you want to keep the information.
  16. The \fBip\fP pointer is NULL or points to private memory. You MUST NOT free \-
  17. it gets freed when you call \fIcurl_easy_cleanup(3)\fP on the corresponding
  18. CURL handle.
  19. .SH PROTOCOLS
  20. This functionality affects all supported protocols
  21. .SH EXAMPLE
  22. .nf
  23. int main(void)
  24. {
  25. char *ip;
  26. CURLcode res;
  27. CURL *curl = curl_easy_init();
  28. curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
  29. /* Perform the transfer */
  30. res = curl_easy_perform(curl);
  31. /* Check for errors */
  32. if((res == CURLE_OK) &&
  33. !curl_easy_getinfo(curl, CURLINFO_PRIMARY_IP, &ip) && ip) {
  34. printf("IP: %s\\n", ip);
  35. }
  36. /* always cleanup */
  37. curl_easy_cleanup(curl);
  38. }
  39. .fi
  40. .SH AVAILABILITY
  41. Added in curl 7.19.0
  42. .SH RETURN VALUE
  43. Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not.
  44. .SH SEE ALSO
  45. .BR CURLINFO_LOCAL_IP (3),
  46. .BR CURLINFO_LOCAL_PORT (3),
  47. .BR CURLINFO_PRIMARY_PORT (3),
  48. .BR curl_easy_getinfo (3),
  49. .BR curl_easy_setopt (3)