* By Gerald Combs <gerald@wireshark.org>
* Copyright 1998 Gerald Combs
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * SPDX-License-Identifier: GPL-2.0+
*/
#include "config.h"
#include <extcap/extcap-base.h>
#include <wsutil/interface.h>
+#include <wsutil/strtoi.h>
+#include <wsutil/filesystem.h>
+#include <wsutil/glib-compat.h>
#include <extcap/ssh-base.h>
#include <writecap/pcapio.h>
/* The read timeout in msec */
#define CISCODUMP_READ_TIMEOUT 3000
-#define CISCODUMP_EXTCAP_INTERFACE "cisco"
+#define CISCODUMP_EXTCAP_INTERFACE "ciscodump"
#define SSH_READ_BLOCK_SIZE 1024
#define SSH_READ_TIMEOUT 10000
ssh_cleanup(&sshs, &channel);
}
-static int wait_until_data(ssh_channel channel, const long unsigned count)
+static int wait_until_data(ssh_channel channel, const guint32 count)
{
long unsigned got = 0;
char output[SSH_READ_BLOCK_SIZE];
return EXIT_SUCCESS;
}
-static int parse_line(char* packet _U_, unsigned* offset, char* line, int status)
+static int parse_line(char* packet, unsigned* offset, char* line, int status)
{
char** parts;
char** part;
/* ABCDEF01: 01020304 05060708 090A0B0C 0D0E0F10 ................ */
/* Note that any of the 4 groups are optional and that a group can be 1 to 4 bytes long */
parts = g_regex_split_simple(
- "^[\\dA-Z]{8,8}:\\s+([\\dA-Z]{2,8})\\s+([\\dA-Z]{2,8}){0,1}\\s+([\\dA-Z]{2,8}){0,1}\\s+([\\dA-Z]{2,8}){0,1}.*",
+ "^[\\dA-F]{8,8}:\\s+([\\dA-F]{2,8})\\s+([\\dA-F]{2,8}){0,1}\\s+([\\dA-F]{2,8}){0,1}\\s+([\\dA-F]{2,8}){0,1}.*",
line, G_REGEX_CASELESS, G_REGEX_MATCH_ANCHORED);
part = parts;
}
part++;
}
+ g_strfreev(parts);
return CISCODUMP_PARSER_IN_PACKET;
}
-static void ssh_loop_read(ssh_channel channel, FILE* fp, const long unsigned count)
+static void ssh_loop_read(ssh_channel channel, FILE* fp, const guint32 count)
{
char line[SSH_READ_BLOCK_SIZE];
char chr;
return FALSE;
}
-static ssh_channel run_capture(ssh_session sshs, const char* iface, const char* cfilter, const unsigned long int count)
+static ssh_channel run_capture(ssh_session sshs, const char* iface, const char* cfilter, const guint32 count)
{
char* cmdline = NULL;
ssh_channel channel;
if (ssh_channel_printf(channel, "monitor capture buffer %s max-size 9500\n", WIRESHARK_CAPTURE_BUFFER) == EXIT_FAILURE)
goto error;
- if (ssh_channel_printf(channel, "monitor capture buffer %s limit packet-count %lu\n", WIRESHARK_CAPTURE_BUFFER, count) == EXIT_FAILURE)
+ if (ssh_channel_printf(channel, "monitor capture buffer %s limit packet-count %u\n", WIRESHARK_CAPTURE_BUFFER, count) == EXIT_FAILURE)
goto error;
if (cfilter) {
static int ssh_open_remote_connection(const char* hostname, const unsigned int port, const char* username, const char* password,
const char* sshkey, const char* sshkey_passphrase, const char* iface, const char* cfilter,
- const unsigned long int count, const char* fifo)
+ const guint32 count, const char* fifo)
{
ssh_session sshs;
ssh_channel channel;
"{type=unsigned}{required=true}{tooltip=The number of remote packets to capture.}\n",
inc++);
+ extcap_config_debug(&inc);
+
g_free(ipfilter);
return EXIT_SUCCESS;
{
int result;
int option_idx = 0;
- int i;
char* remote_host = NULL;
- unsigned int remote_port = 22;
+ guint16 remote_port = 22;
char* remote_username = NULL;
char* remote_password = NULL;
char* remote_interface = NULL;
char* sshkey = NULL;
char* sshkey_passphrase = NULL;
char* remote_filter = NULL;
- unsigned long int count = 0;
+ guint32 count = 0;
int ret = EXIT_FAILURE;
extcap_parameters * extcap_conf = g_new0(extcap_parameters, 1);
+ char* help_url;
char* help_header = NULL;
#ifdef _WIN32
attach_parent_console();
#endif /* _WIN32 */
+ help_url = data_file_url("ciscodump.html");
extcap_base_set_util_info(extcap_conf, argv[0], CISCODUMP_VERSION_MAJOR, CISCODUMP_VERSION_MINOR,
- CISCODUMP_VERSION_RELEASE, NULL);
+ CISCODUMP_VERSION_RELEASE, help_url);
+ g_free(help_url);
extcap_base_register_interface(extcap_conf, CISCODUMP_EXTCAP_INTERFACE, "Cisco remote capture", 147, "Remote capture dependent DLT");
help_header = g_strdup_printf(
" %s --extcap-interfaces\n"
- " %s --extcap-interface=INTERFACE --extcap-dlts\n"
- " %s --extcap-interface=INTERFACE --extcap-config\n"
- " %s --extcap-interface=INTERFACE --remote-host myhost --remote-port 22222 "
+ " %s --extcap-interface=%s --extcap-dlts\n"
+ " %s --extcap-interface=%s --extcap-config\n"
+ " %s --extcap-interface=%s --remote-host myhost --remote-port 22222 "
"--remote-username myuser --remote-interface gigabit0/0 "
- "--fifo=FILENAME --capture\n", argv[0], argv[0], argv[0], argv[0]);
+ "--fifo=FILENAME --capture\n", argv[0], argv[0], CISCODUMP_EXTCAP_INTERFACE, argv[0],
+ CISCODUMP_EXTCAP_INTERFACE, argv[0], CISCODUMP_EXTCAP_INTERFACE);
extcap_help_add_header(extcap_conf, help_header);
g_free(help_header);
extcap_help_add_option(extcap_conf, "--help", "print this help");
extcap_help_add_option(extcap_conf, "--version", "print the version");
- extcap_help_add_option(extcap_conf, "--verbose", "print more messages");
extcap_help_add_option(extcap_conf, "--remote-host <host>", "the remote SSH host");
extcap_help_add_option(extcap_conf, "--remote-port <port>", "the remote SSH port (default: 22)");
extcap_help_add_option(extcap_conf, "--remote-username <username>", "the remote SSH username (default: the current user)");
goto end;
}
- for (i = 0; i < argc; i++)
- g_debug("%s ", argv[i]);
-
while ((result = getopt_long(argc, argv, ":", longopts, &option_idx)) != -1) {
switch (result) {
break;
case OPT_REMOTE_PORT:
- remote_port = (unsigned int)strtoul(optarg, NULL, 10);
- if (remote_port > 65535 || remote_port == 0) {
+ if (!ws_strtou16(optarg, NULL, &remote_port) || remote_port == 0) {
g_warning("Invalid port: %s", optarg);
goto end;
}
break;
case OPT_REMOTE_COUNT:
- count = strtoul(optarg, NULL, 10);
+ if (!ws_strtou32(optarg, NULL, &count)) {
+ g_warning("Invalid packet count: %s", optarg);
+ goto end;
+ }
break;
case ':':
}
}
+ extcap_cmdline_debug(argv, argc);
+
if (optind != argc) {
g_warning("Unexpected extra option: %s", argv[optind]);
goto end;