[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Working on keepalive messages while waiting for local connection
[Thread Prev] | [Thread Next]
- Subject: Re: Working on keepalive messages while waiting for local connection
- From: g4-lisz@xxxxxxxxxxxx
- Reply-to: libssh@xxxxxxxxxx
- Reply-to: libssh@xxxxxxxxxx
- Date: Wed, 11 Apr 2018 16:27:16 +0200
- To: libssh@xxxxxxxxxx
Hello all
I realized that SSH servers with the keep-alive option enabled first
send the keep-alive _global_ request as long as nothing had connected to
the local TCP socket:
$> ssh -v -N xxx@yyy -L 8088:testcom.com:80
debug1: client_input_global_request: rtype keepalive@xxxxxxxxxxx
want_reply 1
After connecting to localhost:8088, these requests are sent over the
channel:
debug1: client_input_channel_req: channel 2 rtype
keepalive@xxxxxxxxxxx reply 1
From this I conclude that the channel should not be opened before there
is a waiting connection on the local TCP socket.
But how do I tell libssh to work on the global request as long as there
is no open channel?
Maybe I have to use ssh_get_fd() and the use select() also on this
socket while waiting for the local incoming connections? And then use
ssh_set_fd_toread()?
I would appreciate a lot if someone could show me some sample code.
Best regards,
Till
On 09.04.2018 18:32, g4-lisz@xxxxxxxxxxxx wrote:
> Hi there
>
> I wrote some basic ssh client to forward a port. This involves binding a
> local listening socket and waiting for an application to connect. But as
> long as there is nothing connected to the local socket, the client is
> not reading from or writing to the channel. This seems to be an issue as
> soon as a SSH server sends keep alive messages: Because nothing is read
> from the client's side of the channel, libssh does not work on the
> keepalive messages.
>
> The pseudo code looks like this:
>
> socket = socket(PF_INET,...);
> bind(socket);
> listen(socket);
>
> while(1) {
> do{ /* nada */ } while( 0 == select(socket,...) );
>
> forwardsock = accept(socket);
> channel = ssh_channel_new(session);
> ssh_channel_open_forward(channel, ...);
>
> while(1) {
> do{ /* nada */ } while( SSH_EINTR == ssh_select(channel,
> channelout, forwardsock) );
>
> if (FD_ISSET(forwardsock,...)) { /* read from socket and write
> to channel */ }
>
> if (channelout) { /* read from channel and write to socket */ }
>
> if (EOF) {break;}
> }
> close(forwardsock);
> ssh_channel_close(channel);
> }
>
> Without keepalive messages from the server, all works fine.
>
> How can this issue be solved?
>
> Thanks,
> Till
>
>
>
| Re: Working on keepalive messages while waiting for local connection | Andreas Schneider <asn@xxxxxxxxxxxxxx> |
| Working on keepalive messages while waiting for local connection | g4-lisz@xxxxxxxxxxxx |