Hi, I am a beginner in network programming and now I have problem with
using direct tcp channel.
Using direct_tcp_example is everything working good and I'm able to connect
with ssh shell to remote server. The same is when using threads in
application code - in the first thread application wait to connection, in
the second thread, new connection to localhost and local_listenport
(something like at direct_tcpip example), new session, handshake and
authentification - everything is OK.
Problem is when listensocket is set to nonblocking mode. Direct channel is
created, nonblocking mode set on session and connection is realized on
localhost. In this case socket is connected
on redirected port, but handshake returns -37 (LIBSSH2_ERROR_EAGAIN). In
this new session is set nonblocking mode.
Is it somehow possible to realize connection to 3rd party host without
using threads or somethink like that? Thanks a lot!
Example code:
...
forwardsock = accept(listensock, (struct sockaddr *)&sin, &sinlen); //now
is listensock in nonblocking mode
con->channel = libssh2_channel_direct_tcpip_ex(con->session,
remote_desthost,remote_destport, shost, sport);
if (!con->channel) { fprintf(stderr, "Could not open the direct-tcpip
channel!\n");}
libssh2_session_set_blocking(con->session, 0);
//channel is ready and now I trying connect to localhost
struct conn c1; //own structure
c1.hostname = "127.0.0.1";
c1.username = "root";
c1.password = "password";
c1.port = 2222; //local listenport
c1.session = NULL;
c1.sftp_session = NULL;
c1.sftp_alive = 1;
struct conn *st1 = &c1;
init_sock(st1); //new socket
init_session(st1); //new session
libssh2_session_set_blocking(st1->session, 0);
// all works fine but this method return -37
x = libssh2_session_handshake(st1->session, st1->socket);
printf("handshake %i\n", x);
_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Received on 2012-09-21