CURLOPT_PREREQDATA(3)

πŸ’… CURLOPT_PREREQDATA(3) πŸ’…

okay so real talk, bestie β€” welcome to the CURLOPT_PREREQDATA page from the Library Functions Manual. Yes, that's the whole title, yes I'm folding it in right here at the top so we can get to the good stuff. Let's go ✨


πŸŽ€ NAME πŸŽ€

CURLOPT_PREREQDATA β€” the lil' pointer you get to pass to the pre-request callback 🫢


🌸 SYNOPSIS 🌸

#include <curl/curl.h>

CURLcode curl_easy_setopt(CURL *handle, CURLOPT_PREREQDATA, void *pointer);

✨ DESCRIPTION ✨

So here's the vibe: you hand libcurl a pointer, and libcurl is like "cool, not mine, not touching it πŸ’…" β€” it literally leaves it alone, untouched. Then it passes that exact same pointer as the first argument to the pre-request callback you set up with CURLOPT_PREREQFUNCTION(3). That's it. That's the whole job. Iconic, honestly. πŸ‘‘

Basically it's your lil' bag of snacks you drop off before the callback shows up, and the callback gets to open it. No cap.


πŸ’– DEFAULT πŸ’–

NULL

(which is giving "no snacks were packed" energy, ngl πŸ™ˆ)


πŸ¦‹ PROTOCOLS πŸ¦‹

this functionality affects all supported protocols β€” like, every single one, fr fr 🌈


πŸ”₯ EXAMPLE πŸ”₯

struct priv {
  void *custom;
};

static int prereq_callback(void *clientp,
                           char *conn_primary_ip,
                           char *conn_local_ip,
                           int conn_primary_port,
                           int conn_local_port)
{
  printf("Connection made to %s:%d\n", conn_primary_ip, conn_primary_port);
  return CURL_PREREQFUNC_OK;
}

int main(void)
{
  struct priv prereq_data;
  CURL *curl = curl_easy_init();
  if(curl) {
    curl_easy_setopt(curl, CURLOPT_PREREQFUNCTION, prereq_callback);
    curl_easy_setopt(curl, CURLOPT_PREREQDATA, &prereq_data);
    curl_easy_perform(curl);
  }
}

see how &prereq_data gets handed over and then just... shows up as clientp in the callback? that's the whole trick, bestie πŸͺ„


⭐ AVAILABILITY ⭐

added in curl 7.80.0 β€” so if you're on something older, this is not the moment, sorry 😭


🌷 RETURN VALUE 🌷

curl_easy_setopt(3) hands you back a CURLcode β€” it's telling you whether it ate or whether it choked πŸ’€

  • CURLE_OK (0) β€” everything was OK, slay βœ…
  • non-zero β€” an error occurred, go check libcurl-errors(3), iykyk

πŸ‘‘ SEE ALSO πŸ‘‘


⚠️ heads up: this is the data half of the pair. the actual callback comes from CURLOPT_PREREQFUNCTION(3) β€” that's where the action lives. this option is just the plus-one 🫢

and that's the page!! mwah πŸ’‹ β€” brought to you by libcurl, dated 2026-10-12, in the one and only CURLOPT_PREREQDATA(3) era. go forth and pass pointers, bestie πŸŽ€πŸ¦‹πŸ’œ

πŸ“¦ where this page comes from