1---
2c: Copyright (C) Daniel Stenberg, <daniel.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)
11---
12
13# NAME
14
15CURLOPT_LOCALPORT - local port number to use for socket
16
17# SYNOPSIS
18
19~~~c
20#include <curl/curl.h>
21
22CURLcode curl_easy_setopt(CURL *handle, CURLOPT_LOCALPORT, long port);
23~~~
24
25# DESCRIPTION
26
27Pass a long. This sets the local port number of the socket used for the
28connection. This can be used in combination with CURLOPT_INTERFACE(3)
29and you are recommended to use CURLOPT_LOCALPORTRANGE(3) as well when
30this option is set. Valid port numbers are 1 - 65535.
31
32# DEFAULT
33
340, disabled - use whatever the system thinks is fine
35
36# PROTOCOLS
37
38All
39
40# EXAMPLE
41
42~~~c
43int main(void)
44{
45  CURL *curl = curl_easy_init();
46  if(curl) {
47    CURLcode res;
48    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
49    curl_easy_setopt(curl, CURLOPT_LOCALPORT, 49152L);
50    /* and try 20 more ports following that */
51    curl_easy_setopt(curl, CURLOPT_LOCALPORTRANGE, 20L);
52    res = curl_easy_perform(curl);
53    curl_easy_cleanup(curl);
54  }
55}
56~~~
57
58# AVAILABILITY
59
60Added in 7.15.2
61
62# RETURN VALUE
63
64Returns CURLE_OK
65