I use the client code for direct and reverse port forwarding from the official tutorials: http://api.libssh.org/master/libssh_tutor_forwarding.html
This code works perfectly when connecting the client to an OpenSSH server on Ubuntu 16.10, i.e., direct and reverse port forwarding is achieved.
However, consider the client code for reverse port forwarding (web_server()
), which makes use of the following calls:
ssh_channel_listen_forward()
ssh_channel_accept_forward()
Using my own libssh server, the problem is that the client times out in the call to ssh_channel_accept_forward()
with the following error message:
"No channel request of this type from server"
That is, the error message is printed by the following client code after waiting 1 minute:
channel = ssh_channel_accept_forward(session, 60000, &port);
if (channel == NULL)
{
fprintf(stderr, "Error waiting for incoming connection: %s\n",
ssh_get_error(session));
return SSH_ERROR;
}
How do I construct a channel request on the server side, such that the client doesn't time out in ssh_channel_forward_accept()
and a new forward channel is created? I've tried most of the API functions without luck...
Is there a specific API function for sending such channel request? If not, how do I accomplish the task of requesting the channel?
My code on the server side goes along the following lines, where the ssh_channel_listen_forward()
request is captured by the following callback function:
void global_request(ssh_session session, ssh_message message, void *userdata) {
#ifdef DEBUG
printf("[Debug] global_request()\n");
#endif
struct session_data_struct *session_data = (struct session_data_struct*) userdata;
ssh_message_global_request_reply_success(message, 8080);
const char *addr = ssh_message_global_request_address(message);
int port = ssh_message_global_request_port(message);
printf("Received global request: %s:%d\n", addr, port);
session_data->channel = ssh_channel_new(session);
ssh_channel ch = ssh_message_channel_request_channel(message);
if (ssh_channel_is_open(session_data->channel)) {
printf("Channel is open!\n");
}
}
However, as stated, the server is not making the client accept a new forward channel in the call to ssh_channel_accept_forward()
.
Any ideas?