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 π«Ά
CURLOPT_SSH_HOSTKEYFUNCTION(3)β the callback that actually receives your precious pointer, duh β¨
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
- 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