• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1---
2c: Copyright (C) Daniel Stenberg, <daniel.se>, et al.
3SPDX-License-Identifier: curl
4Title: CURLINFO_PRIMARY_PORT
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_PRIMARY_PORT - get the latest destination port number
17
18# SYNOPSIS
19
20~~~c
21#include <curl/curl.h>
22
23CURLcode curl_easy_getinfo(CURL *handle, CURLINFO_PRIMARY_PORT, long *portp);
24~~~
25
26# DESCRIPTION
27
28Pass a pointer to a long to receive the destination port of the most recent
29connection done with this **curl** handle.
30
31This is the destination port of the actual TCP or UDP connection libcurl used.
32If a proxy was used for the most recent transfer, this is the port number of
33the proxy, if no proxy was used it is the port number of the most recently
34accessed URL.
35
36# PROTOCOLS
37
38All
39
40# EXAMPLE
41
42~~~c
43int main(void)
44{
45  CURL *curl = curl_easy_init();
46  if(curl) {
47    CURLcode res;
48    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
49    res = curl_easy_perform(curl);
50    if(res == CURLE_OK) {
51      long port;
52      res = curl_easy_getinfo(curl, CURLINFO_PRIMARY_PORT, &port);
53      if(!res)
54        printf("Connected to remote port: %ld\n", port);
55    }
56    curl_easy_cleanup(curl);
57  }
58}
59~~~
60
61# AVAILABILITY
62
63Added in 7.21.0
64
65# RETURN VALUE
66
67Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not.
68