[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Help connecting two ports and ssh_channel_open_forward (or ssh_channel_open_reverse_forward?)
[Thread Prev] | [Thread Next]
- Subject: Help connecting two ports and ssh_channel_open_forward (or ssh_channel_open_reverse_forward?)
- From: Jens Winslow <jenswinslow4@xxxxxxxxx>
- Reply-to: libssh@xxxxxxxxxx
- Date: Thu, 16 Apr 2020 14:09:07 -0400
- To: libssh@xxxxxxxxxx
I wish to connect two ports securely through SSH, so that I can connect a socket with a secure transmission. I have an Echoing Server socket on port 2000 of my Windows machine running SSH server. I have a Client Socket that tries to connect to port 2000 and test connection by sending (and receiving back data). *This works fine without SSH*. Now I want to connect port 2000 on my SSH serve machine running echoing socket server to port 2001 in my client socket machine, then have my client socket connect to 2001, but effectively connect to 2000 through SSH. Something like this EchoClientSocket --P2001 IP127.0.0.1 ==SSH==> P2000 IP192.168.1.109--->EchoSocketServer - As per tutorial: If I use authenticated session to get channel, and call ssh_channel_open_forward(channel, "192.168.1.109", 2000, "127.0.0.1", 2001) I get no errors (or reversing combinations of IPs and ports, since it is unclear to me what is which machine and ports being connected) *However, connecting to port 2001 does not make socket server on port 2000 see connection, and sending data from socket on 2001 never shows up on 2000, nor does a reply come back.* - As per tutorial ssh_channel_open_reverse_forward ssh_channel_accept_forward fails with error on ssh_channel_accept_forward - Trying to connect and set up tunnel with putty seems to work (no error) - but again, there seem to be no connection between ports and I fail to connect to port 2001 - If I run ssh -L command on 127.0.0.1, and provide my admin password, ssh -L 2001:127.0.0.1:2000 127.0.0.1 I get a connection between port 2001 and 2000 after I provide my admin password. *At this point my socket and client works *Client--Port 2001--==SSH==--Port 2000----Echo Socket Server So I have several questions 1. The documentation for ssh_channel_listen_forward, ssh_channel_open_reverse_forward say "This function does not bind the local port and does not automatically forward the content of a socket to the channel. You still have to use channel_read and channel_write for this. " 1. *If they do not make a connection, what is the purpose of these commands?* 2. *Why would I want to use them?* 3. *How do I use the channel read and write to bind ports and sockets?* 2. *What is the best/ correect way to use libssh to connect 2 ports with a secure connection? *Port N on IP ABC <===SSH===> Port M on IP XYZ 1. *How can I achieve "ssh -L 2001:127.0.0.1:2000 <http://127.0.0.1:2000> 127.0.0.1" **programatically* 3. *Am I supposed to use forwarding or reverse forwarding? * 4. *Any suggested links and references?* I am obviously not having much luck connecting two ports based on tutorial (I did manage to connect a channel, make a pseudo shell and read/write commands). In advance, thanks for any help and suggestions. My eternal gratitude for a code example achieving a secure connection between two ports. Jens Winslow
Archive administrator: postmaster@lists.cynapses.org