CURLOPT_PORT(3)
π CURLOPT_PORT β remote port number to connect to
ok so this is from the Library Functions Manual, page CURLOPT_PORT(3), and bestieβ¦ we gotta talk about it. π«Ά
β¨ SYNOPSIS β¨
#include <curl/curl.h>
CURLcode curl_easy_setopt(CURL *handle, CURLOPT_PORT, long number);
πΈ DESCRIPTION πΈ
Okay so real talk first: we lowkey discourage using this option π because its scope is genuinely not obvious and honestly hard to predict. The move? Set the preferred port number in the URL instead. That's the vibe. π
So what does it even do β this option sets number to be the remote port number to connect to, instead of the one specified in the URL or the default port for the protocol you're using. it's giving override energy. π
Usually you just let the URL decide which port to use, but this lets the application override that. main character option, fr fr. β¨
β οΈ Now the important bit, bestie, don't skip this: while this option accepts along, a port number is an unsigned 16 bit number β so using a port number lower than zero or over 65535 causes aCURLE_BAD_FUNCTION_ARGUMENTerror. no cap, it will simply not slay. π
π¦ DEFAULT π¦
0, which makes it not used. Which also means port number zero is literally impossible to set with this API. π
π PROTOCOLS π
This functionality affects all supported protocols. every single one. π
π 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_PORT, 8080L);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
look at her go π§ 8080L β yes with the L, she's a long. β
π AVAILABILITY π
Added in curl 7.1. vintage icon behavior. π
π₯ 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. non-zero means an error occurred, so go check libcurl-errors(3). π
πΈ SEE ALSO πΈ
go read those too, iykyk π
ok bye bestie, this page came from libcurl, dated 2026-10-12, filed under CURLOPT_PORT(3) β mwah, slay, periodt. πβ¨ππ¦
π¦ 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