Took this code from libssh2 project website.
Code:
[me@horse ssh2]$ cat test.c
#include<stdio.h>
#include <libssh2.h>
#include <sys/socket.h>
#include <sys/select.h>
#include <netinet/in.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <sys/time.h>
#include <sys/types.h>
#include <stdlib.h>
#include <fcntl.h>
#include <errno.h>
#include <ctype.h>
static int waitsocket(int socket_fd, LIBSSH2_SESSION *session)
{
struct timeval timeout;
int rc;
fd_set fd;
fd_set *writefd = NULL;
fd_set *readfd = NULL;
int dir;
timeout.tv_sec = 10;
timeout.tv_usec = 0;
FD_ZERO(&fd);
FD_SET(socket_fd, &fd);
/* now make sure we wait in the correct direction */
dir = libssh2_session_block_directions(session);
if(dir & LIBSSH2_SESSION_BLOCK_INBOUND)
readfd = &fd;
if(dir & LIBSSH2_SESSION_BLOCK_OUTBOUND)
writefd = &fd;
rc = select(socket_fd + 1, readfd, writefd, NULL, &timeout);
return rc;
}
main(){
printf ("at the end \n");
}
Compiling it bring the error as "libssh2_session_block_direction"
does not exist.
[me@horse ssh2]$ gcc -o test test.c
/tmp/ccwC6mej.o: In function `waitsocket':
test.c:(.text+0x91): undefined reference to `libssh2_session_block_directions'
collect2: ld returned 1 exit status
[me@horse ssh2]$
But it does exist in the header file libssh2.h
Code:
[me@horse ssh2]$ grep -i2 libssh2_session_block_directions /usr/include/libssh2.h
int *errmsg_len, int want_buf);
LIBSSH2_API int libssh2_session_last_errno(LIBSSH2_SESSION *session);
LIBSSH2_API int libssh2_session_block_directions(LIBSSH2_SESSION *session);
LIBSSH2_API int libssh2_session_flag(LIBSSH2_SESSION *session, int flag,
[me@horse ssh2]$
My versions of ssh and co.
Code:
[me@horse ssh2]$ rpm -aq | grep ssh
libssh2-1.2.7-4.fc16.i686
openssh-5.8p2-25.fc16.i686
libssh2-devel-1.2.7-4.fc16.i686
openssh-server-5.8p2-25.fc16.i686
openssh-askpass-5.8p2-25.fc16.i686
openssh-clients-5.8p2-25.fc16.i686
[me@horse ssh2]$