sandros
20th November 2007, 14:06
Hi all,
I'm developing a qt4 system which connects to a ssh server by using the libssh2 library. The ssh features provided by libssh2 relies on a conventional TCP socket for secure data transmission. My goal is to use a QTcpSocket to handle portability issues among different operating systems and instruct libssh2 to use this Qt socket.
The problem is: when I create a socket by using the GNU/Linux system calls everything works fine. When I switch to the QTcpSocket libssh2 presents an error message during the session startup.
The code which works is:
int sock = socket(AF_INET, SOCK_STREAM, 0);
struct sockaddr_in sin;
sin.sin_family = AF_INET;
sin.sin_port = htons(property("port").toInt());
sin.sin_addr.s_addr = inet_addr(property("host").toString().toAscii().constData());
if (::connect(sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in)) != 0) {
fprintf(stderr, "failed to connect!\n");
return false;
}
session = libssh2_session_init();
rc = libssh2_session_startup(d->session, sock);
if (rc)
{
setErrorMessage("Failure establishing SSH session !");
return false;
}
// Authenticate via password ...
The code which uses the QTcpSocket is:
QTcpSocket socket;
socket.connectToHost(property("host").toString(), (quint16) property("port").toInt());
if (!d->socket.waitForConnected(5 * 1000))
{
setErrorMessage(d->socket.errorString());
return false;
}
session = libssh2_session_init();
rc = libssh2_session_startup(d->session, d->socket.socketDescriptor());
if (rc)
{
setErrorMessage("Failure establishing SSH session !");
return false;
}
I'm using the socketDescriptor() method to acquire the native socket descriptor required by libssh2.
The later solution doesn't work and the message "Failure establishing SSH session !" is exhibited.
What am I doing wrong ? Even if I print the int value of the descriptors in both solutions I get the same value !!!
Thanks in advance,
Sandro
I'm developing a qt4 system which connects to a ssh server by using the libssh2 library. The ssh features provided by libssh2 relies on a conventional TCP socket for secure data transmission. My goal is to use a QTcpSocket to handle portability issues among different operating systems and instruct libssh2 to use this Qt socket.
The problem is: when I create a socket by using the GNU/Linux system calls everything works fine. When I switch to the QTcpSocket libssh2 presents an error message during the session startup.
The code which works is:
int sock = socket(AF_INET, SOCK_STREAM, 0);
struct sockaddr_in sin;
sin.sin_family = AF_INET;
sin.sin_port = htons(property("port").toInt());
sin.sin_addr.s_addr = inet_addr(property("host").toString().toAscii().constData());
if (::connect(sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in)) != 0) {
fprintf(stderr, "failed to connect!\n");
return false;
}
session = libssh2_session_init();
rc = libssh2_session_startup(d->session, sock);
if (rc)
{
setErrorMessage("Failure establishing SSH session !");
return false;
}
// Authenticate via password ...
The code which uses the QTcpSocket is:
QTcpSocket socket;
socket.connectToHost(property("host").toString(), (quint16) property("port").toInt());
if (!d->socket.waitForConnected(5 * 1000))
{
setErrorMessage(d->socket.errorString());
return false;
}
session = libssh2_session_init();
rc = libssh2_session_startup(d->session, d->socket.socketDescriptor());
if (rc)
{
setErrorMessage("Failure establishing SSH session !");
return false;
}
I'm using the socketDescriptor() method to acquire the native socket descriptor required by libssh2.
The later solution doesn't work and the message "Failure establishing SSH session !" is exhibited.
What am I doing wrong ? Even if I print the int value of the descriptors in both solutions I get the same value !!!
Thanks in advance,
Sandro