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