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