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