You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to use the channel_open_direct_tcpip method to open a simple local port forwarding, and got 2 questions:
Is it possible to get a random available local port?
In my case, I just want to open the local port, so a database client is able to use it to talk to the database via the tunnel. aka I do not really want/need to handle anything via the russh channel. Is it possible?
Thanks
The text was updated successfully, but these errors were encountered:
You might be confused by the difference in concepts between the OpenSSH client and the protocol itself. You don't need to open a local port if you just want to connect to somewhere on the remote side via direct-tcpip, you can just do it without listening on the local side first.
The reason why the OpenSSH client does this is because that's the only usable way to do it in a general purpose CLI client
If you just want to connect to a remote database, use channel_open_direct_tcpip, turn your channel into a stream via Channel::into_stream and pass that to your database client library.
Is it possible to get a random available local port?
Yes. Specify port 0 as the port to listen on. Most OS's (Linux, Windows, macOS, at least) will assign a random available port. Example:
use tokio::net::TcpListener;#[tokio::main]asyncfnmain(){let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();println!("Listening on port {}",listener.local_addr().unwrap().port());}
Hi,
I am trying to use the
channel_open_direct_tcpip
method to open a simple local port forwarding, and got 2 questions:Thanks
The text was updated successfully, but these errors were encountered: