CURLINFO_LOCAL_IP.3 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. .\" generated by cd2nroff 0.1 from CURLINFO_LOCAL_IP.md
  2. .TH CURLINFO_LOCAL_IP 3 "2025-01-17" libcurl
  3. .SH NAME
  4. CURLINFO_LOCAL_IP \- get local IP address of last connection
  5. .SH SYNOPSIS
  6. .nf
  7. #include <curl/curl.h>
  8. CURLcode curl_easy_getinfo(CURL *handle, CURLINFO_LOCAL_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 local end of most recent connection done
  13. with this \fBcurl\fP handle. This string may be IPv6 when that is
  14. enabled. Note that you get a pointer to a memory area that is reused at next
  15. request so you need to 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_LOCAL_IP, &ip) && ip) {
  34. printf("Local IP: %s\\n", ip);
  35. }
  36. /* always cleanup */
  37. curl_easy_cleanup(curl);
  38. }
  39. .fi
  40. .SH AVAILABILITY
  41. Added in curl 7.21.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_PORT (3),
  46. .BR CURLINFO_PRIMARY_IP (3),
  47. .BR curl_easy_getinfo (3),
  48. .BR curl_easy_setopt (3)