1CURLINFO_PRIMARY_IP(3)     curl_easy_getinfo options    CURLINFO_PRIMARY_IP(3)
2
3
4

NAME

6       CURLINFO_PRIMARY_IP - get IP address of last connection
7

SYNOPSIS

9       #include <curl/curl.h>
10
11       CURLcode curl_easy_getinfo(CURL *handle, CURLINFO_PRIMARY_IP, char **ip);
12

DESCRIPTION

14       Pass  a pointer to a char pointer to receive the pointer to a null-ter‐
15       minated string holding the IP address of  the  most  recent  connection
16       done  with  this  curl handle. This string may be IPv6 when that is en‐
17       abled. Note that you get a pointer to a memory area that  will  be  re-
18       used at next request so you need to copy the string if you want to keep
19       the information.
20
21       The ip pointer will be NULL or pointing to private memory you MUST  NOT
22       free  -  it gets freed when you call curl_easy_cleanup(3) on the corre‐
23       sponding CURL handle.
24

PROTOCOLS

26       All network based ones
27

EXAMPLE

29       {
30         char *ip;
31
32         curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
33
34         /* Perform the request, res will get the return code */
35         res = curl_easy_perform(curl);
36         /* Check for errors */
37         if((res == CURLE_OK) &&
38            !curl_easy_getinfo(curl, CURLINFO_PRIMARY_IP, &ip) && ip) {
39           printf("IP: %s\n", ip);
40         }
41
42         /* always cleanup */
43         curl_easy_cleanup(curl);
44       }
45

AVAILABILITY

47       Added in 7.19.0
48

RETURN VALUE

50       Returns CURLE_OK if the option is supported,  and  CURLE_UNKNOWN_OPTION
51       if not.
52

SEE ALSO

54       curl_easy_getinfo(3),   curl_easy_setopt(3),  CURLINFO_PRIMARY_PORT(3),
55       CURLINFO_LOCAL_IP(3),
56
57
58
59libcurl 7.85.0                   May 17, 2022           CURLINFO_PRIMARY_IP(3)
Impressum