I am using windows XP and visual studio 2003.
Here I am having a problem in windows only.
If I am creating to 'tunneled' channels by using
'libssh2_channel_direct_tcpip'.
The second channel creation fails 'channel2'.
But the first one is successful.
But in Linux the same program is able to create two channels!
My guess, it is a problem since libssh2 is using select(HAVE_SELECT) in
windows.
I am pasting the source code below:-
/*
CODE
=====
*/
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <time.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#ifndef _WIN32
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#else
#include <winsock2.h>
#include <ws2tcpip.h>
#endif //_WIN32
#include "libssh2.h"
/*
* This function reports the error and
* exits back to the shell :
*/
static void bail(const char *on_what)
{
if ( errno != 0 ) {
fputs(strerror(errno),stderr);
fputs(": ",stderr);
}
fputs(on_what,stderr);
fputc('\n',stderr);
exit(1);
}
int main(int argc,char **argv)
{
char *srvr_addr = NULL;
char *srvr_port = "9099";
SOCKET sock;
struct sockaddr_in sin;
LIBSSH2_SESSION *session;
LIBSSH2_CHANNEL *channel1, *channel2;
#ifdef WIN32
WSADATA wsadata;
WSAStartup(WINSOCK_VERSION, &wsadata);
#endif
sock = socket(AF_INET, SOCK_STREAM, 0);
sin.sin_family = AF_INET;
sin.sin_port = htons(22);
sin.sin_addr.s_addr = inet_addr("192.168.1.3");
printf("TCPIP connection\n");
if (connect(sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in))
!= 0)
{
fprintf(stderr, "failed to connect!\n");
return -1;
}
printf("SSH2 session\n");
session = libssh2_session_init();
if (libssh2_session_startup(session, sock))
{
fprintf(stderr, "Failure establishing SSH session\n");
return -1;
}
printf("SSH2 authentication\n");
/* We could authenticate via password */
if (libssh2_userauth_password(session, "root", "yourpassword"))
{
printf("Authentication by password failed.\n");
}
channel1 = libssh2_channel_direct_tcpip(session, "192.168.1.3", 3306);
if (channel1 == 0)
bail("Failed channel forwarding: channel1\n");
else
printf("channel connected (%x)\n",channel1);
/*
HERE THE ERROR OCCURS: In Windows it fails.
In linux we can create the channel successfully
*/
channel2 = libssh2_channel_direct_tcpip(session, "192.168.1.3", 3306);
if (channel2 == 0)
bail("Failed channel forwarding: channel2\n");
else
printf("channel connected (%x)\n",channel2);
libssh2_channel_close(channel1);
libssh2_channel_free(channel1);
libssh2_channel_close(channel1);
libssh2_channel_free(channel1);
/* Control never gets here */
return 0;
}
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
libssh2-devel mailing list
libssh2-devel_at_lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libssh2-devel
Received on 2008-01-25