CURLINFO_LOCAL_PORT(3)
π CURLINFO_LOCAL_PORT(3) π
okay so bestie, we're in the libcurl section of the manual β Library Functions Manual, if you wanna be formal about it β and today's main character is CURLINFO_LOCAL_PORT: the latest local port number. no cap, that's the whole vibe. π
β¨ NAME β¨
CURLINFO_LOCAL_PORT β latest local port number π¦
β¨ SYNOPSIS β¨
#include <curl/curl.h>
CURLcode curl_easy_getinfo(CURL *handle, CURLINFO_LOCAL_PORT, long *portp);
πΈ DESCRIPTION πΈ
so what you do is, you pass a pointer to a long, and it receives the local port number of the most recent connection done with this curl handle. literally that's it. π«Ά
if the connection was done using QUIC, the port number is a UDP port number, otherwise it is a TCP port number. iykyk. π₯
and if no connection was established, or if the protocol doesn't use ports β no shade to it β then -1 is returned. periodt. π
π§ PROTOCOLS π§
this functionality affects quic and tcp. that's the vibe check, and they both passed. β
π EXAMPLE π
here's the whole thing, copy it exactly, don't @ me:
int main(void)
{
CURL *curl;
CURLcode result;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
result = curl_easy_perform(curl);
if(CURLE_OK == result) {
long port;
result = curl_easy_getinfo(curl, CURLINFO_LOCAL_PORT, &port);
if(CURLE_OK == result) {
printf("We used local port: %ld\n", port);
}
}
curl_easy_cleanup(curl);
}
return 0;
}
like, iconic. it just prints We used local port: %ld and honestly? ate. π
β AVAILABILITY β
added in curl 7.21.0 β so she's been serving since way back. vintage queen. π
π 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 full rundown.
π SEE ALSO π
go read them, bestie, they're all linked in the group chat. π
okay that's the whole page β this one's from libcurl, dated 2026-10-12, and it was CURLINFO_LOCAL_PORT(3) the whole time. mwah. π
β¨π¦
π¦ 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