CURLINFO_PRIMARY_PORT(3)
π CURLINFO_PRIMARY_PORT(3) β like, the manual page, bestie
okay so real talk, this is one of those libcurl manual pages (that's the Library Functions Manual vibe, iykyk) and honestly? it's a little cutie. Let's get into it β¨
πΈ NAME πΈ
CURLINFO_PRIMARY_PORT β last destination port number
β¨ SYNOPSIS β¨
#include <curl/curl.h>
CURLcode curl_easy_getinfo(CURL *handle, CURLINFO_PRIMARY_PORT, long *portp);
π DESCRIPTION π
okay so what you're doing here is passing a pointer to a long and it receives the destination port of the most recent connection done with this curl handle. that's it, that's the whole vibe π
and it's specifically the destination port of the actual TCP or UDP connection that libcurl used. so like, important nuance incoming:
- if a proxy was used for the most recent transfer β this is the port number of the proxy
- if no proxy was used β this is the port number of the most recently accessed URL
if the connection was done using QUIC, the port number is a UDP port number. (not me double-checking which port family we're in π«Ά)
and if no connection was established, or if the protocol doesn't even use ports? then -1 is returned. no cap, that's your "nope" signal π
π¦ PROTOCOLS π¦
This functionality affects all supported protocols β every single one, periodt π
π EXAMPLE π
okay here's the actual code, copy it exactly bestie, don't be creative with it:
int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
result = curl_easy_perform(curl);
if(result == CURLE_OK) {
long port;
result = curl_easy_getinfo(curl, CURLINFO_PRIMARY_PORT, &port);
if(!result)
printf("Connected to remote port: %ld\n", port);
}
curl_easy_cleanup(curl);
}
}
β AVAILABILITY β
Added in curl 7.21.0 β so your fave has been iconic for a minute π°οΈ
π RETURN VALUE π
curl_easy_getinfo(3) returns a CURLcode indicating success or error.
CURLE_OK(0) means everything was OK π₯³- non-zero means an error occurred β see
libcurl-errors(3)for the deets
π SEE ALSO π
ngl, this page is short and sweet and I'm obsessed. go forth and check your ports, bestie πΈ
libcurl manual, dated 2026-10-12 β that's the source/version and date, mwah, signing off π«Άβ¨
π¦ 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