libssh2_channel_direct_tcpip_ex(3)
π 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 bylibssh2_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. π
π¦ where this page comes from
- alpine 3.22: libssh2-doc 1.11.1-r3 Β· BSD-3-Clause
- alpine 3.23: libssh2-doc 1.11.1-r4 Β· BSD-3-Clause
- alpine 3.24: libssh2-doc 1.11.1-r4 Β· BSD-3-Clause
- arch rolling: libssh2 1.11.1-7 Β· BSD-3-Clause
- debian trixie: libssh2-1-dev 1.11.1-1+deb13u1 Β· BSD3
- debian trixie: libssh2-1-dev 1.11.1-1+deb13u2 Β· BSD3
- epel 10: libssh2-docs 1.11.1-9.el10_3 Β· BSD-3-Clause
- epel 9: libssh2-docs 1.11.1-9.el9 Β· BSD-3-Clause
- fedora 43: libssh2-docs 1.11.1-4.fc43 Β· BSD-3-Clause
- fedora 43: libssh2-docs 1.11.1-9.fc43 Β· BSD-3-Clause
- fedora 44: libssh2-docs 1.11.1-5.fc44 Β· BSD-3-Clause
- fedora 44: libssh2-docs 1.11.1-9.fc44 Β· BSD-3-Clause
- opensuse-leap 16.0: libssh2-devel 1.11.1-160000.5.1 Β· BSD-3-Clause
- opensuse-leap 16.0: libssh2-devel 1.11.1-160000.5.1 Β· BSD-3-Clause
- opensuse-leap 16.0: libssh2-devel 1.11.1-160000.5.1 Β· BSD-3-Clause
- opensuse-leap 16.0: libssh2-devel 1.11.1-160000.5.1 Β· BSD-3-Clause
- ubuntu questing: libssh2-1-dev 1.11.1-1build1
- ubuntu questing: libssh2-1-dev 1.11.1-1ubuntu0.25.10.2
- ubuntu resolute: libssh2-1-dev 1.11.1-1build2 Β· BSD3
- ubuntu resolute: libssh2-1-dev 1.11.1-1ubuntu0.26.04.4 Β· BSD3
- ubuntu stonking: libssh2-1-dev 1.11.1-6 Β· BSD3
- π the page's license: BSD-3-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms