libssh2_session_method_pref(3)

πŸ“¦
version 1.11.1 Β· 3 versions
, in alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, debian trixie, epel 10, epel 9, fedora 43, fedora 44, opensuse-leap 16.0, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– libssh2_session_method_pref β€” the libssh2 manual, but make it make sense πŸ’–

okay bestie, welcome to the libssh2 manual page for libssh2_session_method_pref(3) β€” yes that's the whole name, yes it's a mouthful, we're gonna get through it together 🫢


✨ NAME ✨

libssh2_session_method_pref β€” set preferred key exchange method πŸ‘‘


✨ SYNOPSIS ✨

#include <libssh2.h>

int
libssh2_session_method_pref(LIBSSH2_SESSION *session,
                            int method_type, const char *prefs);

✨ DESCRIPTION ✨

okay so here's the vibe. You're telling libssh2 which methods you want, in what order, before it goes and talks to the remote host. It's giving "I have preferences and I'm not sorry" πŸ’…

The arguments, one by one:

  • session β€” the Session instance, as returned by libssh2_session_init_ex(3). Your main character object fr fr 🌸
  • method_type β€” one of the Method Type constants. Pick your fighter.
  • prefs β€” a comma-delimited list of the preferred methods you wanna use, with the most preferred listed first and the least preferred listed last. Lowkey a ranking. Highkey a ranking.
heads up: if a method is listed that libssh2 doesn't support, it just gets ignored β€” no error, no drama, nothing. It will not be sent to the remote host during protocol negotiation. So don't be out here thinking you sent something you didn't 😭

So what does this actually do? It sets the preferred methods to be negotiated. ✨

And this is the part that matters: these preferences must be set prior to calling libssh2_session_handshake(3), because that's when they get used β€” during the protocol initiation phase. Set them after and, bestie, you're just too late. πŸ•°οΈπŸ’€


✨ RETURN VALUE ✨

  • 0 on success πŸŽ€
  • negative on failure

It returns LIBSSH2_ERROR_EAGAIN when it would otherwise block. And yes, LIBSSH2_ERROR_EAGAIN is a negative number, but no, it's not really a failure per se. It's just vibing. Don't panic. πŸ™ˆ


✨ ERRORS ✨

  • LIBSSH2_ERROR_INVAL β€” the requested method type was invalid. wrong button, bestie πŸ”₯
  • LIBSSH2_ERROR_ALLOC β€” an internal memory allocation call failed. it's not you, it's the malloc πŸ’€
  • LIBSSH2_ERROR_METHOD_NOT_SUPPORTED β€” the requested method is not supported. she said no πŸ’…

✨ SEE ALSO ✨


and that's the whole page, you ate it πŸ‘‘ periodt πŸ’–

cute little sign-off: this was libssh2 0.15, dated 1 Jun 2007, and yeah the date is older than most of us but she's still iconic βœ¨πŸ¦‹