static ssh_channel run_ssh_command(ssh_session sshs, const char* capture_bin, const char* iface, const char* cfilter, unsigned long int count) { gchar* cmdline; ssh_channel channel; char* quoted_bin; char* quoted_iface; char* default_filter; char* quoted_filter; char* count_str = NULL; unsigned int remote_port = 22; if (!capture_bin) capture_bin = DEFAULT_CAPTURE_BIN; if (!iface) iface = "eth0"; channel = ssh_channel_new(sshs); if (!channel) return NULL; if (ssh_channel_open_session(channel) != SSH_OK) { ssh_channel_free(channel); return NULL; } ssh_options_get_port(sshs, &remote_port); /* escape parameters to go save with the shell */ quoted_bin = g_shell_quote(capture_bin); quoted_iface = g_shell_quote(iface); default_filter = local_interfaces_to_filter(remote_port); if (!cfilter) cfilter = default_filter; quoted_filter = g_shell_quote(cfilter); if (count > 0) count_str = g_strdup_printf("-c %lu", count); cmdline = g_strdup_printf("%s -i %s -P -w - -f %s %s", quoted_bin, quoted_iface, quoted_filter, count_str ? count_str : ""); verbose_print("Running: %s\n", cmdline); if (ssh_channel_request_exec(channel, cmdline) != SSH_OK) { ssh_channel_close(channel); ssh_channel_free(channel); channel = NULL; } g_free(quoted_bin); g_free(quoted_iface); g_free(default_filter); g_free(quoted_filter); g_free(cmdline); if (count_str) g_free(count_str); return channel; }
static void torture_options_get_port(void **state) { ssh_session session = *state; unsigned int given_port = 1234; unsigned int port_container; int rc; rc = ssh_options_set(session, SSH_OPTIONS_PORT, &given_port); assert_true(rc == 0); rc = ssh_options_get_port(session, &port_container); assert_true(rc == 0); assert_int_equal(port_container, 1234); }