GNURLOPT_PORT(3)

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

πŸ’… GNURLOPT_PORT(3) β€” like, the curl_easy_setopt options girlies ✨

okay so real talk, this is from the gnurl manual, section 3 (the curl_easy_setopt options corner of the library), and bestie, it's a short one but it matters. Let's get into it πŸŽ€


🌸 NAME 🌸

CURLOPT_PORT β€” set the remote port number you wanna work with, no cap πŸ”Œ


✨ SYNOPSIS ✨

#include <gnurl/curl.h>

CURLcode curl_easy_setopt(CURL *handle, CURLOPT_PORT, long number);

like, that's the whole vibe. three args, one dream 🫢


πŸ’– DESCRIPTION πŸ’–

So this option sets number to be the remote port number to connect to β€” instead of the one that's specified in the URL, or the default port for whatever protocol you're using. it's giving "I make the rules now" πŸ‘‘

Usually you just let the URL decide which port to use (and honestly? iconic behaviour, she knows what she's doing), but this option lets the application override that. main character energy fr ✨

⚠️ okay important thing though: while this option accepts a long, a port number is usually a 16 bit number, and therefore using a port number over 65535 will cause a run-time error. so like… don't do that πŸ’€

πŸ¦‹ DEFAULT πŸ¦‹

By default this is 0, which makes it not used. she's dormant. she's resting. she awakens only when summoned 🌈


πŸŽ€ PROTOCOLS πŸŽ€

Used for all protocols that speak to a port number. so basically everyone, bestie πŸ’…


🌟 EXAMPLE 🌟

CURL *curl = curl_easy_init();
if(curl) {
  curl_easy_setopt(curl, CURLOPT_URL, "http://example.com/foo.bin");
  curl_easy_setopt(curl, CURLOPT_PORT, 8080L);
  ret = curl_easy_perform(curl);
  curl_easy_cleanup(curl);
}

look at her go. 8080L and everything 😌 (note the L β€” it's a long, she's fancy like that)


⭐ AVAILABILITY ⭐

Always. she's been here since day one, no gatekeeping πŸ’œ


πŸ“ RETURN VALUE πŸ“

Returns CURLE_OK. that's it, that's the tweet 🐦


πŸ‘‘ SEE ALSO πŸ‘‘

go read those next, iykyk 🧚


πŸ’Œ and that's the page!! brought to you by libcurl 7.37.0, dated 17 Jun 2014 β€” yeah she's vintage, she's a classic, she ate and left no crumbs. mwah 😘 πŸ’–
πŸ“¦ where this page comes from