CURLINFO_CONN_ID(3)

πŸ’… CURLINFO_CONN_ID β€” like, the ID of the last connection, bestie

okay so this is a page from the Library Functions Manual (that's the manual name, mwah πŸ’–) and it's all about CURLINFO_CONN_ID. Buckle in, it's short and iconic.


✨ NAME ✨

CURLINFO_CONN_ID β€” the ID of the last connection πŸŽ€


🌸 SYNOPSIS 🌸

#include <curl/curl.h>

CURLcode curl_easy_getinfo(CURL *handle, CURLINFO_CONN_ID,
                           curl_off_t *conn_id);

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so you pass in a pointer to a curl_off_t and it receives the connection identifier that the handle used last. that's it, that's the whole vibe πŸ’…

and listen β€” if there was, like, no connection used at all? it stores -1. no cap, that's your "nobody home" signal πŸ™ˆ

now the important part: the connection id is unique among all connections using the same connection cache. and since all connections in the same multi handle implicitly share that cache, yeah β€” that's the case for them too. iykyk ✨


πŸ”₯ PROTOCOLS πŸ”₯

this functionality affects all supported protocols β€” every single one, periodt πŸ‘‘


🧚 EXAMPLE 🧚

int main(void)
{
  CURL *curl = curl_easy_init();
  if(curl) {
    CURLcode result;

    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");

    /* Perform the request */
    result = curl_easy_perform(curl);

    if(!result) {
      curl_off_t conn_id;
      result = curl_easy_getinfo(curl, CURLINFO_CONN_ID, &conn_id);
      if(!result) {
        printf("Connection used: %" CURL_FORMAT_CURL_OFF_T "\n", conn_id);
      }
    }
  }
}

look at that. curl_easy_init, curl_easy_setopt with CURLOPT_URL, curl_easy_perform, then curl_easy_getinfo with CURLINFO_CONN_ID grabbing your conn_id and printing "Connection used: %" CURL_FORMAT_CURL_OFF_T "\n". the printf ate, fr fr πŸ’–


⭐ AVAILABILITY ⭐

added in curl 8.2.0 β€” so if you're on anything older, sorry bestie, it's giving not-yet 😭


🌈 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 β€” go check libcurl-errors(3) for the deets 🫢


πŸ‘‘ SEE ALSO πŸ‘‘


go touch grass after this, but like, after you read the also-sees. balance πŸ’…

libcurl Β· 2026-10-12 Β· that's the source/version and date, bestie β€” this page is a wrap, mwah πŸŽ€πŸ¦‹βœ¨

πŸ“¦ where this page comes from