1---
2c: Copyright (C) Daniel Stenberg, <daniel.se>, et al.
3SPDX-License-Identifier: curl
4Title: CURLOPT_LOCALPORTRANGE
5Section: 3
6Source: libcurl
7See-also:
8  - CURLOPT_INTERFACE (3)
9  - CURLOPT_LOCALPORT (3)
10---
11
12# NAME
13
14CURLOPT_LOCALPORTRANGE - number of additional local ports to try
15
16# SYNOPSIS
17
18~~~c
19#include <curl/curl.h>
20
21CURLcode curl_easy_setopt(CURL *handle, CURLOPT_LOCALPORTRANGE,
22                          long range);
23~~~
24
25# DESCRIPTION
26
27Pass a long. The *range* argument is the number of attempts libcurl makes
28to find a working local port number. It starts with the given
29CURLOPT_LOCALPORT(3) and adds one to the number for each retry. Setting
30this option to 1 or below makes libcurl only do one try for the exact port
31number. Port numbers by nature are scarce resources that are busy at times so
32setting this value to something too low might cause unnecessary connection
33setup failures.
34
35# DEFAULT
36
371
38
39# PROTOCOLS
40
41All
42
43# EXAMPLE
44
45~~~c
46int main(void)
47{
48  CURL *curl = curl_easy_init();
49  if(curl) {
50    CURLcode res;
51    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
52    curl_easy_setopt(curl, CURLOPT_LOCALPORT, 49152L);
53    /* and try 20 more ports following that */
54    curl_easy_setopt(curl, CURLOPT_LOCALPORTRANGE, 20L);
55    res = curl_easy_perform(curl);
56    curl_easy_cleanup(curl);
57  }
58}
59~~~
60
61# AVAILABILITY
62
63Added in 7.15.2
64
65# RETURN VALUE
66
67Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not.
68