CURLOPT_LOCALPORT(3)

πŸ’… CURLOPT_LOCALPORT(3) β€” the "pick your own local port" manual, bestie

okay so this is a libcurl manpage, like from the Library Functions Manual, and it's all about choosing the local port number your socket uses. no cap, it's lowkey iconic. let's get into it πŸŽ€


✨ NAME ✨

CURLOPT_LOCALPORT β€” literally the local port number to use for the socket πŸ’–

🌸 SYNOPSIS 🌸

#include <curl/curl.h>

CURLcode curl_easy_setopt(CURL *handle, CURLOPT_LOCALPORT, long port);

πŸ¦‹ DESCRIPTION πŸ¦‹

So you pass a long, right? And that sets the local port number of the socket that's used for the connection. Periodt. πŸ’…

You can totally use this in combination with CURLOPT_INTERFACE(3), and honestly? You're recommended to use CURLOPT_LOCALPORTRANGE(3) as well when this option is set β€” like, do both, bestie, it's giving teamwork. 🫢

Valid port numbers are 1 - 65535. That's the whole range, no cap. ✨

πŸŽ€ DEFAULT πŸŽ€

0, disabled β€” use whatever the system thinks is fine πŸ™ˆ (the system is the main character here, we just let it cook)

🧚 PROTOCOLS 🧚

This functionality affects all supported protocols. all of them. every single one. slay. πŸ‘‘

⭐ 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 look at that β€” sets the port to 49152L, then tries 20 more ports following that. ate and left no crumbs. πŸ”₯

🌈 AVAILABILITY 🌈

Added in curl 7.15.2 β€” vintage but still iconic πŸ’œ

πŸ’€ RETURN VALUE πŸ’€

curl_easy_setopt(3) returns a CURLcode indicating success or error.

CURLE_OK (0) means everything was OK β€” we love to see it 😭✨ β€” and non-zero means an error occurred, in which case go see libcurl-errors(3). iykyk.

🌸 SEE ALSO 🌸


k that's the whole page, bestie πŸ“ β€” this one came from the libcurl Library Functions Manual, dated 2026-10-12, in the CURLOPT_LOCALPORT(3) era. mwah, go pick a port and slay πŸ’‹

πŸ“¦ where this page comes from