libssh2_session_init_ex(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_init_ex β€” bestie's guide to starting an SSH session πŸ’–

ok so this is page libssh2_session_init_ex(3) from the libssh2 manual, and it's literally the first thing you call. main character energy only.


🌸 SYNOPSIS 🌸

#include <libssh2.h>

LIBSSH2_SESSION *
libssh2_session_init_ex(LIBSSH2_ALLOC_FUNC((*myalloc)),
                        LIBSSH2_FREE_FUNC((*myfree)),
                        LIBSSH2_REALLOC_FUNC((*myrealloc)),
                        void *abstract);

LIBSSH2_SESSION *
libssh2_session_init(void);

two flavours, bestie: the fancy one with all the callbacks, and the chill one with zero args 🫢


πŸ’… DESCRIPTION πŸ’…

ok so the extended version takes four args, let's go one by one:

  • myalloc β€” ur custom allocator function. go read the section on Callbacks for how to actually write an allocator callback. pass NULL and it just uses the default system allocator, no stress ✨
  • myfree β€” ur custom de-allocator function. again, Callbacks section has the deets for implementing a deallocator callback. NULL here means default system deallocator, periodt.
  • myrealloc β€” ur custom re-allocator function. yep, Callbacks section, reallocator callback, you know the drill. NULL = default system reallocator 🌸
  • abstract β€” an arbitrary pointer to application specific callback data. this value gets passed to any callback function associated with the named session instance. it's giving "attach whatever u want to the session" πŸ’«

so what does the whole thing actually do? it initializes an SSH session object, duh πŸ’– by default the system memory allocators (malloc(), free(), realloc()) handle every dynamically allocated memory block. but if u want alternate memory allocation functions, that's what the extended version of this API call is for β€” and/or u can attach optional application specific data to the session object. slay.

⚠️ important bestie: this method must be called first, before u configure session options or start up an SSH session with a remote server. like, it's the opening act. no skipping ahead. πŸ™ˆ

πŸŽ€ RETURN VALUE πŸŽ€

a pointer to a freshly allocated LIBSSH2_SESSION instance πŸ’– … or NULL if something went wrong 😭 (errors, bestie, errors).


πŸ¦‹ SEE ALSO πŸ¦‹


and that's the whole vibe, bestie ✨ this was from libssh2 version 0.15, dated 1 Jun 2007 β€” yeah she's vintage but she still ate πŸ’…πŸ‘‘ no cap, go init that session. πŸŽ€πŸ¦‹πŸ’œ