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:
Qt Code:
  1. int sock = socket(AF_INET, SOCK_STREAM, 0);
  2.  
  3. struct sockaddr_in sin;
  4. sin.sin_family = AF_INET;
  5. sin.sin_port = htons(property("port").toInt());
  6. sin.sin_addr.s_addr = inet_addr(property("host").toString().toAscii().constData());
  7. if (::connect(sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in)) != 0) {
  8. fprintf(stderr, "failed to connect!\n");
  9. return false;
  10. }
  11.  
  12. session = libssh2_session_init();
  13. rc = libssh2_session_startup(d->session, sock);
  14. if (rc)
  15. {
  16. setErrorMessage("Failure establishing SSH session !");
  17. return false;
  18. }
  19.  
  20. // Authenticate via password ...
To copy to clipboard, switch view to plain text mode 

The code which uses the QTcpSocket is:

Qt Code:
  1. QTcpSocket socket;
  2. socket.connectToHost(property("host").toString(), (quint16) property("port").toInt());
  3.  
  4. if (!d->socket.waitForConnected(5 * 1000))
  5. {
  6. setErrorMessage(d->socket.errorString());
  7. return false;
  8. }
  9.  
  10. session = libssh2_session_init();
  11. rc = libssh2_session_startup(d->session, d->socket.socketDescriptor());
  12. if (rc)
  13. {
  14. setErrorMessage("Failure establishing SSH session !");
  15. return false;
  16. }
To copy to clipboard, switch view to plain text mode 

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