xref: /curl/docs/libcurl/opts/CURLOPT_LOCALPORT.md (revision 5a488251)
1---
2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
3SPDX-License-Identifier: curl
4Title: CURLOPT_LOCALPORT
5Section: 3
6Source: libcurl
7See-also:
8  - CURLINFO_LOCAL_PORT (3)
9  - CURLOPT_INTERFACE (3)
10  - CURLOPT_LOCALPORTRANGE (3)
11Protocol:
12  - All
13Added-in: 7.15.2
14---
15
16# NAME
17
18CURLOPT_LOCALPORT - local port number to use for socket
19
20# SYNOPSIS
21
22~~~c
23#include <curl/curl.h>
24
25CURLcode curl_easy_setopt(CURL *handle, CURLOPT_LOCALPORT, long port);
26~~~
27
28# DESCRIPTION
29
30Pass a long. This sets the local port number of the socket used for the
31connection. This can be used in combination with CURLOPT_INTERFACE(3)
32and you are recommended to use CURLOPT_LOCALPORTRANGE(3) as well when
33this option is set. Valid port numbers are 1 - 65535.
34
35# DEFAULT
36
370, disabled - use whatever the system thinks is fine
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/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
63Returns CURLE_OK
64