1--- 2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 3SPDX-License-Identifier: curl 4Title: CURLINFO_LOCAL_IP 5Section: 3 6Source: libcurl 7See-also: 8 - CURLINFO_LOCAL_PORT (3) 9 - CURLINFO_PRIMARY_IP (3) 10 - curl_easy_getinfo (3) 11 - curl_easy_setopt (3) 12Protocol: 13 - All 14--- 15 16# NAME 17 18CURLINFO_LOCAL_IP - get local IP address of last connection 19 20# SYNOPSIS 21 22~~~c 23#include <curl/curl.h> 24 25CURLcode curl_easy_getinfo(CURL *handle, CURLINFO_LOCAL_IP, char **ip); 26~~~ 27 28# DESCRIPTION 29 30Pass a pointer to a char pointer to receive the pointer to a null-terminated 31string holding the IP address of the local end of most recent connection done 32with this **curl** handle. This string may be IPv6 when that is 33enabled. Note that you get a pointer to a memory area that is reused at next 34request so you need to copy the string if you want to keep the information. 35 36The **ip** pointer is NULL or points to private memory. You MUST NOT free - 37it gets freed when you call curl_easy_cleanup(3) on the corresponding 38CURL handle. 39 40# EXAMPLE 41 42~~~c 43int main(void) 44{ 45 char *ip; 46 CURLcode res; 47 CURL *curl = curl_easy_init(); 48 49 curl_easy_setopt(curl, CURLOPT_URL, "https://example.com"); 50 51 /* Perform the transfer */ 52 res = curl_easy_perform(curl); 53 /* Check for errors */ 54 if((res == CURLE_OK) && 55 !curl_easy_getinfo(curl, CURLINFO_LOCAL_IP, &ip) && ip) { 56 printf("Local IP: %s\n", ip); 57 } 58 59 /* always cleanup */ 60 curl_easy_cleanup(curl); 61} 62~~~ 63 64# AVAILABILITY 65 66Added in 7.21.0 67 68# RETURN VALUE 69 70Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not. 71