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
- 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