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
9  - QUIC
10See-also:
11  - CURLINFO_LOCAL_IP (3)
12  - CURLINFO_PRIMARY_PORT (3)
13  - curl_easy_getinfo (3)
14  - curl_easy_setopt (3)
15Added-in: 7.21.0
16---
17
18# NAME
19
20CURLINFO_LOCAL_PORT - get the latest local port number
21
22# SYNOPSIS
23
24~~~c
25#include <curl/curl.h>
26
27CURLcode curl_easy_getinfo(CURL *handle, CURLINFO_LOCAL_PORT, long *portp);
28~~~
29
30# DESCRIPTION
31
32Pass a pointer to a long to receive the local port number of the most recent
33connection done with this **curl** handle.
34
35If the connection was done using QUIC, the port number is a UDP port number,
36otherwise it is a TCP port number.
37
38# %PROTOCOLS%
39
40# EXAMPLE
41
42~~~c
43int main(void)
44{
45  CURL *curl;
46  CURLcode res;
47
48  curl = curl_easy_init();
49  if(curl) {
50    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
51    res = curl_easy_perform(curl);
52
53    if(CURLE_OK == res) {
54      long port;
55      res = curl_easy_getinfo(curl, CURLINFO_LOCAL_PORT, &port);
56
57      if(CURLE_OK == res) {
58        printf("We used local port: %ld\n", port);
59      }
60    }
61    curl_easy_cleanup(curl);
62  }
63  return 0;
64}
65~~~
66
67# %AVAILABILITY%
68
69# RETURN VALUE
70
71Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not.
72