xref: /curl/docs/libcurl/opts/CURLOPT_PORT.md (revision 5a488251)
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
13Added-in: 7.1
14---
15
16# NAME
17
18CURLOPT_PORT - remote port number to connect to
19
20# SYNOPSIS
21
22~~~c
23#include <curl/curl.h>
24
25CURLcode curl_easy_setopt(CURL *handle, CURLOPT_PORT, long number);
26~~~
27
28# DESCRIPTION
29
30We discourage using this option since its scope is not obvious and hard to
31predict. Set the preferred port number in the URL instead.
32
33This option sets *number* to be the remote port number to connect to,
34instead of the one specified in the URL or the default port for the used
35protocol.
36
37Usually, you just let the URL decide which port to use but this allows the
38application to override that.
39
40While this option accepts a 'long', a port number is an unsigned 16 bit number
41and therefore using a port number lower than zero or over 65535 causes a
42**CURLE_BAD_FUNCTION_ARGUMENT** error.
43
44# DEFAULT
45
460 which makes it not used. This also makes port number zero impossible to set
47with this API.
48
49# %PROTOCOLS%
50
51# EXAMPLE
52
53~~~c
54int main(void)
55{
56  CURL *curl = curl_easy_init();
57  if(curl) {
58    CURLcode res;
59    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
60    curl_easy_setopt(curl, CURLOPT_PORT, 8080L);
61    res = curl_easy_perform(curl);
62    curl_easy_cleanup(curl);
63  }
64}
65~~~
66
67# %AVAILABILITY%
68
69# RETURN VALUE
70
71Returns CURLE_OK
72