[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

example of a server


Hi,

Recently I started investigation of the libssh capabilities. I
analyzed tutorial and various examples but couldn't find a sufficient
example how to implement a non-blocking SSH server. I would like to
achieve the following:

1) listening on a TCP socket on a predefined port

2) When there is a new connection on the socket I assume that it is a
new ssh client's connection. Then I would like to pass the socket fd
to the libssh saying "handle this connection as the ssh connection".
Is the following pseudo code correct in order to do that?:

ssh_bind_struct* b = ssh_bind_new()
ssh_bind_set_blocking(b, 0)
ssh_bind_listen(b)

TCPSocket tcp;
select(tcp.fd);
ssh_bind_set_fd(tcp.fd);

ssh_session_struct* ses = ssh_new()
ssh_bind_accept(b, ses)

3) In the next step I would like to wait on another select and handle
all the requests, like SSH_REQUEST_AUTH, SSH_REQUEST_CHANNEL_OPEN,
SSH_REQUEST_CHANNEL and so on, but in the same time I would like to
check/receive (in a non-blocking mode by waiting on the same select) a
user-passed data. How to achieve that? The "ssh_message_get" is
blocking so I cannot use it. I also found an example of
reading/writing data using ssh_channel_read/ssh_channel_write
functions, however the examples do not show how to receive user data
(channel data) and in the same time handle messages such as
pty-request.

/Tomek

Follow-Ups:
Re: example of a serverTomasz Mikolajczyk <tmmikolajczyk@xxxxxxxxx>
Re: example of a serverTomasz Mikolajczyk <tmmikolajczyk@xxxxxxxxx>
Archive administrator: postmaster@lists.cynapses.org