1--- 2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 3SPDX-License-Identifier: curl 4Title: CURLOPT_PORT 5Section: 3 6Source: libcurl 7See-also: 8 - CURLINFO_PRIMARY_PORT (3) 9 - CURLOPT_STDERR (3) 10 - CURLOPT_URL (3) 11Protocol: 12 - All 13--- 14 15# NAME 16 17CURLOPT_PORT - remote port number to connect to 18 19# SYNOPSIS 20 21~~~c 22#include <curl/curl.h> 23 24CURLcode curl_easy_setopt(CURL *handle, CURLOPT_PORT, long number); 25~~~ 26 27# DESCRIPTION 28 29We discourage using this option since its scope is not obvious and hard to 30predict. Set the preferred port number in the URL instead. 31 32This option sets *number* to be the remote port number to connect to, 33instead of the one specified in the URL or the default port for the used 34protocol. 35 36Usually, you just let the URL decide which port to use but this allows the 37application to override that. 38 39While this option accepts a 'long', a port number is an unsigned 16 bit number 40and therefore using a port number lower than zero or over 65535 causes a 41**CURLE_BAD_FUNCTION_ARGUMENT** error. 42 43# DEFAULT 44 45By default this is 0 which makes it not used. This also makes port number zero 46impossible to set with this API. 47 48# EXAMPLE 49 50~~~c 51int main(void) 52{ 53 CURL *curl = curl_easy_init(); 54 if(curl) { 55 CURLcode res; 56 curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin"); 57 curl_easy_setopt(curl, CURLOPT_PORT, 8080L); 58 res = curl_easy_perform(curl); 59 curl_easy_cleanup(curl); 60 } 61} 62~~~ 63 64# AVAILABILITY 65 66Always 67 68# RETURN VALUE 69 70Returns CURLE_OK 71