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