CURLOPT_LOCALPORTRANGE(3)
π CURLOPT_LOCALPORTRANGE(3) β the curl bestie page
okay so this is a page from the Library Functions Manual and it's literally all about CURLOPT_LOCALPORTRANGE, no cap β¨
πΈ NAME πΈ
CURLOPT_LOCALPORTRANGE β the number of extra local ports libcurl is allowed to try, bestie π
β¨ SYNOPSIS β¨
#include <curl/curl.h>
CURLcode curl_easy_setopt(CURL *handle, CURLOPT_LOCALPORTRANGE,
long range);
π¦ DESCRIPTION π¦
so you pass a long, okay? and the range argument is the number of attempts libcurl makes to find a working local port number. it starts with whatever you gave to CURLOPT_LOCALPORT(3) and then adds one to the number for each retry π₯
setting this option to 1 or below makes libcurl do only one try for the exact port number β like, it's not gonna go shopping around, it's just gonna commit to that one port, periodt π
and here's the real talk: port numbers by nature are scarce resources that are busy at times, so setting this value to something too low might cause unnecessary connection setup failures π so don't be stingy with your range, okay? give it room to breathe π«Ά
π DEFAULT π
1
π PROTOCOLS π
this functionality affects all supported protocols β every single one, fr fr β
π EXAMPLE π
int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
curl_easy_setopt(curl, CURLOPT_LOCALPORT, 49152L);
/* and try 20 more ports following that */
curl_easy_setopt(curl, CURLOPT_LOCALPORTRANGE, 20L);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
like see how it locks in 49152L as the starting port and then says "and try 20 more ports following that"? that's the vibe π
π AVAILABILITY π
added in curl 7.15.2 β she's been iconic since day one π§
π₯ RETURN VALUE π₯
curl_easy_setopt(3) returns a CURLcode indicating success or error β that's the whole tea β
CURLE_OK (0) means everything was OK. non-zero means an error occurred, see libcurl-errors(3) π
π SEE ALSO π
and that's the whole page, bestie β slay, go configure your ports responsibly π β¨
libcurl Β·2026-10-12Β·CURLOPT_LOCALPORTRANGE(3)β mwah, thanks for reading, ily, bye π«Άπ
π¦ where this page comes from
- fedora 44: libcurl-devel 8.18.0-14.fc44 Β· curl
- fedora 44: libcurl-devel 8.18.0-14.fc44 Β· curl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms