GNURLOPT_LOCALPORT(3)

πŸ“¦ version 7.72.0, in nixos 26.05, nixpkgs unstable

πŸ’… GNURLOPT_LOCALPORT(3) πŸ’…

okay so this is the GNURLOPT_LOCALPORT(3) page from the curl_easy_setopt options manual, and it’s all about setting the local port number for a socket. Bestie, let’s get into it πŸŽ€


✨ NAME ✨

CURLOPT_LOCALPORT β€” set local port number to use for socket. That’s the whole name vibe check, periodt πŸ’…

πŸ¦‹ SYNOPSIS πŸ¦‹

#include <gnurl/curl.h>

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

πŸ’– DESCRIPTION πŸ’–

Okay so: pass a long, bestie. This sets the local port number of the socket used for the connection. It’s giving β€œpick your own local port” energy ✨

This can be used in combination with CURLOPT_INTERFACE(3), and you are recommended to use CURLOPT_LOCALPORTRANGE(3) as well when this option is set. Lowkey important, so don’t skip that rec πŸ‘€

Valid port numbers are 1 - 65535. That’s the range, no cap. Stay inside it, bestie πŸ’€

πŸŽ€ DEFAULT πŸŽ€

0, disabled - use whatever the system thinks is fine. So if you don’t set it, the system gets main character energy and chooses, fr fr πŸ’β™€οΈ

🌈 PROTOCOLS 🌈

All β€” literally every protocol, no exceptions. Slay 🌟

πŸ“ EXAMPLE πŸ“

Here’s the example exactly as the manual gives it, untouched and iconic β€” and yes, it ate:

CURL *curl = curl_easy_init();
if(curl) {
  curl_easy_setopt(curl, CURLOPT_URL, "http://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);
  ret = curl_easy_perform(curl);
  curl_easy_cleanup(curl);
}

The way that comment is doing the most, and honestly? We’re obsessed 🫢

⭐ AVAILABILITY ⭐

Added in 7.15.2. Yes queen, she’s been around πŸ’«

πŸ”₯ RETURN VALUE πŸ”₯

Returns CURLE_OK. That’s it, that’s the return value tea β˜•

πŸ‘‘ SEE ALSO πŸ‘‘

Those are your besties for this one β€” go read them if you want the full lore, iykyk πŸ“š


Bye bestie 🫢 β€” this was GNURLOPT_LOCALPORT(3) from libcurl 7.37.0, dated 19 Jun 2014. Stay slay πŸ’…βœ¨

πŸ“¦ where this page comes from