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