How can I debug SSH tunnel? (CkSshTunnel in C++)? |
The best approach is to begin with something very simple -- and step-by-step add functionality until you arrive at the final objective. Starting with the entire ball-of-wax and trying to determine the problems in a complex system will typically get you nowhere. It's better to begin with simplicity, get it working, and then add complexity bit by bit. This guide will use C++ for the programming language, but the API is identical (except for syntax and naming conventions) in all programming languages supported by Chilkat. The first, most basic task is to setup the CkSshTunnel for debug logging, specify the property settings, and then start a background thread for accepting incoming connections. That's it. After starting the background thread, shut it down and exit the test program. No actual connections will be tested in the very first step. The point here is to (1) make sure the background thread can be started and stoppped, and (2) make sure the log files can be created. Your program must specify log file paths such that you have the filesystem permissions to create the files. Make sure your C++ program is compiled for multi-threaded (do NOT use a single-thread runtime). Here is the source code for this test: // This tests the bare minimum: // It starts a background thread to begin accepting incoming connections. // It then stops the background thread, and stops all tunnels. // (However, in this example, no tunnels are actually created, so there aren't // actually any tunnels to be stopped.) void sshTunnelTest0(void) { CkSshTunnel sshTunnel; |
Step #2 -- This is the same as the initial sanity test, except a single SSH tunnel is created, and then shutdown. No data is sent or received over the tunnel. // The next test is the same as the sshTunnelTest0, except we // initiate a connection to the SSH tunnel. Our background thread is waiting // for incoming connections on port 3316, and our foreground thread will connect to it. // Upon connecting, the background thread connects to the SSH server to create an // SSH tunnel. (The SSH server connects to the DestHostname:DestPort) // This is a bi-direction connection where data sent to localhost:3316 // will be forwarded over the SSH tunnel to the SSH server, and then the server // will forward the data to DestHostname:DestPort. |
The final test is to establish an SSH tunnel, and then send/receive data. // This is the same as the sshTunnelTest1, except we // will now send data over the tunnel. |