CURLOPT_SSH_HOSTKEYDATA(3)

πŸ’… CURLOPT_SSH_HOSTKEYDATA β€” the manual page, but make it make sense ✨

okay so real talk: this is the CURLOPT_SSH_HOSTKEYDATA(3) page from the libcurl Library Functions Manual, and it's genuinely short and sweet. It's about handing a little pointer to your SSH host key callback so your callback has somewhere to stash its vibe. Let's get into it 🫢


✨ NAME ✨

CURLOPT_SSH_HOSTKEYDATA β€” literally just a pointer you pass along to the SSH host key callback πŸ’…


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <curl/curl.h>

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

🌸 DESCRIPTION 🌸

So here's the tea β˜•: you pass a void * as the parameter. That's it. That pointer gets passed along untouched β€” like, zero meddling, not even a little β€” to the callback you set with CURLOPT_SSH_HOSTKEYFUNCTION(3).

Think of it as the little bag your callback carries around. It's your stuff, you put it in there, and curl just hands the whole bag over. No cap. πŸ’–


πŸŽ€ DEFAULT πŸŽ€

NULL

(yeah, empty bag by default, bestie πŸ™ˆ)


🌈 PROTOCOLS 🌈

This functionality affects scp and sftp 🧚


⭐ EXAMPLE ⭐

ok bestie here's the whole thing in action, copy it exactly, don't be weird about it:

struct mine {
  void *custom;
};

static int hostkeycb(void *clientp,   /* CURLOPT_SSH_HOSTKEYDATA */
                     int keytype,     /* CURLKHTYPE */
                     const char *key, /* host key to check */
                     size_t keylen)   /* length of the key */
{
  /* 'clientp' points to the callback_data struct */
  /* investigate the situation and return the correct value */
  return CURLKHMATCH_OK;
}

int main(void)
{
  CURL *curl = curl_easy_init();
  if(curl) {
    struct mine callback_data;
    curl_easy_setopt(curl, CURLOPT_URL, "sftp://example.com/thisfile.txt");
    curl_easy_setopt(curl, CURLOPT_SSH_HOSTKEYFUNCTION, hostkeycb);
    curl_easy_setopt(curl, CURLOPT_SSH_HOSTKEYDATA, &callback_data);

    curl_easy_perform(curl);
  }
}

see how &callback_data gets yeeted straight into clientp inside the callback? that's the whole trick. iconic behavior honestly πŸ‘‘


πŸ’€ NOTES πŸ’€

Works only with the libssh2 backend. not negotiable, not flexible, that's just how it is 😭


πŸ‘‘ AVAILABILITY πŸ‘‘

Added in curl 7.84.0 ⭐ (so if you're on something ancient, this option is gonna look at you like πŸ‘οΈπŸ‘„πŸ‘οΈ)


πŸ”₯ RETURN VALUE πŸ”₯

curl_easy_setopt(3) returns a CURLcode indicating success or error.

CURLE_OK (0) means everything was OK β€” slay πŸ’– β€” and non-zero means an error occurred. go see libcurl-errors(3) for the full drama.


🫢 SEE ALSO 🫢


and that's the page, bestie πŸŽ€ huge shoutout to the libcurl girlies β€” this one's from the libcurl source, dated 2026-10-12, and it says CURLOPT_SSH_HOSTKEYDATA(3) right there in the footnotes. go forth and pass your pointers responsibly πŸ’œπŸ¦‹

πŸ“¦ where this page comes from