Hi, I am developing a test application to understand how to perform SSH tunneling to connect to a MySQL database in C ++.
I use the libssh2 library, and I use the example from https://www.libssh2.org/examples/direct_tcpip.html , but I'm not 100% sure whether this is the right thing to use.
I copied this example quite a lot, but when connecting to MySQL in my mysql throws socket
Errro 2013 (HY000): Lost connection to mysql server while "reading communication packet", system error: 0
When I connect to mysql using mysql -uroot -p -P2222, my application reads the data through the pipe using the following:
int len = libssh2_channel_read(channel, buf, sizeof(len));
and buf contains SSH-2.0- , and then this is written to the forwarding socket as follows:
wr = 0; while (wr < len) { i = send(forward_socket, buf + wr, len - wr, 0); if (i <= 0) { perror("write"); return EXIT_FAILURE; } wr += i; }
Once the transfer is complete, I will immediately get a mysql error. I suppose this is because I am sending SSH-2.0- to MySQL, which MySQL does not expect, so it closes the connection, but I donβt see what is wrong, and I canβt determine exactly whether libssh2 direct_tcpip is the right thing to use .
Thanks for any help you can provide.