Subject: Re: libssh2_channel_direct_tcpip_ex

Re: libssh2_channel_direct_tcpip_ex

From: Me Me <decay40_at_gmail.com>
Date: Wed, 16 Dec 2009 13:59:48 -0500

On Wed, Dec 16, 2009 at 1:52 PM, Me Me <decay40_at_gmail.com> wrote:

> On Wed, Dec 16, 2009 at 11:50 AM, Peter Stuge <peter_at_stuge.se> wrote:
>
>> Me Me wrote:
>> > I am trying to tunnel a MySQL connection thru
>> > libssh2_channel_direct_tcpip_ex.
>> ..
>> > Once I have the channel, do I need to do anything with it?
>> > The MySQL client should take over from there with the
>> > communication, since it handles all the sockets, and I should just
>> > be able to give it 127.0.0.1 and it should connect. Am I
>> > completely misunderstanding the way this works?
>>
>> Somewhat. You need to socket(), bind(3306), listen() and accept(),
>> and for each connected client you then create a direct-tcpip channel.
>>
>> host,port=127.0.0.1,3306 (relative the SSH server side)
>> shost,sport=info from the addr returned by accept()
>>
>> Then you pump data between channel and socket. Lots of fun.
>>
>>
> Peter,
>
> So does that mean I have to skip using the MySQL client library completely,
> and manipulate the raw communication from the server myself, as opposed to
> just connecting to a local port that is being forwarded from the server?
>

Sorry to reply to myself, but hopefully this will clear things up:

If I run this command from the command line:

ssh -N -f -L 3306:192.168.1.170:3306 localhost

and run a program using the libmysqlclient library connecting to
127.0.0.1:3306 it works fine. So, I guess what I am asking is there
something that is as easy as that corresponding to the direct_tcip_ex call?
I would prefer that the MySQL client library do the heavy lifiting.
Ideally, it should see the local port as just another one to communicate
over, as it does when executing the ssh command from the shell.

_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Received on 2009-12-16