libssh2_channel_direct_tcpip_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_channel_direct_tcpip_ex β€” the libssh2 bestie handbook πŸ’–

okay so. bestie. say it with me: tunnel a TCP connection through an SSH session. that's the whole vibe. this page lives in the libssh2 manual (yes, the libssh2 manual, the one we all pretend we read) and it's about yeeting a TCP connection through your SSH session so the remote host does the legwork for you. lowkey iconic. 🫢


✨ NAME ✨

libssh2_channel_direct_tcpip_ex β€” Tunnel a TCP connection through an SSH session

like literally that's it. that's the job. tunnel the TCP. through the SSH session. no cap.


🌸 SYNOPSIS 🌸

#include <libssh2.h>

LIBSSH2_CHANNEL *
libssh2_channel_direct_tcpip_ex(LIBSSH2_SESSION *session,
                                const char *host, int port,
                                const char *shost, int sport);

LIBSSH2_CHANNEL *
libssh2_channel_direct_tcpip(LIBSSH2_SESSION *session,
                             const char *host, int port);

so there's two of them: the _ex one that takes all five args (she's the main character πŸ‘‘) and the plain one that's just the chill three-arg version. copy them character for character bestie, don't freestyle the signature, that's not the vibe. πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

okay let's go through the cast of characters one by one, because every single one matters:

  • session β€” Session instance as returned by libssh2_session_init_ex(3). you already have one of these, she's your ride or die.
  • host β€” Third party host to connect to using the SSH host as a proxy. so like, not the SSH server itself, the other person you're trying to reach through it.
  • port β€” Port on third party host to connect to. obviously. the door number on that third party host.
  • shost β€” Host to tell the SSH server the connection originated on. it's a little white lie you're telling the server about where you came from πŸ™ˆ.
  • sport β€” Port to tell the SSH server the connection originated from. same energy, but the port version.

and now the actual plot:

Tunnel a TCP/IP connection through the SSH transport via the remote host to a third party. Communication from the client to the SSH server remains encrypted, communication from the server to the 3rd party host travels in cleartext.

bestie read that last part again. cleartext. the clientβ†’SSH-server hop is encrypted, gorgeous, protected. but the SSH-serverβ†’third-party hop? that's out in the open, naked, no encryption at all. it's giving "trust the middleman" and you should know that before you ship it. 🚨

🌈 RETURN VALUE 🌈

Pointer to a newly allocated LIBSSH2_CHANNEL instance, or NULL on errors.

so: you get a fresh LIBSSH2_CHANNEL pointer when it slays, and NULL when it doesn't. check it. always check it. ✨


πŸ’€ ERRORS πŸ’€

  • LIBSSH2_ERROR_ALLOC β€” An internal memory allocation call failed. the malloc said no. it happens to the best of us. 😭

πŸ‘‘ SEE ALSO πŸ‘‘

go read that one too, you need the session before you can do literally any of this. iykyk. πŸ’œ


that's the whole page bestie, every flag, every arg, every error, nothing skipped, periodt. πŸŽ€

this absolute banger of a manual page comes from libssh2 0.15, dated 1 Jun 2007 β€” yeah she's vintage but she still ate. mwah. πŸ’