1---
2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
3SPDX-License-Identifier: curl
4Title: CURLINFO_LOCAL_PORT
5Section: 3
6Source: libcurl
7Protocol:
8  - TCP
9See-also:
10  - CURLINFO_LOCAL_IP (3)
11  - CURLINFO_PRIMARY_PORT (3)
12  - curl_easy_getinfo (3)
13  - curl_easy_setopt (3)
14---
15
16# NAME
17
18CURLINFO_LOCAL_PORT - get the latest local port number
19
20# SYNOPSIS
21
22~~~c
23#include <curl/curl.h>
24
25CURLcode curl_easy_getinfo(CURL *handle, CURLINFO_LOCAL_PORT, long *portp);
26~~~
27
28# DESCRIPTION
29
30Pass a pointer to a long to receive the local port number of the most recent
31connection done with this **curl** handle.
32
33# EXAMPLE
34
35~~~c
36int main(void)
37{
38  CURL *curl;
39  CURLcode res;
40
41  curl = curl_easy_init();
42  if(curl) {
43    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
44    res = curl_easy_perform(curl);
45
46    if(CURLE_OK == res) {
47      long port;
48      res = curl_easy_getinfo(curl, CURLINFO_LOCAL_PORT, &port);
49
50      if(CURLE_OK == res) {
51        printf("We used local port: %ld\n", port);
52      }
53    }
54    curl_easy_cleanup(curl);
55  }
56  return 0;
57}
58~~~
59
60# AVAILABILITY
61
62Added in 7.21.0
63
64# RETURN VALUE
65
66Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not.
67