static void forwarding(ssh_session session){ ssh_channel channel; int r; channel = ssh_channel_new(session); r = ssh_channel_open_forward(channel, desthost, atoi(port), "localhost", 22); if(r<0) { printf("error forwarding port : %s\n",ssh_get_error(session)); return; } select_loop(session,channel); }
/** * Open a libssh forwarding channel for the given channel socket/channel pair * * Try to open a forwarding channel and if it fails, remove the chan_sock * attribute from the pm. * * @cs the map to destroy * @return 0 if OK, -1 on error */ int connect_forward_channel(struct chan_sock *cs) { struct static_port_map *pm = cs->parent; int rc; rc = ssh_channel_open_forward(cs->channel, pm->remote_host, pm->remote_port, "localhost", pm->local_port); if(rc != SSH_OK) { log_msg("Error: error opening forward %d -> %s:%d", pm->local_port, pm->remote_host, pm->remote_port); remove_channel_from_map(cs); return -1; } return 0; }
int channel_open_forward(ssh_channel channel, const char *remotehost, int remoteport, const char *sourcehost, int localport){ return ssh_channel_open_forward(channel, remotehost, remoteport, sourcehost,localport); }