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

ssh_channel_open_session only works the first time called


Hello!

I am trying to implement a simple "activate/deactive port" function for
a Cisco switch in C++.
For that I initialize a new SSH conection to the switch, which works
great, and then I am doing the following:

void activePort() {
  ssh_channel channel = ssh_channel_new(getSession());
  if (ssh_channel_open_session(channel) < 0)
  {
    // print the ssh_get_error() string
    return;
  }
  ssh_channel_request_pty(channel);
[...]
  read/write from and to channel
[...]
  ssh_channel_close(channel);
  ssh_channel_free(channel);
}

In my program I can call activatePort() excactly one times.
The second time I call activatePort() the ssh_channel_open() method
returns -1 and ssh_get_error() shows:

"Socket error: No error"

The last log message is: "channel_open: Sent a SSH_MSG_CHANNEL_OPEN type
session for channel 44"

Below is an extract of the first-run logs and from the second run.

What am I doing wrong? :(

=====================

FIRST RUN
=========
[2021/11/02 13:49:10.891679, 2] channel_open:  Creating a channel 43
with 64000 window and 32768 max packet
[2021/11/02 13:49:10.891679, 3] ssh_packet_need_rekey:  packet:
[data_rekey_needed=0, out_blocks=5, in_blocks=2
[2021/11/02 13:49:10.892676, 3] ssh_socket_unbuffered_write:  Enabling
POLLOUT for socket
[2021/11/02 13:49:10.892676, 3] packet_send2:  packet: wrote [type=90,
len=44, padding_size=19, comp=24, payload=24]
[2021/11/02 13:49:10.893673, 3] channel_open:  Sent a
SSH_MSG_CHANNEL_OPEN type session for channel 43
[2021/11/02 13:49:11.887885, 3] ssh_packet_socket_callback:  packet:
read type 91 [len=28,padding=10,comp=17,payload=17]
[2021/11/02 13:49:11.888847, 3] ssh_packet_process:  Dispatching handler
for packet type 91
[2021/11/02 13:49:11.888847, 3] ssh_packet_channel_open_conf:  Received
SSH2_MSG_CHANNEL_OPEN_CONFIRMATION
[2021/11/02 13:49:11.889845, 2] ssh_packet_channel_open_conf:  Received
a CHANNEL_OPEN_CONFIRMATION for channel 43:3
[2021/11/02 13:49:11.890856, 2] ssh_packet_channel_open_conf:  Remote
window : 8192, maxpacket : 4096

SECOND RUN
==========
[2021/11/02 13:49:12.669605, 2] channel_open:  Creating a channel 44
with 64000 window and 32768 max packet
[2021/11/02 13:49:12.670603, 3] ssh_packet_need_rekey:  packet:
[data_rekey_needed=0, out_blocks=13, in_blocks=17
[2021/11/02 13:49:12.671609, 3] ssh_socket_unbuffered_write:  Enabling
POLLOUT for socket
[2021/11/02 13:49:12.671609, 1] ssh_socket_exception_callback:  Socket
exception callback: 2 (0)
[2021/11/02 13:49:12.672598, 1] ssh_socket_exception_callback:  Socket
error: No error
[2021/11/02 13:49:12.673644, 3] packet_send2:  packet: wrote [type=90,
len=44, padding_size=19, comp=24, payload=24]
[2021/11/02 13:49:12.673644, 3] channel_open:  Sent a
SSH_MSG_CHANNEL_OPEN type session for channel 44
Socket error: No error

===================



Follow-Ups:
Re: ssh_channel_open_session only works the first time calledJakub Jelen <jjelen@xxxxxxxxxx>
Archive administrator: postmaster@lists.cynapses.org