I have connected to the remote external host using Libssh2, and now I want to map the port of the internal host to 127.0.0.1. The code is as follows:
localPort := 33069;
tunnelSock := fpSocket(AF_INET, SOCK_STREAM, 0);
FillChar(tunnelAddr, SizeOf(tunnelAddr), 0);
tunnelAddr.sin_family := AF_INET;
tunnelAddr.sin_port := htons(localPort);
tunnelAddr.sin_addr.S_addr := INADDR_ANY;
rc := fpBind(tunnelSock, @tunnelAddr, SizeOf(tunnelAddr));
rc := fpListen(tunnelSock, 1);
channel1:=libssh2_channel_direct_tcpip_ex(session1, '192.168.0.77', 3306, '127.0.0.1', localPort);
But now MySQL cannot connect to the intranet host. The error is: MySQL waiting for initial communication packet.
rc := fpBind(tunnelSock, @tunnelAddr, SizeOf(tunnelAddr));
rc := fpListen(tunnelSock, 1);
channel1:=libssh2_channel_direct_tcpip_ex(session1, '192.168.0.77', 3306, '127.0.0.1', localPort);
All return to normal.