aboutsummaryrefslogtreecommitdiffstats
path: root/extcap/sshdump.c
diff options
context:
space:
mode:
authorJoão Valverde <j@v6e.pt>2021-07-26 17:22:36 +0100
committerJoão Valverde <j@v6e.pt>2021-09-17 00:43:54 +0100
commit8df2a73594fbcc812f4ea22a72ab7a79bfb63dc3 (patch)
tree7d30bc5be8e85c52c0dd295cb15cd717d5770dcb /extcap/sshdump.c
parent7462e76884942258bae110ead925f25ffa54e2a8 (diff)
Use the musl in-tree getopt_long() everywhere
Besides the obvious limitation of being unavailable on Windows, the standard is vague about getopt() and getopt_long() has many non-portable pitfalls and buggy implementations, that increase the maintainance cost a lot. Also the GNU libc code currently in the tree is not suited for embedding and is unmaintainable. Own maintainership for getopt_long() and use the musl implementation everywhere. This way we don't need to worry if optreset is available, or if the $OPERATING_SYSTEM version behaves in subtly different ways. The API is under the Wireshark namespace to avoid conflicts with system headers. Side-note, the Mingw-w64 9.0 getopt_long() implementation is buggy with opterr and known to crash. In my experience it's a headache to use the embedded getopt implementation if the system provides one.
Diffstat (limited to 'extcap/sshdump.c')
-rw-r--r--extcap/sshdump.c42
1 files changed, 21 insertions, 21 deletions
diff --git a/extcap/sshdump.c b/extcap/sshdump.c
index afb7693193..2c3bb37c7a 100644
--- a/extcap/sshdump.c
+++ b/extcap/sshdump.c
@@ -426,15 +426,15 @@ int main(int argc, char *argv[])
"listen on local interfaces IPs)");
extcap_help_add_option(extcap_conf, "--remote-count <count>", "the number of packets to capture");
- opterr = 0;
- optind = 0;
+ ws_opterr = 0;
+ ws_optind = 0;
if (argc == 1) {
extcap_help_print(extcap_conf);
goto end;
}
- while ((result = getopt_long(argc, argv, ":", longopts, &option_idx)) != -1) {
+ while ((result = ws_getopt_long(argc, argv, ":", longopts, &option_idx)) != -1) {
switch (result) {
@@ -450,51 +450,51 @@ int main(int argc, char *argv[])
case OPT_REMOTE_HOST:
g_free(ssh_params->host);
- ssh_params->host = g_strdup(optarg);
+ ssh_params->host = g_strdup(ws_optarg);
break;
case OPT_REMOTE_PORT:
- if (!ws_strtou16(optarg, NULL, &ssh_params->port) || ssh_params->port == 0) {
- ws_warning("Invalid port: %s", optarg);
+ if (!ws_strtou16(ws_optarg, NULL, &ssh_params->port) || ssh_params->port == 0) {
+ ws_warning("Invalid port: %s", ws_optarg);
goto end;
}
break;
case OPT_REMOTE_USERNAME:
g_free(ssh_params->username);
- ssh_params->username = g_strdup(optarg);
+ ssh_params->username = g_strdup(ws_optarg);
break;
case OPT_REMOTE_PASSWORD:
g_free(ssh_params->password);
- ssh_params->password = g_strdup(optarg);
- memset(optarg, 'X', strlen(optarg));
+ ssh_params->password = g_strdup(ws_optarg);
+ memset(ws_optarg, 'X', strlen(ws_optarg));
break;
case OPT_SSHKEY:
g_free(ssh_params->sshkey_path);
- ssh_params->sshkey_path = g_strdup(optarg);
+ ssh_params->sshkey_path = g_strdup(ws_optarg);
break;
case OPT_SSHKEY_PASSPHRASE:
g_free(ssh_params->sshkey_passphrase);
- ssh_params->sshkey_passphrase = g_strdup(optarg);
- memset(optarg, 'X', strlen(optarg));
+ ssh_params->sshkey_passphrase = g_strdup(ws_optarg);
+ memset(ws_optarg, 'X', strlen(ws_optarg));
break;
case OPT_PROXYCOMMAND:
g_free(ssh_params->proxycommand);
- ssh_params->proxycommand = g_strdup(optarg);
+ ssh_params->proxycommand = g_strdup(ws_optarg);
break;
case OPT_REMOTE_INTERFACE:
g_free(remote_interface);
- remote_interface = g_strdup(optarg);
+ remote_interface = g_strdup(ws_optarg);
break;
case OPT_REMOTE_CAPTURE_COMMAND:
g_free(remote_capture_command);
- remote_capture_command = g_strdup(optarg);
+ remote_capture_command = g_strdup(ws_optarg);
break;
case OPT_REMOTE_SUDO:
@@ -503,12 +503,12 @@ int main(int argc, char *argv[])
case OPT_REMOTE_FILTER:
g_free(remote_filter);
- remote_filter = g_strdup(optarg);
+ remote_filter = g_strdup(ws_optarg);
break;
case OPT_REMOTE_COUNT:
- if (!ws_strtou32(optarg, NULL, &count)) {
- ws_warning("Invalid value for count: %s", optarg);
+ if (!ws_strtou32(ws_optarg, NULL, &count)) {
+ ws_warning("Invalid value for count: %s", ws_optarg);
goto end;
}
break;
@@ -519,12 +519,12 @@ int main(int argc, char *argv[])
case ':':
/* missing option argument */
- ws_warning("Option '%s' requires an argument", argv[optind - 1]);
+ ws_warning("Option '%s' requires an argument", argv[ws_optind - 1]);
break;
default:
- if (!extcap_base_parse_options(extcap_conf, result - EXTCAP_OPT_LIST_INTERFACES, optarg)) {
- ws_warning("Invalid option: %s", argv[optind - 1]);
+ if (!extcap_base_parse_options(extcap_conf, result - EXTCAP_OPT_LIST_INTERFACES, ws_optarg)) {
+ ws_warning("Invalid option: %s", argv[ws_optind - 1]);
goto end;
}
}