CURLOPT_LOCALPORT.md (1425B)
1 --- 2 c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 3 SPDX-License-Identifier: curl 4 Title: CURLOPT_LOCALPORT 5 Section: 3 6 Source: libcurl 7 See-also: 8 - CURLINFO_LOCAL_PORT (3) 9 - CURLOPT_INTERFACE (3) 10 - CURLOPT_LOCALPORTRANGE (3) 11 Protocol: 12 - All 13 Added-in: 7.15.2 14 --- 15 16 # NAME 17 18 CURLOPT_LOCALPORT - local port number to use for socket 19 20 # SYNOPSIS 21 22 ~~~c 23 #include <curl/curl.h> 24 25 CURLcode curl_easy_setopt(CURL *handle, CURLOPT_LOCALPORT, long port); 26 ~~~ 27 28 # DESCRIPTION 29 30 Pass a long. This sets the local port number of the socket used for the 31 connection. This can be used in combination with CURLOPT_INTERFACE(3) 32 and you are recommended to use CURLOPT_LOCALPORTRANGE(3) as well when 33 this option is set. Valid port numbers are 1 - 65535. 34 35 # DEFAULT 36 37 0, disabled - use whatever the system thinks is fine 38 39 # %PROTOCOLS% 40 41 # EXAMPLE 42 43 ~~~c 44 int 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/foo.bin"); 50 curl_easy_setopt(curl, CURLOPT_LOCALPORT, 49152L); 51 /* and try 20 more ports following that */ 52 curl_easy_setopt(curl, CURLOPT_LOCALPORTRANGE, 20L); 53 res = curl_easy_perform(curl); 54 curl_easy_cleanup(curl); 55 } 56 } 57 ~~~ 58 59 # %AVAILABILITY% 60 61 # RETURN VALUE 62 63 curl_easy_setopt(3) returns a CURLcode indicating success or error. 64 65 CURLE_OK (0) means everything was OK, non-zero means an error occurred, see 66 libcurl-errors(3).