[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Reverse port forwarding requests server implementation

I'm trying to implement a ssh server, obiousvly using libssh, that accept
reverse port forwarding requests coming from clients.

For the client implementation I'm using with success the example available
in the tutorial ( http://api.libssh.org/master/libssh_tutor_forwarding.html ),
but for server I'm able to find only example about authentication, channel
open/close/write/read, and no references about how to accept incoming
reverse port forwading requests.

I see that in the source code there are some undocumented functions that
talks about general request and so on, but also after several attempes I'm
not able to find a solution.

Below some code.

if ( rc == SSH_AUTH_SUCCESS )
DebugStream() << "Authentication completed with success";
 //forward connection
rc = ssh_forward_listen(ssh_session, NULL, 3863 , NULL);
 if (rc != SSH_OK)
DebugStream() << "Error opening remote port:" << ssh_get_error(ssh_session);
DebugStream() << "Error opening remote port:" <<

DebugStream() << "Waiting forward connections";
ssh_channel channel = ssh_forward_accept(ssh_session, 60000);
 if (channel == NULL)
DebugStream() << "Error waiting for incoming connection:" <<
 DebugStream() << "Connection accepted";


do { //waiting for open channel request message = ssh_message_get(session);
log("Message received"); if(message){ switch(ssh_message_type(message)){
ssh_message_free(message); break; } default:
ssh_message_reply_default(message); ssh_message_free(message); } } }
while(message); log("Forward request ok!");

Is this code correct?
Any suggestion?
Thank you in advance

Best Regards
-- Marco Ganci
-- mak82@xxxxxxxxx
-- marco.ganci@xxxxxxxxx

Re: Reverse port forwarding requests server implementationAndreas Schneider <asn@xxxxxxxxxxxxxx>
Archive administrator: postmaster@lists.cynapses.org