forked from osmocom/wireshark
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.pespin/rlcmac
parent
7462e76884
commit
8df2a73594
|
@ -93,29 +93,6 @@ if (NOT WIN32)
|
|||
check_function_exists("clock_gettime" HAVE_CLOCK_GETTIME)
|
||||
endif (NOT WIN32)
|
||||
|
||||
check_function_exists("getopt_long" HAVE_GETOPT_LONG)
|
||||
if(HAVE_GETOPT_LONG)
|
||||
check_include_file("getopt.h" HAVE_GETOPT_H)
|
||||
#
|
||||
# The OS has getopt_long(), so it might have optreset.
|
||||
# Do we have it?
|
||||
#
|
||||
if(HAVE_GETOPT_H)
|
||||
check_symbol_exists("optreset" "getopt.h" HAVE_OPTRESET)
|
||||
else()
|
||||
check_symbol_exists("optreset" HAVE_OPTRESET)
|
||||
endif()
|
||||
else()
|
||||
#
|
||||
# The OS doesn't have getopt_long(), so we're using the GNU libc
|
||||
# version that we have in wsutil. It doesn't have optreset, so we
|
||||
# don't need to check for it.
|
||||
#
|
||||
# However, it uses alloca(), so we may need to include alloca.h;
|
||||
# check for it.
|
||||
#
|
||||
check_include_file("alloca.h" HAVE_ALLOCA_H)
|
||||
endif()
|
||||
check_function_exists("getifaddrs" HAVE_GETIFADDRS)
|
||||
check_function_exists("issetugid" HAVE_ISSETUGID)
|
||||
check_function_exists("setresgid" HAVE_SETRESGID)
|
||||
|
|
19
capinfos.c
19
capinfos.c
|
@ -51,18 +51,7 @@
|
|||
#include <locale.h>
|
||||
#include <errno.h>
|
||||
|
||||
/*
|
||||
* If we have getopt_long() in the system library, include <getopt.h>.
|
||||
* Otherwise, we're using our own getopt_long() (either because the
|
||||
* system has getopt() but not getopt_long(), as with some UN*Xes,
|
||||
* or because it doesn't even have getopt(), as with Windows), so
|
||||
* include our getopt_long()'s header.
|
||||
*/
|
||||
#ifdef HAVE_GETOPT_LONG
|
||||
#include <getopt.h>
|
||||
#else
|
||||
#include <wsutil/wsgetopt.h>
|
||||
#endif
|
||||
#include <wsutil/ws_getopt.h>
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
|
@ -1620,7 +1609,7 @@ main(int argc, char *argv[])
|
|||
wtap_init(TRUE);
|
||||
|
||||
/* Process the options */
|
||||
while ((opt = getopt_long(argc, argv, "abcdehiklmnoqrstuvxyzABCDEFHIKLMNQRST", long_options, NULL)) !=-1) {
|
||||
while ((opt = ws_getopt_long(argc, argv, "abcdehiklmnoqrstuvxyzABCDEFHIKLMNQRST", long_options, NULL)) !=-1) {
|
||||
|
||||
switch (opt) {
|
||||
|
||||
|
@ -1803,7 +1792,7 @@ main(int argc, char *argv[])
|
|||
}
|
||||
}
|
||||
|
||||
if ((argc - optind) < 1) {
|
||||
if ((argc - ws_optind) < 1) {
|
||||
print_usage(stderr);
|
||||
overall_error_status = INVALID_OPTION;
|
||||
goto exit;
|
||||
|
@ -1825,7 +1814,7 @@ main(int argc, char *argv[])
|
|||
|
||||
overall_error_status = 0;
|
||||
|
||||
for (opt = optind; opt < argc; opt++) {
|
||||
for (opt = ws_optind; opt < argc; opt++) {
|
||||
|
||||
(void) g_strlcpy(file_sha256, "<unknown>", HASH_STR_SIZE);
|
||||
(void) g_strlcpy(file_rmd160, "<unknown>", HASH_STR_SIZE);
|
||||
|
|
|
@ -332,7 +332,7 @@ capture_opts_cleanup(capture_options *capture_opts);
|
|||
|
||||
/* set a command line option value */
|
||||
extern int
|
||||
capture_opts_add_opt(capture_options *capture_opts, int opt, const char *optarg);
|
||||
capture_opts_add_opt(capture_options *capture_opts, int opt, const char *ws_optarg);
|
||||
|
||||
/* log content of capture_opts */
|
||||
extern void
|
||||
|
|
15
captype.c
15
captype.c
|
@ -20,18 +20,7 @@
|
|||
#include <locale.h>
|
||||
#include <errno.h>
|
||||
|
||||
/*
|
||||
* If we have getopt_long() in the system library, include <getopt.h>.
|
||||
* Otherwise, we're using our own getopt_long() (either because the
|
||||
* system has getopt() but not getopt_long(), as with some UN*Xes,
|
||||
* or because it doesn't even have getopt(), as with Windows), so
|
||||
* include our getopt_long()'s header.
|
||||
*/
|
||||
#ifdef HAVE_GETOPT_LONG
|
||||
#include <getopt.h>
|
||||
#else
|
||||
#include <wsutil/wsgetopt.h>
|
||||
#endif
|
||||
#include <wsutil/ws_getopt.h>
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
|
@ -157,7 +146,7 @@ main(int argc, char *argv[])
|
|||
wtap_init(TRUE);
|
||||
|
||||
/* Process the options */
|
||||
while ((opt = getopt_long(argc, argv, "hv", long_options, NULL)) !=-1) {
|
||||
while ((opt = ws_getopt_long(argc, argv, "hv", long_options, NULL)) !=-1) {
|
||||
|
||||
switch (opt) {
|
||||
|
||||
|
|
|
@ -67,9 +67,6 @@
|
|||
/* Define if you have the 'getexecname' function. */
|
||||
#cmakedefine HAVE_GETEXECNAME 1
|
||||
|
||||
/* Define to 1 if you have the getopt_long function. */
|
||||
#cmakedefine HAVE_GETOPT_LONG 1
|
||||
|
||||
/* Define to 1 if you have the <grp.h> header file. */
|
||||
#cmakedefine HAVE_GRP_H 1
|
||||
|
||||
|
@ -217,9 +214,6 @@
|
|||
/* Define to 1 if you have the <pwd.h> header file. */
|
||||
#cmakedefine HAVE_PWD_H 1
|
||||
|
||||
/* Define to 1 if you have the optreset variable */
|
||||
#cmakedefine HAVE_OPTRESET 1
|
||||
|
||||
/* Define to 1 if you want to playing SBC by standalone BlueZ SBC library */
|
||||
#cmakedefine HAVE_SBC 1
|
||||
|
||||
|
|
|
@ -351,6 +351,9 @@ libwsutil.so.0 libwsutil0 #MINVER#
|
|||
ws_buffer_remove_start@Base 1.99.0
|
||||
ws_cleanup_sockets@Base 3.1.0
|
||||
ws_cmac_buffer@Base 3.1.0
|
||||
ws_getopt@Base 3.5.1
|
||||
ws_getopt_long@Base 3.5.1
|
||||
ws_getopt_long_only@Base 3.5.1
|
||||
ws_buffer_cleanup@Base 2.3.0
|
||||
ws_hexstrtou16@Base 2.3.0
|
||||
ws_hexstrtou32@Base 2.3.0
|
||||
|
@ -387,6 +390,12 @@ libwsutil.so.0 libwsutil0 #MINVER#
|
|||
ws_logv_full@Base 3.5.0
|
||||
ws_mempbrk_compile@Base 1.99.4
|
||||
ws_mempbrk_exec@Base 1.99.4
|
||||
ws_optarg@Base 3.5.1
|
||||
ws_opterr@Base 3.5.1
|
||||
ws_optind@Base 3.5.1
|
||||
ws_optopt@Base 3.5.1
|
||||
ws_optpos@Base 3.5.1
|
||||
ws_optreset@Base 3.5.1
|
||||
ws_pipe_close@Base 2.6.5
|
||||
ws_pipe_data_available@Base 2.5.0
|
||||
ws_pipe_init@Base 2.5.1
|
||||
|
|
41
dumpcap.c
41
dumpcap.c
|
@ -22,18 +22,7 @@
|
|||
#include <netinet/in.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
* If we have getopt_long() in the system library, include <getopt.h>.
|
||||
* Otherwise, we're using our own getopt_long() (either because the
|
||||
* system has getopt() but not getopt_long(), as with some UN*Xes,
|
||||
* or because it doesn't even have getopt(), as with Windows), so
|
||||
* include our getopt_long()'s header.
|
||||
*/
|
||||
#ifdef HAVE_GETOPT_LONG
|
||||
#include <getopt.h>
|
||||
#else
|
||||
#include <wsutil/wsgetopt.h>
|
||||
#endif
|
||||
#include <wsutil/ws_getopt.h>
|
||||
|
||||
#if defined(__APPLE__) && defined(__LP64__)
|
||||
#include <sys/utsname.h>
|
||||
|
@ -5126,7 +5115,7 @@ main(int argc, char *argv[])
|
|||
global_capture_opts.capture_child = capture_child;
|
||||
|
||||
/* Now get our args */
|
||||
while ((opt = getopt_long(argc, argv, OPTSTRING, long_options, NULL)) != -1) {
|
||||
while ((opt = ws_getopt_long(argc, argv, OPTSTRING, long_options, NULL)) != -1) {
|
||||
switch (opt) {
|
||||
case 'h': /* Print help and exit */
|
||||
show_help_header("Capture network packets and dump them into a pcapng or pcap file.");
|
||||
|
@ -5166,7 +5155,7 @@ main(int argc, char *argv[])
|
|||
case 'I': /* Monitor mode */
|
||||
#endif
|
||||
case LONGOPT_COMPRESS_TYPE: /* compress type */
|
||||
status = capture_opts_add_opt(&global_capture_opts, opt, optarg);
|
||||
status = capture_opts_add_opt(&global_capture_opts, opt, ws_optarg);
|
||||
if (status != 0) {
|
||||
exit_main(status);
|
||||
}
|
||||
|
@ -5177,7 +5166,7 @@ main(int argc, char *argv[])
|
|||
interface_options *interface_opts;
|
||||
|
||||
interface_opts = &g_array_index(global_capture_opts.ifaces, interface_options, global_capture_opts.ifaces->len - 1);
|
||||
interface_opts->ifname = g_strdup(optarg);
|
||||
interface_opts->ifname = g_strdup(ws_optarg);
|
||||
} else {
|
||||
cmdarg_err("--ifname must be specified after a -i option");
|
||||
exit_main(1);
|
||||
|
@ -5188,7 +5177,7 @@ main(int argc, char *argv[])
|
|||
interface_options *interface_opts;
|
||||
|
||||
interface_opts = &g_array_index(global_capture_opts.ifaces, interface_options, global_capture_opts.ifaces->len - 1);
|
||||
interface_opts->descr = g_strdup(optarg);
|
||||
interface_opts->descr = g_strdup(ws_optarg);
|
||||
} else {
|
||||
cmdarg_err("--ifdescr must be specified after a -i option");
|
||||
exit_main(1);
|
||||
|
@ -5198,7 +5187,7 @@ main(int argc, char *argv[])
|
|||
if (capture_comments == NULL) {
|
||||
capture_comments = g_ptr_array_new_with_free_func(g_free);
|
||||
}
|
||||
g_ptr_array_add(capture_comments, g_strdup(optarg));
|
||||
g_ptr_array_add(capture_comments, g_strdup(ws_optarg));
|
||||
break;
|
||||
case 'Z':
|
||||
capture_child = TRUE;
|
||||
|
@ -5206,11 +5195,11 @@ main(int argc, char *argv[])
|
|||
/* set output pipe to binary mode, to avoid ugly text conversions */
|
||||
_setmode(2, O_BINARY);
|
||||
/*
|
||||
* optarg = the control ID, aka the PPID, currently used for the
|
||||
* ws_optarg = the control ID, aka the PPID, currently used for the
|
||||
* signal pipe name.
|
||||
*/
|
||||
if (strcmp(optarg, SIGNAL_PIPE_CTRL_ID_NONE) != 0) {
|
||||
sig_pipe_name = g_strdup_printf(SIGNAL_PIPE_FORMAT, optarg);
|
||||
if (strcmp(ws_optarg, SIGNAL_PIPE_CTRL_ID_NONE) != 0) {
|
||||
sig_pipe_name = g_strdup_printf(SIGNAL_PIPE_FORMAT, ws_optarg);
|
||||
sig_pipe_handle = CreateFile(utf_8to16(sig_pipe_name),
|
||||
GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
|
||||
|
||||
|
@ -5260,7 +5249,7 @@ main(int argc, char *argv[])
|
|||
case 'k': /* Set wireless channel */
|
||||
if (!set_chan) {
|
||||
set_chan = TRUE;
|
||||
set_chan_arg = optarg;
|
||||
set_chan_arg = ws_optarg;
|
||||
run_once_args++;
|
||||
} else {
|
||||
cmdarg_err("Only one -k flag may be specified");
|
||||
|
@ -5271,13 +5260,13 @@ main(int argc, char *argv[])
|
|||
machine_readable = TRUE;
|
||||
break;
|
||||
case 'C':
|
||||
pcap_queue_byte_limit = get_positive_int(optarg, "byte_limit");
|
||||
pcap_queue_byte_limit = get_positive_int(ws_optarg, "byte_limit");
|
||||
break;
|
||||
case 'N':
|
||||
pcap_queue_packet_limit = get_positive_int(optarg, "packet_limit");
|
||||
pcap_queue_packet_limit = get_positive_int(ws_optarg, "packet_limit");
|
||||
break;
|
||||
default:
|
||||
cmdarg_err("Invalid Option: %s", argv[optind-1]);
|
||||
cmdarg_err("Invalid Option: %s", argv[ws_optind-1]);
|
||||
/* FALLTHROUGH */
|
||||
case '?': /* Bad flag - print usage message */
|
||||
arg_error = TRUE;
|
||||
|
@ -5285,8 +5274,8 @@ main(int argc, char *argv[])
|
|||
}
|
||||
}
|
||||
if (!arg_error) {
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
argc -= ws_optind;
|
||||
argv += ws_optind;
|
||||
if (argc >= 1) {
|
||||
/* user specified file name as regular command-line argument */
|
||||
/* XXX - use it as the capture file name (or something else)? */
|
||||
|
|
101
editcap.c
101
editcap.c
|
@ -40,18 +40,7 @@
|
|||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
* If we have getopt_long() in the system library, include <getopt.h>.
|
||||
* Otherwise, we're using our own getopt_long() (either because the
|
||||
* system has getopt() but not getopt_long(), as with some UN*Xes,
|
||||
* or because it doesn't even have getopt(), as with Windows), so
|
||||
* include our getopt_long()'s header.
|
||||
*/
|
||||
#ifdef HAVE_GETOPT_LONG
|
||||
#include <getopt.h>
|
||||
#else
|
||||
#include <wsutil/wsgetopt.h>
|
||||
#endif
|
||||
#include <wsutil/ws_getopt.h>
|
||||
|
||||
#include <wiretap/secrets-types.h>
|
||||
#include <wiretap/wtap.h>
|
||||
|
@ -1240,7 +1229,7 @@ main(int argc, char *argv[])
|
|||
wtap_init(TRUE);
|
||||
|
||||
/* Process the options */
|
||||
while ((opt = getopt_long(argc, argv, ":a:A:B:c:C:dD:E:F:hi:I:Lo:rs:S:t:T:vVw:", long_options, NULL)) != -1) {
|
||||
while ((opt = ws_getopt_long(argc, argv, ":a:A:B:c:C:dD:E:F:hi:I:Lo:rs:S:t:T:vVw:", long_options, NULL)) != -1) {
|
||||
switch (opt) {
|
||||
case LONGOPT_NO_VLAN:
|
||||
{
|
||||
|
@ -1256,9 +1245,9 @@ main(int argc, char *argv[])
|
|||
|
||||
case LONGOPT_SEED:
|
||||
{
|
||||
if (sscanf(optarg, "%u", &seed) != 1) {
|
||||
if (sscanf(ws_optarg, "%u", &seed) != 1) {
|
||||
fprintf(stderr, "editcap: \"%s\" isn't a valid seed\n\n",
|
||||
optarg);
|
||||
ws_optarg);
|
||||
ret = INVALID_OPTION;
|
||||
goto clean_exit;
|
||||
}
|
||||
|
@ -1270,11 +1259,11 @@ main(int argc, char *argv[])
|
|||
{
|
||||
guint32 secrets_type_id = 0;
|
||||
const char *secrets_filename = NULL;
|
||||
if (strcmp("help", optarg) == 0) {
|
||||
if (strcmp("help", ws_optarg) == 0) {
|
||||
list_secrets_types(stdout);
|
||||
goto clean_exit;
|
||||
}
|
||||
gchar **splitted = g_strsplit(optarg, ",", 2);
|
||||
gchar **splitted = g_strsplit(ws_optarg, ",", 2);
|
||||
if (splitted[0] && splitted[0][0] != '\0') {
|
||||
secrets_type_id = lookup_secrets_type(splitted[0]);
|
||||
if (secrets_type_id == 0) {
|
||||
|
@ -1313,7 +1302,7 @@ main(int argc, char *argv[])
|
|||
if (!capture_comments) {
|
||||
capture_comments = g_ptr_array_new_with_free_func(g_free);
|
||||
}
|
||||
g_ptr_array_add(capture_comments, g_strdup(optarg));
|
||||
g_ptr_array_add(capture_comments, g_strdup(ws_optarg));
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -1328,9 +1317,9 @@ main(int argc, char *argv[])
|
|||
guint frame_number;
|
||||
gint string_start_index = 0;
|
||||
|
||||
if ((sscanf(optarg, "%u:%n", &frame_number, &string_start_index) < 1) || (string_start_index == 0)) {
|
||||
if ((sscanf(ws_optarg, "%u:%n", &frame_number, &string_start_index) < 1) || (string_start_index == 0)) {
|
||||
fprintf(stderr, "editcap: \"%s\" isn't a valid <frame>:<comment>\n\n",
|
||||
optarg);
|
||||
ws_optarg);
|
||||
ret = INVALID_OPTION;
|
||||
goto clean_exit;
|
||||
}
|
||||
|
@ -1341,7 +1330,7 @@ main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
/* Insert this entry (framenum -> comment) */
|
||||
g_tree_replace(frames_user_comments, GUINT_TO_POINTER(frame_number), g_strdup(optarg+string_start_index));
|
||||
g_tree_replace(frames_user_comments, GUINT_TO_POINTER(frame_number), g_strdup(ws_optarg+string_start_index));
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -1351,7 +1340,7 @@ main(int argc, char *argv[])
|
|||
nstime_t in_time;
|
||||
|
||||
check_startstop = TRUE;
|
||||
if ((0 < iso8601_to_nstime(&in_time, optarg)) || (0 < unix_epoch_to_nstime(&in_time, optarg))) {
|
||||
if ((0 < iso8601_to_nstime(&in_time, ws_optarg)) || (0 < unix_epoch_to_nstime(&in_time, ws_optarg))) {
|
||||
if (opt == 'A') {
|
||||
nstime_copy(&starttime, &in_time);
|
||||
have_starttime = TRUE;
|
||||
|
@ -1363,21 +1352,21 @@ main(int argc, char *argv[])
|
|||
}
|
||||
else {
|
||||
fprintf(stderr, "editcap: \"%s\" isn't a valid date and time\n\n",
|
||||
optarg);
|
||||
ws_optarg);
|
||||
ret = INVALID_OPTION;
|
||||
goto clean_exit;
|
||||
}
|
||||
}
|
||||
|
||||
case 'c':
|
||||
split_packet_count = get_nonzero_guint32(optarg, "packet count");
|
||||
split_packet_count = get_nonzero_guint32(ws_optarg, "packet count");
|
||||
break;
|
||||
|
||||
case 'C':
|
||||
{
|
||||
int choplen = 0, chopoff = 0;
|
||||
|
||||
switch (sscanf(optarg, "%d:%d", &chopoff, &choplen)) {
|
||||
switch (sscanf(ws_optarg, "%d:%d", &chopoff, &choplen)) {
|
||||
case 1: /* only the chop length was specififed */
|
||||
choplen = chopoff;
|
||||
chopoff = 0;
|
||||
|
@ -1388,7 +1377,7 @@ main(int argc, char *argv[])
|
|||
|
||||
default:
|
||||
fprintf(stderr, "editcap: \"%s\" isn't a valid chop length or offset:length\n",
|
||||
optarg);
|
||||
ws_optarg);
|
||||
ret = INVALID_OPTION;
|
||||
goto clean_exit;
|
||||
break;
|
||||
|
@ -1419,7 +1408,7 @@ main(int argc, char *argv[])
|
|||
case 'D':
|
||||
dup_detect = TRUE;
|
||||
dup_detect_by_time = FALSE;
|
||||
dup_window = get_guint32(optarg, "duplicate window");
|
||||
dup_window = get_guint32(ws_optarg, "duplicate window");
|
||||
if (dup_window > MAX_DUP_DEPTH) {
|
||||
fprintf(stderr, "editcap: \"%d\" duplicate window value must be between 0 and %d inclusive.\n",
|
||||
dup_window, MAX_DUP_DEPTH);
|
||||
|
@ -1429,20 +1418,20 @@ main(int argc, char *argv[])
|
|||
break;
|
||||
|
||||
case 'E':
|
||||
err_prob = g_ascii_strtod(optarg, &p);
|
||||
if (p == optarg || err_prob < 0.0 || err_prob > 1.0) {
|
||||
err_prob = g_ascii_strtod(ws_optarg, &p);
|
||||
if (p == ws_optarg || err_prob < 0.0 || err_prob > 1.0) {
|
||||
fprintf(stderr, "editcap: probability \"%s\" must be between 0.0 and 1.0\n",
|
||||
optarg);
|
||||
ws_optarg);
|
||||
ret = INVALID_OPTION;
|
||||
goto clean_exit;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'F':
|
||||
out_file_type_subtype = wtap_name_to_file_type_subtype(optarg);
|
||||
out_file_type_subtype = wtap_name_to_file_type_subtype(ws_optarg);
|
||||
if (out_file_type_subtype < 0) {
|
||||
fprintf(stderr, "editcap: \"%s\" isn't a valid capture file type\n\n",
|
||||
optarg);
|
||||
ws_optarg);
|
||||
list_capture_types(stderr);
|
||||
ret = INVALID_OPTION;
|
||||
goto clean_exit;
|
||||
|
@ -1457,7 +1446,7 @@ main(int argc, char *argv[])
|
|||
|
||||
case 'i': /* break capture file based on time interval */
|
||||
{
|
||||
double spb = get_positive_double(optarg, "time interval");
|
||||
double spb = get_positive_double(ws_optarg, "time interval");
|
||||
if (spb == 0.0) {
|
||||
cmdarg_err("The specified interval is zero");
|
||||
ret = INVALID_OPTION;
|
||||
|
@ -1472,7 +1461,7 @@ main(int argc, char *argv[])
|
|||
break;
|
||||
|
||||
case 'I': /* ignored_bytes at the beginning of the frame for duplications removal */
|
||||
ignored_bytes = get_guint32(optarg, "number of bytes to ignore");
|
||||
ignored_bytes = get_guint32(ws_optarg, "number of bytes to ignore");
|
||||
break;
|
||||
|
||||
case 'L':
|
||||
|
@ -1480,7 +1469,7 @@ main(int argc, char *argv[])
|
|||
break;
|
||||
|
||||
case 'o':
|
||||
change_offset = get_guint32(optarg, "change offset");
|
||||
change_offset = get_guint32(ws_optarg, "change offset");
|
||||
break;
|
||||
|
||||
case 'r':
|
||||
|
@ -1493,11 +1482,11 @@ main(int argc, char *argv[])
|
|||
break;
|
||||
|
||||
case 's':
|
||||
snaplen = get_nonzero_guint32(optarg, "snapshot length");
|
||||
snaplen = get_nonzero_guint32(ws_optarg, "snapshot length");
|
||||
break;
|
||||
|
||||
case 'S':
|
||||
if (!set_strict_time_adj(optarg)) {
|
||||
if (!set_strict_time_adj(ws_optarg)) {
|
||||
ret = INVALID_OPTION;
|
||||
goto clean_exit;
|
||||
}
|
||||
|
@ -1505,17 +1494,17 @@ main(int argc, char *argv[])
|
|||
break;
|
||||
|
||||
case 't':
|
||||
if (!set_time_adjustment(optarg)) {
|
||||
if (!set_time_adjustment(ws_optarg)) {
|
||||
ret = INVALID_OPTION;
|
||||
goto clean_exit;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'T':
|
||||
out_frame_type = wtap_name_to_encap(optarg);
|
||||
out_frame_type = wtap_name_to_encap(ws_optarg);
|
||||
if (out_frame_type < 0) {
|
||||
fprintf(stderr, "editcap: \"%s\" isn't a valid encapsulation type\n\n",
|
||||
optarg);
|
||||
ws_optarg);
|
||||
list_encap_types(stderr);
|
||||
ret = INVALID_OPTION;
|
||||
goto clean_exit;
|
||||
|
@ -1540,7 +1529,7 @@ main(int argc, char *argv[])
|
|||
dup_detect = FALSE;
|
||||
dup_detect_by_time = TRUE;
|
||||
dup_window = MAX_DUP_DEPTH;
|
||||
if (!set_rel_time(optarg)) {
|
||||
if (!set_rel_time(ws_optarg)) {
|
||||
ret = INVALID_OPTION;
|
||||
goto clean_exit;
|
||||
}
|
||||
|
@ -1548,7 +1537,7 @@ main(int argc, char *argv[])
|
|||
|
||||
case '?': /* Bad options if GNU getopt */
|
||||
case ':': /* missing option argument */
|
||||
switch(optopt) {
|
||||
switch(ws_optopt) {
|
||||
case'F':
|
||||
list_capture_types(stdout);
|
||||
break;
|
||||
|
@ -1557,9 +1546,9 @@ main(int argc, char *argv[])
|
|||
break;
|
||||
default:
|
||||
if (opt == '?') {
|
||||
fprintf(stderr, "editcap: invalid option -- '%c'\n", optopt);
|
||||
fprintf(stderr, "editcap: invalid option -- '%c'\n", ws_optopt);
|
||||
} else {
|
||||
fprintf(stderr, "editcap: option requires an argument -- '%c'\n", optopt);
|
||||
fprintf(stderr, "editcap: option requires an argument -- '%c'\n", ws_optopt);
|
||||
}
|
||||
print_usage(stderr);
|
||||
ret = INVALID_OPTION;
|
||||
|
@ -1571,10 +1560,10 @@ main(int argc, char *argv[])
|
|||
} /* processing commmand-line options */
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "Optind = %i, argc = %i\n", optind, argc);
|
||||
fprintf(stderr, "Optind = %i, argc = %i\n", ws_optind, argc);
|
||||
#endif
|
||||
|
||||
if ((argc - optind) < 2) {
|
||||
if ((argc - ws_optind) < 2) {
|
||||
print_usage(stderr);
|
||||
ret = INVALID_OPTION;
|
||||
goto clean_exit;
|
||||
|
@ -1609,16 +1598,16 @@ main(int argc, char *argv[])
|
|||
goto clean_exit;
|
||||
}
|
||||
|
||||
wth = wtap_open_offline(argv[optind], WTAP_TYPE_AUTO, &read_err, &read_err_info, FALSE);
|
||||
wth = wtap_open_offline(argv[ws_optind], WTAP_TYPE_AUTO, &read_err, &read_err_info, FALSE);
|
||||
|
||||
if (!wth) {
|
||||
cfile_open_failure_message(argv[optind], read_err, read_err_info);
|
||||
cfile_open_failure_message(argv[ws_optind], read_err, read_err_info);
|
||||
ret = INVALID_FILE;
|
||||
goto clean_exit;
|
||||
}
|
||||
|
||||
if (verbose) {
|
||||
fprintf(stderr, "File %s is a %s capture file.\n", argv[optind],
|
||||
fprintf(stderr, "File %s is a %s capture file.\n", argv[ws_optind],
|
||||
wtap_file_type_subtype_description(wtap_file_type_subtype(wth)));
|
||||
}
|
||||
|
||||
|
@ -1740,7 +1729,7 @@ main(int argc, char *argv[])
|
|||
* Now process the arguments following the input and output file
|
||||
* names, if any; they specify packets to include/exclude.
|
||||
*/
|
||||
for (i = optind + 2; i < argc; i++)
|
||||
for (i = ws_optind + 2; i < argc; i++)
|
||||
if (add_selection(argv[i], &max_packet_number) == FALSE)
|
||||
break;
|
||||
|
||||
|
@ -1778,14 +1767,14 @@ main(int argc, char *argv[])
|
|||
/* Extra actions for the first packet */
|
||||
if (read_count == 1) {
|
||||
if (split_packet_count != 0 || !nstime_is_unset(&secs_per_block)) {
|
||||
if (!fileset_extract_prefix_suffix(argv[optind+1], &fprefix, &fsuffix)) {
|
||||
if (!fileset_extract_prefix_suffix(argv[ws_optind+1], &fprefix, &fsuffix)) {
|
||||
ret = CANT_EXTRACT_PREFIX;
|
||||
goto clean_exit;
|
||||
}
|
||||
|
||||
filename = fileset_get_filename_by_pattern(block_cnt++, rec, fprefix, fsuffix);
|
||||
} else {
|
||||
filename = g_strdup(argv[optind+1]);
|
||||
filename = g_strdup(argv[ws_optind+1]);
|
||||
}
|
||||
ws_assert(filename);
|
||||
|
||||
|
@ -1810,7 +1799,7 @@ main(int argc, char *argv[])
|
|||
* Process whatever IDBs we haven't seen yet.
|
||||
*/
|
||||
if (!process_new_idbs(wth, pdh, idbs_seen, &write_err, &write_err_info)) {
|
||||
cfile_write_failure_message(argv[optind], filename,
|
||||
cfile_write_failure_message(argv[ws_optind], filename,
|
||||
write_err, write_err_info,
|
||||
read_count,
|
||||
out_file_type_subtype);
|
||||
|
@ -2255,7 +2244,7 @@ main(int argc, char *argv[])
|
|||
|
||||
/* Attempt to dump out current frame to the output file */
|
||||
if (!wtap_dump(pdh, rec, buf, &write_err, &write_err_info)) {
|
||||
cfile_write_failure_message(argv[optind], filename,
|
||||
cfile_write_failure_message(argv[ws_optind], filename,
|
||||
write_err, write_err_info,
|
||||
read_count,
|
||||
out_file_type_subtype);
|
||||
|
@ -2276,14 +2265,14 @@ main(int argc, char *argv[])
|
|||
if (read_err != 0) {
|
||||
/* Print a message noting that the read failed somewhere along the
|
||||
* line. */
|
||||
cfile_read_failure_message(argv[optind], read_err, read_err_info);
|
||||
cfile_read_failure_message(argv[ws_optind], read_err, read_err_info);
|
||||
}
|
||||
|
||||
if (!pdh) {
|
||||
/* No valid packages found, open the outfile so we can write an
|
||||
* empty header */
|
||||
g_free (filename);
|
||||
filename = g_strdup(argv[optind+1]);
|
||||
filename = g_strdup(argv[ws_optind+1]);
|
||||
|
||||
pdh = editcap_dump_open(filename, ¶ms, idbs_seen, &write_err,
|
||||
&write_err_info);
|
||||
|
|
|
@ -19,13 +19,13 @@
|
|||
|
||||
static GHashTable* ex_opts = NULL;
|
||||
|
||||
gboolean ex_opt_add(const gchar* optarg) {
|
||||
gboolean ex_opt_add(const gchar* ws_optarg) {
|
||||
gchar** splitted;
|
||||
|
||||
if (!ex_opts)
|
||||
ex_opts = g_hash_table_new(g_str_hash,g_str_equal);
|
||||
|
||||
splitted = g_strsplit(optarg,":",2);
|
||||
splitted = g_strsplit(ws_optarg,":",2);
|
||||
|
||||
if (splitted[0] && splitted[1]) {
|
||||
GPtrArray* this_opts = (GPtrArray *)g_hash_table_lookup(ex_opts,splitted[0]);
|
||||
|
|
|
@ -22,7 +22,7 @@ extern "C" {
|
|||
#endif /* __cplusplus */
|
||||
|
||||
/* will be called by main each time a -X option is found */
|
||||
WS_DLL_PUBLIC gboolean ex_opt_add(const gchar* optarg);
|
||||
WS_DLL_PUBLIC gboolean ex_opt_add(const gchar* ws_optarg);
|
||||
|
||||
/* yields the number of arguments of a given key obviously returns 0 if there aren't */
|
||||
WS_DLL_PUBLIC gint ex_opt_count(const gchar* key);
|
||||
|
|
|
@ -189,9 +189,9 @@ WS_DLL_PUBLIC void stats_tree_reinit(void *p_st);
|
|||
/* callback for destoy */
|
||||
WS_DLL_PUBLIC void stats_tree_free(stats_tree *st);
|
||||
|
||||
/** given an optarg splits the abbr part
|
||||
/** given an ws_optarg splits the abbr part
|
||||
and returns a newly allocated buffer containing it */
|
||||
WS_DLL_PUBLIC gchar *stats_tree_get_abbr(const gchar *optarg);
|
||||
WS_DLL_PUBLIC gchar *stats_tree_get_abbr(const gchar *ws_optarg);
|
||||
|
||||
/** obtains a stats tree from the registry given its abbr */
|
||||
WS_DLL_PUBLIC stats_tree_cfg *stats_tree_get_cfg_by_abbr(const char *abbr);
|
||||
|
|
|
@ -2598,8 +2598,8 @@ int main(int argc, char *argv[]) {
|
|||
extcap_help_add_option(extcap_conf, "--bt-local-ip <IP>", "the bluetooth local IP");
|
||||
extcap_help_add_option(extcap_conf, "--bt-local-tcp-port <port>", "the bluetooth local TCP port");
|
||||
|
||||
opterr = 0;
|
||||
optind = 0;
|
||||
ws_opterr = 0;
|
||||
ws_optind = 0;
|
||||
|
||||
if (argc == 1) {
|
||||
extcap_help_print(extcap_conf);
|
||||
|
@ -2607,7 +2607,7 @@ int main(int argc, char *argv[]) {
|
|||
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) {
|
||||
|
||||
case OPT_VERSION:
|
||||
|
@ -2619,77 +2619,77 @@ int main(int argc, char *argv[]) {
|
|||
ret = EXIT_CODE_SUCCESS;
|
||||
goto end;
|
||||
case OPT_CONFIG_ADB_SERVER_IP:
|
||||
adb_server_ip = optarg;
|
||||
adb_server_ip = ws_optarg;
|
||||
break;
|
||||
case OPT_CONFIG_ADB_SERVER_TCP_PORT:
|
||||
adb_server_tcp_port = &local_adb_server_tcp_port;
|
||||
if (!optarg){
|
||||
if (!ws_optarg){
|
||||
ws_warning("Impossible exception. Parameter required argument, but there is no it right now.");
|
||||
goto end;
|
||||
}
|
||||
if (!ws_strtou16(optarg, NULL, adb_server_tcp_port)) {
|
||||
ws_warning("Invalid adb server TCP port: %s", optarg);
|
||||
if (!ws_strtou16(ws_optarg, NULL, adb_server_tcp_port)) {
|
||||
ws_warning("Invalid adb server TCP port: %s", ws_optarg);
|
||||
goto end;
|
||||
}
|
||||
break;
|
||||
case OPT_CONFIG_LOGCAT_TEXT:
|
||||
if (optarg && !*optarg)
|
||||
if (ws_optarg && !*ws_optarg)
|
||||
logcat_text = TRUE;
|
||||
else
|
||||
logcat_text = (g_ascii_strncasecmp(optarg, "TRUE", 4) == 0);
|
||||
logcat_text = (g_ascii_strncasecmp(ws_optarg, "TRUE", 4) == 0);
|
||||
break;
|
||||
case OPT_CONFIG_LOGCAT_IGNORE_LOG_BUFFER:
|
||||
if (optarg == NULL || (optarg && !*optarg))
|
||||
if (ws_optarg == NULL || (ws_optarg && !*ws_optarg))
|
||||
logcat_ignore_log_buffer = TRUE;
|
||||
else
|
||||
logcat_ignore_log_buffer = (g_ascii_strncasecmp(optarg, "TRUE", 4) == 0);
|
||||
logcat_ignore_log_buffer = (g_ascii_strncasecmp(ws_optarg, "TRUE", 4) == 0);
|
||||
break;
|
||||
case OPT_CONFIG_LOGCAT_CUSTOM_OPTIONS:
|
||||
if (optarg == NULL || (optarg && *optarg == '\0')) {
|
||||
if (ws_optarg == NULL || (ws_optarg && *ws_optarg == '\0')) {
|
||||
logcat_custom_parameter = NULL;
|
||||
break;
|
||||
}
|
||||
|
||||
if (g_regex_match_simple("(^|\\s)-[bBcDfgLnpPrv]", optarg, G_REGEX_RAW, (GRegexMatchFlags)0)) {
|
||||
if (g_regex_match_simple("(^|\\s)-[bBcDfgLnpPrv]", ws_optarg, G_REGEX_RAW, (GRegexMatchFlags)0)) {
|
||||
ws_error("Found prohibited option in logcat-custom-options");
|
||||
return EXIT_CODE_GENERIC;
|
||||
}
|
||||
|
||||
logcat_custom_parameter = optarg;
|
||||
logcat_custom_parameter = ws_optarg;
|
||||
|
||||
break;
|
||||
case OPT_CONFIG_BT_SERVER_TCP_PORT:
|
||||
bt_server_tcp_port = &local_bt_server_tcp_port;
|
||||
if (!optarg){
|
||||
if (!ws_optarg){
|
||||
ws_warning("Impossible exception. Parameter required argument, but there is no it right now.");
|
||||
goto end;
|
||||
}
|
||||
if (!ws_strtou16(optarg, NULL, bt_server_tcp_port)) {
|
||||
ws_warning("Invalid bluetooth server TCP port: %s", optarg);
|
||||
if (!ws_strtou16(ws_optarg, NULL, bt_server_tcp_port)) {
|
||||
ws_warning("Invalid bluetooth server TCP port: %s", ws_optarg);
|
||||
goto end;
|
||||
}
|
||||
break;
|
||||
case OPT_CONFIG_BT_FORWARD_SOCKET:
|
||||
bt_forward_socket = (g_ascii_strncasecmp(optarg, "TRUE", 4) == 0);
|
||||
bt_forward_socket = (g_ascii_strncasecmp(ws_optarg, "TRUE", 4) == 0);
|
||||
break;
|
||||
case OPT_CONFIG_BT_LOCAL_IP:
|
||||
bt_local_ip = optarg;
|
||||
bt_local_ip = ws_optarg;
|
||||
break;
|
||||
case OPT_CONFIG_BT_LOCAL_TCP_PORT:
|
||||
bt_local_tcp_port = &local_bt_local_tcp_port;
|
||||
if (!optarg){
|
||||
if (!ws_optarg){
|
||||
ws_warning("Impossible exception. Parameter required argument, but there is no it right now.");
|
||||
goto end;
|
||||
}
|
||||
if (!ws_strtou16(optarg, NULL, bt_local_tcp_port)) {
|
||||
ws_warning("Invalid bluetooth local tcp port: %s", optarg);
|
||||
if (!ws_strtou16(ws_optarg, NULL, bt_local_tcp_port)) {
|
||||
ws_warning("Invalid bluetooth local tcp port: %s", ws_optarg);
|
||||
goto end;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (!extcap_base_parse_options(extcap_conf, result - EXTCAP_OPT_LIST_INTERFACES, optarg))
|
||||
if (!extcap_base_parse_options(extcap_conf, result - EXTCAP_OPT_LIST_INTERFACES, ws_optarg))
|
||||
{
|
||||
ws_warning("Invalid argument <%s>. Try --help.\n", argv[optind - 1]);
|
||||
ws_warning("Invalid argument <%s>. Try --help.\n", argv[ws_optind - 1]);
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -588,15 +588,15 @@ int main(int argc, char *argv[])
|
|||
extcap_help_add_option(extcap_conf, "--remote-filter <filter>", "a filter for remote capture "
|
||||
"(default: don't capture data for lal interfaces IPs)");
|
||||
|
||||
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) {
|
||||
|
||||
|
@ -611,68 +611,68 @@ 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_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 packet count: %s", optarg);
|
||||
if (!ws_strtou32(ws_optarg, NULL, &count)) {
|
||||
ws_warning("Invalid packet count: %s", ws_optarg);
|
||||
goto end;
|
||||
}
|
||||
break;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -680,8 +680,8 @@ int main(int argc, char *argv[])
|
|||
|
||||
extcap_cmdline_debug(argv, argc);
|
||||
|
||||
if (optind != argc) {
|
||||
ws_warning("Unexpected extra option: %s", argv[optind]);
|
||||
if (ws_optind != argc) {
|
||||
ws_warning("Unexpected extra option: %s", argv[ws_optind]);
|
||||
goto end;
|
||||
}
|
||||
|
||||
|
|
|
@ -530,15 +530,15 @@ int main(int argc, char *argv[])
|
|||
extcap_help_add_option(extcap_conf, "--version", "print the version");
|
||||
extcap_help_add_option(extcap_conf, "--port <port> ", "the dpauxmon interface index");
|
||||
|
||||
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) {
|
||||
|
||||
case OPT_HELP:
|
||||
|
@ -551,20 +551,20 @@ int main(int argc, char *argv[])
|
|||
goto end;
|
||||
|
||||
case OPT_INTERFACE_ID:
|
||||
if (!ws_strtou32(optarg, NULL, &interface_id)) {
|
||||
ws_warning("Invalid interface id: %s", optarg);
|
||||
if (!ws_strtou32(ws_optarg, NULL, &interface_id)) {
|
||||
ws_warning("Invalid interface id: %s", ws_optarg);
|
||||
goto end;
|
||||
}
|
||||
break;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -572,8 +572,8 @@ int main(int argc, char *argv[])
|
|||
|
||||
extcap_cmdline_debug(argv, argc);
|
||||
|
||||
if (optind != argc) {
|
||||
ws_warning("Unexpected extra option: %s", argv[optind]);
|
||||
if (ws_optind != argc) {
|
||||
ws_warning("Unexpected extra option: %s", argv[ws_optind]);
|
||||
goto end;
|
||||
}
|
||||
|
||||
|
|
22
extcap/etl.c
22
extcap/etl.c
|
@ -17,7 +17,7 @@
|
|||
|
||||
#include "config.h"
|
||||
#include "etl.h"
|
||||
#include "wsutil/wsgetopt.h"
|
||||
#include "wsutil/ws_getopt.h"
|
||||
#include "wsutil/strtoi.h"
|
||||
#include "etw_message.h"
|
||||
|
||||
|
@ -179,11 +179,11 @@ wtap_open_return_val etw_dump(const char* etl_filename, const char* pcapng_filen
|
|||
params_array_num++;
|
||||
}
|
||||
|
||||
optind = 0;
|
||||
while ((opt_result = getopt_long(params_array_num, params_array, ":", longopts, &option_idx)) != -1) {
|
||||
ws_optind = 0;
|
||||
while ((opt_result = ws_getopt_long(params_array_num, params_array, ":", longopts, &option_idx)) != -1) {
|
||||
switch (opt_result) {
|
||||
case OPT_PROVIDER:
|
||||
mbstowcs(provider_id, optarg, FILENAME_MAX);
|
||||
mbstowcs(provider_id, ws_optarg, FILENAME_MAX);
|
||||
if (UuidFromString(provider_id, &g_provider_filters[provider_idx].ProviderId) == RPC_S_INVALID_STRING_UUID)
|
||||
{
|
||||
PEVT_VARIANT value = NULL;
|
||||
|
@ -209,7 +209,7 @@ wtap_open_return_val etw_dump(const char* etl_filename, const char* pcapng_filen
|
|||
}
|
||||
else
|
||||
{
|
||||
*err_info = g_strdup_printf("Cannot convert provider %s to a GUID, err is 0x%x", optarg, *err);
|
||||
*err_info = g_strdup_printf("Cannot convert provider %s to a GUID, err is 0x%x", ws_optarg, *err);
|
||||
return WTAP_OPEN_ERROR;
|
||||
}
|
||||
|
||||
|
@ -219,7 +219,7 @@ wtap_open_return_val etw_dump(const char* etl_filename, const char* pcapng_filen
|
|||
if (IsEqualGUID(&g_provider_filters[0].ProviderId, &ZeroGuid))
|
||||
{
|
||||
*err = ERROR_INVALID_PARAMETER;
|
||||
*err_info = g_strdup_printf("Provider %s is zero, err is 0x%x", optarg, *err);
|
||||
*err_info = g_strdup_printf("Provider %s is zero, err is 0x%x", ws_optarg, *err);
|
||||
return WTAP_OPEN_ERROR;
|
||||
}
|
||||
provider_idx++;
|
||||
|
@ -232,11 +232,11 @@ wtap_open_return_val etw_dump(const char* etl_filename, const char* pcapng_filen
|
|||
return WTAP_OPEN_ERROR;
|
||||
}
|
||||
|
||||
g_provider_filters[provider_idx - 1].Keyword = _strtoui64(optarg, NULL, 0);
|
||||
g_provider_filters[provider_idx - 1].Keyword = _strtoui64(ws_optarg, NULL, 0);
|
||||
if (!g_provider_filters[provider_idx - 1].Keyword)
|
||||
{
|
||||
*err = ERROR_INVALID_PARAMETER;
|
||||
*err_info = g_strdup_printf("Keyword %s cannot be converted, err is 0x%x", optarg, *err);
|
||||
*err_info = g_strdup_printf("Keyword %s cannot be converted, err is 0x%x", ws_optarg, *err);
|
||||
return WTAP_OPEN_ERROR;
|
||||
}
|
||||
break;
|
||||
|
@ -248,17 +248,17 @@ wtap_open_return_val etw_dump(const char* etl_filename, const char* pcapng_filen
|
|||
return WTAP_OPEN_ERROR;
|
||||
}
|
||||
|
||||
convert_level = strtoul(optarg, NULL, 0);
|
||||
convert_level = strtoul(ws_optarg, NULL, 0);
|
||||
if (convert_level > UCHAR_MAX)
|
||||
{
|
||||
*err = ERROR_INVALID_PARAMETER;
|
||||
*err_info = g_strdup_printf("Level %s is bigger than 0xff, err is 0x%x", optarg, *err);
|
||||
*err_info = g_strdup_printf("Level %s is bigger than 0xff, err is 0x%x", ws_optarg, *err);
|
||||
return WTAP_OPEN_ERROR;
|
||||
}
|
||||
if (!convert_level)
|
||||
{
|
||||
*err = ERROR_INVALID_PARAMETER;
|
||||
*err_info = g_strdup_printf("Level %s cannot be converted, err is 0x%x", optarg, *err);
|
||||
*err_info = g_strdup_printf("Level %s cannot be converted, err is 0x%x", ws_optarg, *err);
|
||||
return WTAP_OPEN_ERROR;
|
||||
}
|
||||
|
||||
|
|
|
@ -170,7 +170,7 @@ int main(int argc, char* argv[])
|
|||
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) {
|
||||
case OPT_VERSION:
|
||||
extcap_version_print(extcap_conf);
|
||||
|
@ -183,12 +183,12 @@ int main(int argc, char* argv[])
|
|||
goto end;
|
||||
|
||||
case OPT_ETLFILE:
|
||||
etlfile = g_strdup(optarg);
|
||||
etlfile = g_strdup(ws_optarg);
|
||||
break;
|
||||
|
||||
case OPT_PARAMS:
|
||||
/* Add params as the prefix since getopt_long will ignore the first argument always */
|
||||
params = g_strdup_printf("params %s", optarg);
|
||||
params = g_strdup_printf("params %s", ws_optarg);
|
||||
break;
|
||||
|
||||
case OPT_INCLUDE_UNDECIDABLE_EVENT:
|
||||
|
@ -197,14 +197,14 @@ 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:
|
||||
/* Handle extcap specific options */
|
||||
if (!extcap_base_parse_options(extcap_conf, result - EXTCAP_OPT_LIST_INTERFACES, optarg))
|
||||
if (!extcap_base_parse_options(extcap_conf, result - EXTCAP_OPT_LIST_INTERFACES, ws_optarg))
|
||||
{
|
||||
ws_warning("Invalid option: %s", argv[optind - 1]);
|
||||
ws_warning("Invalid option: %s", argv[ws_optind - 1]);
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,18 +21,6 @@
|
|||
#include <wsutil/wslog.h>
|
||||
|
||||
#include <wsutil/ws_assert.h>
|
||||
/*
|
||||
* If we have getopt_long() in the system library, include <getopt.h>.
|
||||
* Otherwise, we're using our own getopt_long() (either because the
|
||||
* system has getopt() but not getopt_long(), as with some UN*Xes,
|
||||
* or because it doesn't even have getopt(), as with Windows), so
|
||||
* include our getopt_long()'s header.
|
||||
*/
|
||||
#ifdef HAVE_GETOPT_LONG
|
||||
#include <getopt.h>
|
||||
#else
|
||||
#include <wsutil/wsgetopt.h>
|
||||
#endif
|
||||
|
||||
#include "ws_attributes.h"
|
||||
|
||||
|
|
|
@ -19,18 +19,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/*
|
||||
* If we have getopt_long() in the system library, include <getopt.h>.
|
||||
* Otherwise, we're using our own getopt_long() (either because the
|
||||
* system has getopt() but not getopt_long(), as with some UN*Xes,
|
||||
* or because it doesn't even have getopt(), as with Windows), so
|
||||
* include our getopt_long()'s header.
|
||||
*/
|
||||
#ifdef HAVE_GETOPT_LONG
|
||||
#include <getopt.h>
|
||||
#else
|
||||
#include <wsutil/wsgetopt.h>
|
||||
#endif
|
||||
#include <wsutil/ws_getopt.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <io.h>
|
||||
|
|
|
@ -205,7 +205,7 @@ int main(int argc, char *argv[])
|
|||
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) {
|
||||
case OPT_VERSION:
|
||||
extcap_version_print(extcap_conf);
|
||||
|
@ -218,23 +218,23 @@ int main(int argc, char *argv[])
|
|||
goto end;
|
||||
|
||||
case OPT_MAXBYTES:
|
||||
if (!ws_strtou16(optarg, NULL, &maxbytes)) {
|
||||
if (!ws_strtou16(ws_optarg, NULL, &maxbytes)) {
|
||||
ws_warning("Invalid parameter maxbytes: %s (max value is %u)",
|
||||
optarg, G_MAXUINT16);
|
||||
ws_optarg, G_MAXUINT16);
|
||||
goto end;
|
||||
}
|
||||
break;
|
||||
|
||||
case OPT_COUNT:
|
||||
if (!ws_strtou64(optarg, NULL, &count)) {
|
||||
ws_warning("Invalid packet count: %s", optarg);
|
||||
if (!ws_strtou64(ws_optarg, NULL, &count)) {
|
||||
ws_warning("Invalid packet count: %s", ws_optarg);
|
||||
goto end;
|
||||
}
|
||||
break;
|
||||
|
||||
case OPT_DELAY:
|
||||
if (!ws_strtou64(optarg, NULL, &packet_delay_ms)) {
|
||||
ws_warning("Invalid packet delay: %s", optarg);
|
||||
if (!ws_strtou64(ws_optarg, NULL, &packet_delay_ms)) {
|
||||
ws_warning("Invalid packet delay: %s", ws_optarg);
|
||||
goto end;
|
||||
}
|
||||
break;
|
||||
|
@ -249,19 +249,19 @@ int main(int argc, char *argv[])
|
|||
|
||||
case OPT_TYPE:
|
||||
g_free(type);
|
||||
type = g_strdup(optarg);
|
||||
type = g_strdup(ws_optarg);
|
||||
break;
|
||||
|
||||
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:
|
||||
/* Handle extcap specific options */
|
||||
if (!extcap_base_parse_options(extcap_conf, result - EXTCAP_OPT_LIST_INTERFACES, optarg))
|
||||
if (!extcap_base_parse_options(extcap_conf, result - EXTCAP_OPT_LIST_INTERFACES, ws_optarg))
|
||||
{
|
||||
ws_warning("Invalid option: %s", argv[optind - 1]);
|
||||
ws_warning("Invalid option: %s", argv[ws_optind - 1]);
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -385,15 +385,15 @@ int main(int argc, char **argv)
|
|||
extcap_help_add_option(extcap_conf, "--version", "print the version");
|
||||
extcap_help_add_option(extcap_conf, "--start-from <entry count>", "starting position");
|
||||
|
||||
opterr = 0;
|
||||
optind = 0;
|
||||
ws_opterr = 0;
|
||||
ws_optind = 0;
|
||||
|
||||
if (argc == 1) {
|
||||