CURLINFO_ACTIVESOCKET(3)
π CURLINFO_ACTIVESOCKET(3) π
okay so real talk β this is a page from the libcurl manual, and it's about getting your hands on the actual socket. bestie, it's lowkey iconic. let's go π«Ά
β¨ NAME β¨
CURLINFO_ACTIVESOCKET β the active socket, periodt π
β¨ SYNOPSIS β¨
#include <curl/curl.h>
CURLcode curl_easy_getinfo(CURL *handle, CURLINFO_ACTIVESOCKET,
curl_socket_t *socket);
classic move: you pass in the handle, the info you want (CURLINFO_ACTIVESOCKET), and a pointer so it can hand you back the good stuff π
β¨ DESCRIPTION β¨
So here's the vibe: you pass a pointer to a curl_socket_t, and it gets filled in with the most recently active socket that this curl session used for the transfer connection. That's it. That's the whole girlboss moment β¨
ngl, one thing to know β if the socket is no longer valid, you get CURL_SOCKET_BAD back. not great, not terrible, just how it is π
π¨ okay this part matters, don't skip it: when you are finished working with the socket, you must call curl_easy_cleanup(3) as usual on the easy handle, and let libcurl close the socket and clean up the other resources associated with the handle. do not go closing it yourself, bestie. that's libcurl's job. iykyk.
also, heads up β this option returns the active socket only after the transfer is complete. so it's typically used in combination with CURLOPT_CONNECT_ONLY(3), which skips the transfer phase entirely. honestly? that combo ate. π₯
and some lore for you π§: CURLINFO_ACTIVESOCKET(3) was added as a replacement for CURLINFO_LASTSOCKET(3), since that one just straight up does not work on all platforms. so like... use the new one. π
π PROTOCOLS π
this functionality affects all supported protocols π¦ (yes, all of them, she's versatile)
πΈ EXAMPLE πΈ
here's the whole thing, and yes you can literally copy it:
int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_socket_t sockfd;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
/* Do not do the transfer - only connect to host */
curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L);
result = curl_easy_perform(curl);
if(result != CURLE_OK) {
printf("Error: %s\n", curl_easy_strerror(result));
curl_easy_cleanup(curl);
return 1;
}
/* Extract the socket from the curl handle */
result = curl_easy_getinfo(curl, CURLINFO_ACTIVESOCKET, &sockfd);
if(!result && sockfd != CURL_SOCKET_BAD) {
/* operate on sockfd */
}
curl_easy_cleanup(curl);
}
}
like, look at her go π connection only, no transfer, socket extracted, main character energy the entire time π
β AVAILABILITY β
Added in curl 7.45.0 β she's been around, she's established, she's got seniority π
π 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 tea
π¦ SEE ALSO π¦
the whole squad, fr fr π«Ά
and that's the page!! this cutie came from the libcurl manual, dated 2026-10-12, and the page you're reading is CURLINFO_ACTIVESOCKET(3). go get that socket bestie, you got this ππβ¨
π¦ 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