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.
This commit is contained in:
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) {
|
||||
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) {
|
||||
|
||||
|
@ -408,12 +408,12 @@ int main(int argc, char **argv)
|
|||
goto end;
|
||||
|
||||
case OPT_START_FROM:
|
||||
start_from_entries = (int) strtol(optarg, NULL, 10);
|
||||
start_from_entries = (int) strtol(ws_optarg, NULL, 10);
|
||||
if (errno == EINVAL) {
|
||||
ws_warning("Invalid entry count: %s", optarg);
|
||||
ws_warning("Invalid entry count: %s", ws_optarg);
|
||||
goto end;
|
||||
}
|
||||
if (strlen(optarg) > 0 && optarg[0] == '+') {
|
||||
if (strlen(ws_optarg) > 0 && ws_optarg[0] == '+') {
|
||||
start_from_end = FALSE;
|
||||
}
|
||||
if (start_from_entries < 0) {
|
||||
|
@ -425,12 +425,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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -399,15 +399,15 @@ int main(int argc, char *argv[])
|
|||
extcap_help_add_option(extcap_conf, "--port <port>", port_msg);
|
||||
g_free(port_msg);
|
||||
|
||||
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:
|
||||
|
@ -420,25 +420,25 @@ int main(int argc, char *argv[])
|
|||
goto end;
|
||||
|
||||
case OPT_PORT:
|
||||
if (!ws_strtou16(optarg, NULL, &port)) {
|
||||
ws_warning("Invalid port: %s", optarg);
|
||||
if (!ws_strtou16(ws_optarg, NULL, &port)) {
|
||||
ws_warning("Invalid port: %s", ws_optarg);
|
||||
goto end;
|
||||
}
|
||||
break;
|
||||
|
||||
case OPT_PAYLOAD:
|
||||
g_free(payload);
|
||||
payload = g_strdup(optarg);
|
||||
payload = 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:
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -446,8 +446,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;
|
||||
}
|
||||
|
||||
|
|
43
mergecap.c
43
mergecap.c
|
@ -18,18 +18,7 @@
|
|||
#include <errno.h>
|
||||
#include <glib.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 <string.h>
|
||||
|
||||
|
@ -265,7 +254,7 @@ main(int argc, char *argv[])
|
|||
wtap_init(TRUE);
|
||||
|
||||
/* Process the options first */
|
||||
while ((opt = getopt_long(argc, argv, "aF:hI:s:vVw:", long_options, NULL)) != -1) {
|
||||
while ((opt = ws_getopt_long(argc, argv, "aF:hI:s:vVw:", long_options, NULL)) != -1) {
|
||||
|
||||
switch (opt) {
|
||||
case 'a':
|
||||
|
@ -273,10 +262,10 @@ main(int argc, char *argv[])
|
|||
break;
|
||||
|
||||
case 'F':
|
||||
file_type = wtap_name_to_file_type_subtype(optarg);
|
||||
file_type = wtap_name_to_file_type_subtype(ws_optarg);
|
||||
if (file_type < 0) {
|
||||
fprintf(stderr, "mergecap: \"%s\" isn't a valid capture file type\n",
|
||||
optarg);
|
||||
ws_optarg);
|
||||
list_capture_types();
|
||||
status = MERGE_ERR_INVALID_OPTION;
|
||||
goto clean_exit;
|
||||
|
@ -290,10 +279,10 @@ main(int argc, char *argv[])
|
|||
break;
|
||||
|
||||
case 'I':
|
||||
mode = merge_string_to_idb_merge_mode(optarg);
|
||||
mode = merge_string_to_idb_merge_mode(ws_optarg);
|
||||
if (mode == IDB_MERGE_MODE_MAX) {
|
||||
fprintf(stderr, "mergecap: \"%s\" isn't a valid IDB merge mode\n",
|
||||
optarg);
|
||||
ws_optarg);
|
||||
list_idb_merge_modes();
|
||||
status = MERGE_ERR_INVALID_OPTION;
|
||||
goto clean_exit;
|
||||
|
@ -301,7 +290,7 @@ 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 'v':
|
||||
|
@ -314,11 +303,11 @@ main(int argc, char *argv[])
|
|||
break;
|
||||
|
||||
case 'w':
|
||||
out_filename = optarg;
|
||||
out_filename = ws_optarg;
|
||||
break;
|
||||
|
||||
case '?': /* Bad options if GNU getopt */
|
||||
switch(optopt) {
|
||||
switch(ws_optopt) {
|
||||
case'F':
|
||||
list_capture_types();
|
||||
break;
|
||||
|
@ -344,7 +333,7 @@ main(int argc, char *argv[])
|
|||
/* check for proper args; at a minimum, must have an output
|
||||
* filename and one input file
|
||||
*/
|
||||
in_file_count = argc - optind;
|
||||
in_file_count = argc - ws_optind;
|
||||
if (!out_filename) {
|
||||
fprintf(stderr, "mergecap: an output filename must be set with -w\n");
|
||||
fprintf(stderr, " run with -h for help\n");
|
||||
|
@ -376,7 +365,7 @@ main(int argc, char *argv[])
|
|||
if (strcmp(out_filename, "-") == 0) {
|
||||
/* merge the files to the standard output */
|
||||
status = merge_files_to_stdout(file_type,
|
||||
(const char *const *) &argv[optind],
|
||||
(const char *const *) &argv[ws_optind],
|
||||
in_file_count, do_append, mode, snaplen,
|
||||
get_appname_and_version(),
|
||||
verbose ? &cb : NULL,
|
||||
|
@ -384,7 +373,7 @@ main(int argc, char *argv[])
|
|||
} else {
|
||||
/* merge the files to the outfile */
|
||||
status = merge_files(out_filename, file_type,
|
||||
(const char *const *) &argv[optind], in_file_count,
|
||||
(const char *const *) &argv[ws_optind], in_file_count,
|
||||
do_append, mode, snaplen, get_appname_and_version(),
|
||||
verbose ? &cb : NULL,
|
||||
&err, &err_info, &err_fileno, &err_framenum);
|
||||
|
@ -400,7 +389,7 @@ main(int argc, char *argv[])
|
|||
break;
|
||||
|
||||
case MERGE_ERR_CANT_OPEN_INFILE:
|
||||
cfile_open_failure_message(argv[optind + err_fileno], err, err_info);
|
||||
cfile_open_failure_message(argv[ws_optind + err_fileno], err, err_info);
|
||||
break;
|
||||
|
||||
case MERGE_ERR_CANT_OPEN_OUTFILE:
|
||||
|
@ -408,16 +397,16 @@ main(int argc, char *argv[])
|
|||
break;
|
||||
|
||||
case MERGE_ERR_CANT_READ_INFILE:
|
||||
cfile_read_failure_message(argv[optind + err_fileno], err, err_info);
|
||||
cfile_read_failure_message(argv[ws_optind + err_fileno], err, err_info);
|
||||
break;
|
||||
|
||||
case MERGE_ERR_BAD_PHDR_INTERFACE_ID:
|
||||
cmdarg_err("Record %u of \"%s\" has an interface ID that does not match any IDB in its file.",
|
||||
err_framenum, argv[optind + err_fileno]);
|
||||
err_framenum, argv[ws_optind + err_fileno]);
|
||||
break;
|
||||
|
||||
case MERGE_ERR_CANT_WRITE_OUTFILE:
|
||||
cfile_write_failure_message(argv[optind + err_fileno], out_filename,
|
||||
cfile_write_failure_message(argv[ws_optind + err_fileno], out_filename,
|
||||
err, err_info, err_framenum, file_type);
|
||||
break;
|
||||
|
||||
|
|
25
randpkt.c
25
randpkt.c
|
@ -31,18 +31,7 @@
|
|||
#include <wsutil/report_message.h>
|
||||
#include <wsutil/wslog.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 "randpkt_core/randpkt_core.h"
|
||||
|
||||
|
@ -171,10 +160,10 @@ main(int argc, char *argv[])
|
|||
create_app_running_mutex();
|
||||
#endif /* _WIN32 */
|
||||
|
||||
while ((opt = getopt_long(argc, argv, "b:c:ht:r", long_options, NULL)) != -1) {
|
||||
while ((opt = ws_getopt_long(argc, argv, "b:c:ht:r", long_options, NULL)) != -1) {
|
||||
switch (opt) {
|
||||
case 'b': /* max bytes */
|
||||
produce_max_bytes = get_positive_int(optarg, "max bytes");
|
||||
produce_max_bytes = get_positive_int(ws_optarg, "max bytes");
|
||||
if (produce_max_bytes > 65536) {
|
||||
cmdarg_err("max bytes is > 65536");
|
||||
ret = INVALID_OPTION;
|
||||
|
@ -183,11 +172,11 @@ main(int argc, char *argv[])
|
|||
break;
|
||||
|
||||
case 'c': /* count */
|
||||
produce_count = get_positive_int(optarg, "count");
|
||||
produce_count = get_positive_int(ws_optarg, "count");
|
||||
break;
|
||||
|
||||
case 't': /* type of packet to produce */
|
||||
type = g_strdup(optarg);
|
||||
type = g_strdup(ws_optarg);
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
|
@ -208,8 +197,8 @@ main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
/* any more command line parameters? */
|
||||
if (argc > optind) {
|
||||
produce_filename = argv[optind];
|
||||
if (argc > ws_optind) {
|
||||
produce_filename = argv[ws_optind];
|
||||
} else {
|
||||
usage(TRUE);
|
||||
ret = INVALID_OPTION;
|
||||
|
|
65
rawshark.c
65
rawshark.c
|
@ -35,18 +35,7 @@
|
|||
|
||||
#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>
|
||||
#include <epan/epan.h>
|
||||
|
@ -540,17 +529,17 @@ main(int argc, char *argv[])
|
|||
|
||||
/* Now get our args */
|
||||
/* XXX - We should probably have an option to dump libpcap link types */
|
||||
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 'd': /* Payload type */
|
||||
if (!set_link_type(optarg)) {
|
||||
cmdarg_err("Invalid link type or protocol \"%s\"", optarg);
|
||||
if (!set_link_type(ws_optarg)) {
|
||||
cmdarg_err("Invalid link type or protocol \"%s\"", ws_optarg);
|
||||
ret = INVALID_OPTION;
|
||||
goto clean_exit;
|
||||
}
|
||||
break;
|
||||
case 'F': /* Read field to display */
|
||||
g_ptr_array_add(disp_fields, g_strdup(optarg));
|
||||
g_ptr_array_add(disp_fields, g_strdup(ws_optarg));
|
||||
break;
|
||||
case 'h': /* Print help and exit */
|
||||
show_help_header("Dump and analyze network traffic.");
|
||||
|
@ -574,8 +563,8 @@ main(int argc, char *argv[])
|
|||
break;
|
||||
#ifndef _WIN32
|
||||
case 'm':
|
||||
limit.rlim_cur = get_positive_int(optarg, "memory limit");
|
||||
limit.rlim_max = get_positive_int(optarg, "memory limit");
|
||||
limit.rlim_cur = get_positive_int(ws_optarg, "memory limit");
|
||||
limit.rlim_max = get_positive_int(ws_optarg, "memory limit");
|
||||
|
||||
if(setrlimit(RLIMIT_AS, &limit) != 0) {
|
||||
cmdarg_err("setrlimit() returned error");
|
||||
|
@ -588,7 +577,7 @@ main(int argc, char *argv[])
|
|||
disable_name_resolution();
|
||||
break;
|
||||
case 'N': /* Select what types of addresses/port #s to resolve */
|
||||
badopt = string_to_name_resolve(optarg, &gbl_resolv_flags);
|
||||
badopt = string_to_name_resolve(ws_optarg, &gbl_resolv_flags);
|
||||
if (badopt != '\0') {
|
||||
cmdarg_err("-N specifies unknown resolving option '%c'; valid options are 'd', m', 'n', 'N', and 't'",
|
||||
badopt);
|
||||
|
@ -600,13 +589,13 @@ main(int argc, char *argv[])
|
|||
{
|
||||
char *errmsg = NULL;
|
||||
|
||||
switch (prefs_set_pref(optarg, &errmsg)) {
|
||||
switch (prefs_set_pref(ws_optarg, &errmsg)) {
|
||||
|
||||
case PREFS_SET_OK:
|
||||
break;
|
||||
|
||||
case PREFS_SET_SYNTAX_ERR:
|
||||
cmdarg_err("Invalid -o flag \"%s\"%s%s", optarg,
|
||||
cmdarg_err("Invalid -o flag \"%s\"%s%s", ws_optarg,
|
||||
errmsg ? ": " : "", errmsg ? errmsg : "");
|
||||
g_free(errmsg);
|
||||
ret = INVALID_OPTION;
|
||||
|
@ -615,7 +604,7 @@ main(int argc, char *argv[])
|
|||
|
||||
case PREFS_SET_NO_SUCH_PREF:
|
||||
case PREFS_SET_OBSOLETE:
|
||||
cmdarg_err("-o flag \"%s\" specifies unknown preference", optarg);
|
||||
cmdarg_err("-o flag \"%s\" specifies unknown preference", ws_optarg);
|
||||
ret = INVALID_OPTION;
|
||||
goto clean_exit;
|
||||
break;
|
||||
|
@ -626,11 +615,11 @@ main(int argc, char *argv[])
|
|||
want_pcap_pkthdr = TRUE;
|
||||
break;
|
||||
case 'r': /* Read capture file xxx */
|
||||
pipe_name = g_strdup(optarg);
|
||||
pipe_name = g_strdup(ws_optarg);
|
||||
break;
|
||||
case 'R': /* Read file filter */
|
||||
if(n_rfilters < (int) sizeof(rfilters) / (int) sizeof(rfilters[0])) {
|
||||
rfilters[n_rfilters++] = optarg;
|
||||
rfilters[n_rfilters++] = ws_optarg;
|
||||
}
|
||||
else {
|
||||
cmdarg_err("Too many display filters");
|
||||
|
@ -642,36 +631,36 @@ main(int argc, char *argv[])
|
|||
skip_pcap_header = TRUE;
|
||||
break;
|
||||
case 'S': /* Print string representations */
|
||||
if (!parse_field_string_format(optarg)) {
|
||||
if (!parse_field_string_format(ws_optarg)) {
|
||||
cmdarg_err("Invalid field string format");
|
||||
ret = INVALID_OPTION;
|
||||
goto clean_exit;
|
||||
}
|
||||
break;
|
||||
case 't': /* Time stamp type */
|
||||
if (strcmp(optarg, "r") == 0)
|
||||
if (strcmp(ws_optarg, "r") == 0)
|
||||
timestamp_set_type(TS_RELATIVE);
|
||||
else if (strcmp(optarg, "a") == 0)
|
||||
else if (strcmp(ws_optarg, "a") == 0)
|
||||
timestamp_set_type(TS_ABSOLUTE);
|
||||
else if (strcmp(optarg, "ad") == 0)
|
||||
else if (strcmp(ws_optarg, "ad") == 0)
|
||||
timestamp_set_type(TS_ABSOLUTE_WITH_YMD);
|
||||
else if (strcmp(optarg, "adoy") == 0)
|
||||
else if (strcmp(ws_optarg, "adoy") == 0)
|
||||
timestamp_set_type(TS_ABSOLUTE_WITH_YDOY);
|
||||
else if (strcmp(optarg, "d") == 0)
|
||||
else if (strcmp(ws_optarg, "d") == 0)
|
||||
timestamp_set_type(TS_DELTA);
|
||||
else if (strcmp(optarg, "dd") == 0)
|
||||
else if (strcmp(ws_optarg, "dd") == 0)
|
||||
timestamp_set_type(TS_DELTA_DIS);
|
||||
else if (strcmp(optarg, "e") == 0)
|
||||
else if (strcmp(ws_optarg, "e") == 0)
|
||||
timestamp_set_type(TS_EPOCH);
|
||||
else if (strcmp(optarg, "u") == 0)
|
||||
else if (strcmp(ws_optarg, "u") == 0)
|
||||
timestamp_set_type(TS_UTC);
|
||||
else if (strcmp(optarg, "ud") == 0)
|
||||
else if (strcmp(ws_optarg, "ud") == 0)
|
||||
timestamp_set_type(TS_UTC_WITH_YMD);
|
||||
else if (strcmp(optarg, "udoy") == 0)
|
||||
else if (strcmp(ws_optarg, "udoy") == 0)
|
||||
timestamp_set_type(TS_UTC_WITH_YDOY);
|
||||
else {
|
||||
cmdarg_err("Invalid time stamp type \"%s\"",
|
||||
optarg);
|
||||
ws_optarg);
|
||||
cmdarg_err_cont(
|
||||
"It must be \"a\" for absolute, \"ad\" for absolute with YYYY-MM-DD date,");
|
||||
cmdarg_err_cont(
|
||||
|
@ -718,7 +707,7 @@ main(int argc, char *argv[])
|
|||
still command-line arguments, treat them as the tokens of a capture
|
||||
filter (if no "-r" flag was specified) or a read filter (if a "-r"
|
||||
flag was specified. */
|
||||
if (optind < argc) {
|
||||
if (ws_optind < argc) {
|
||||
if (pipe_name != NULL) {
|
||||
if (n_rfilters != 0) {
|
||||
cmdarg_err("Read filters were specified both with \"-R\" "
|
||||
|
@ -726,7 +715,7 @@ main(int argc, char *argv[])
|
|||
ret = INVALID_OPTION;
|
||||
goto clean_exit;
|
||||
}
|
||||
rfilters[n_rfilters] = get_args_as_string(argc, argv, optind);
|
||||
rfilters[n_rfilters] = get_args_as_string(argc, argv, ws_optind);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
21
reordercap.c
21
reordercap.c
|
@ -15,18 +15,7 @@
|
|||
#include <string.h>
|
||||
#include <glib.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 <wiretap/wtap.h>
|
||||
|
||||
|
@ -242,7 +231,7 @@ main(int argc, char *argv[])
|
|||
wtap_init(TRUE);
|
||||
|
||||
/* Process the options first */
|
||||
while ((opt = getopt_long(argc, argv, "hnv", long_options, NULL)) != -1) {
|
||||
while ((opt = ws_getopt_long(argc, argv, "hnv", long_options, NULL)) != -1) {
|
||||
switch (opt) {
|
||||
case 'n':
|
||||
write_output_regardless = FALSE;
|
||||
|
@ -262,10 +251,10 @@ main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
/* Remaining args are file names */
|
||||
file_count = argc - optind;
|
||||
file_count = argc - ws_optind;
|
||||
if (file_count == 2) {
|
||||
infile = argv[optind];
|
||||
outfile = argv[optind+1];
|
||||
infile = argv[ws_optind];
|
||||
outfile = argv[ws_optind+1];
|
||||
}
|
||||
else {
|
||||
print_usage(stderr);
|
||||
|
|
|
@ -30,18 +30,7 @@
|
|||
#include <wsutil/inet_addr.h>
|
||||
#include <wsutil/please_report_bug.h>
|
||||
#include <wsutil/wslog.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>
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <sys/un.h>
|
||||
|
@ -295,29 +284,29 @@ sharkd_init(int argc, char **argv)
|
|||
*/
|
||||
|
||||
do {
|
||||
if (optind > (argc - 1))
|
||||
if (ws_optind > (argc - 1))
|
||||
break;
|
||||
|
||||
opt = getopt_long(argc, argv, optstring, long_options, NULL);
|
||||
opt = ws_getopt_long(argc, argv, optstring, long_options, NULL);
|
||||
|
||||
switch (opt) {
|
||||
case 'C': /* Configuration Profile */
|
||||
if (profile_exists(optarg, FALSE)) {
|
||||
set_profile_name(optarg); // In Daemon Mode, we may need to do this again in the child process
|
||||
if (profile_exists(ws_optarg, FALSE)) {
|
||||
set_profile_name(ws_optarg); // In Daemon Mode, we may need to do this again in the child process
|
||||
}
|
||||
else {
|
||||
fprintf(stderr, "Configuration Profile \"%s\" does not exist\n", optarg);
|
||||
fprintf(stderr, "Configuration Profile \"%s\" does not exist\n", ws_optarg);
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'a':
|
||||
fd = socket_init(optarg);
|
||||
fd = socket_init(ws_optarg);
|
||||
if (fd == INVALID_SOCKET)
|
||||
return -1;
|
||||
_server_fd = fd;
|
||||
|
||||
fprintf(stderr, "Sharkd listening on: %s\n", optarg);
|
||||
fprintf(stderr, "Sharkd listening on: %s\n", ws_optarg);
|
||||
|
||||
mode = SHARKD_MODE_GOLD_DAEMON;
|
||||
break;
|
||||
|
@ -338,8 +327,8 @@ sharkd_init(int argc, char **argv)
|
|||
break;
|
||||
|
||||
default:
|
||||
if (!optopt)
|
||||
fprintf(stderr, "This option isn't supported: %s\n", argv[optind]);
|
||||
if (!ws_optopt)
|
||||
fprintf(stderr, "This option isn't supported: %s\n", argv[ws_optind]);
|
||||
fprintf(stderr, "Use sharkd -h for details of supported options\n");
|
||||
exit(0);
|
||||
break;
|
||||
|
|
107
text2pcap.c
107
text2pcap.c
|
@ -113,18 +113,7 @@
|
|||
#include <time.h>
|
||||
#include <glib.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 <errno.h>
|
||||
#include <assert.h>
|
||||
|
@ -1467,7 +1456,7 @@ parse_options (int argc, char *argv[])
|
|||
ws_init_version_info("Text2pcap (Wireshark)", NULL, NULL, NULL);
|
||||
|
||||
/* Scan CLI parameters */
|
||||
while ((c = getopt_long(argc, argv, "aDdhqe:i:l:m:nN:o:u:s:S:t:T:v4:6:", long_options, NULL)) != -1) {
|
||||
while ((c = ws_getopt_long(argc, argv, "aDdhqe:i:l:m:nN:o:u:s:S:t:T:v4:6:", long_options, NULL)) != -1) {
|
||||
switch (c) {
|
||||
case 'h':
|
||||
show_help_header("Generate a capture file from an ASCII hexdump of packets.");
|
||||
|
@ -1477,17 +1466,17 @@ parse_options (int argc, char *argv[])
|
|||
case 'd': if (!quiet) debug++; break;
|
||||
case 'D': has_direction = TRUE; break;
|
||||
case 'q': quiet = TRUE; debug = 0; break;
|
||||
case 'l': pcap_link_type = (guint32)strtol(optarg, NULL, 0); break;
|
||||
case 'm': max_offset = (guint32)strtol(optarg, NULL, 0); break;
|
||||
case 'l': pcap_link_type = (guint32)strtol(ws_optarg, NULL, 0); break;
|
||||
case 'm': max_offset = (guint32)strtol(ws_optarg, NULL, 0); break;
|
||||
case 'n': use_pcapng = TRUE; break;
|
||||
case 'N': interface_name = optarg; break;
|
||||
case 'N': interface_name = ws_optarg; break;
|
||||
case 'o':
|
||||
if (optarg[0] != 'h' && optarg[0] != 'o' && optarg[0] != 'd') {
|
||||
fprintf(stderr, "Bad argument for '-o': %s\n", optarg);
|
||||
if (ws_optarg[0] != 'h' && ws_optarg[0] != 'o' && ws_optarg[0] != 'd') {
|
||||
fprintf(stderr, "Bad argument for '-o': %s\n", ws_optarg);
|
||||
print_usage(stderr);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
switch (optarg[0]) {
|
||||
switch (ws_optarg[0]) {
|
||||
case 'o': offset_base = 8; break;
|
||||
case 'h': offset_base = 16; break;
|
||||
case 'd': offset_base = 10; break;
|
||||
|
@ -1495,18 +1484,18 @@ parse_options (int argc, char *argv[])
|
|||
break;
|
||||
case 'e':
|
||||
hdr_ethernet = TRUE;
|
||||
if (sscanf(optarg, "%x", &hdr_ethernet_proto) < 1) {
|
||||
fprintf(stderr, "Bad argument for '-e': %s\n", optarg);
|
||||
if (sscanf(ws_optarg, "%x", &hdr_ethernet_proto) < 1) {
|
||||
fprintf(stderr, "Bad argument for '-e': %s\n", ws_optarg);
|
||||
print_usage(stderr);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'i':
|
||||
hdr_ip_proto = strtol(optarg, &p, 10);
|
||||
if (p == optarg || *p != '\0' || hdr_ip_proto < 0 ||
|
||||
hdr_ip_proto = strtol(ws_optarg, &p, 10);
|
||||
if (p == ws_optarg || *p != '\0' || hdr_ip_proto < 0 ||
|
||||
hdr_ip_proto > 255) {
|
||||
fprintf(stderr, "Bad argument for '-i': %s\n", optarg);
|
||||
fprintf(stderr, "Bad argument for '-i': %s\n", ws_optarg);
|
||||
print_usage(stderr);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
@ -1518,8 +1507,8 @@ parse_options (int argc, char *argv[])
|
|||
hdr_data_chunk = FALSE;
|
||||
hdr_tcp = FALSE;
|
||||
hdr_udp = FALSE;
|
||||
hdr_sctp_src = (guint32)strtol(optarg, &p, 10);
|
||||
if (p == optarg || (*p != ',' && *p != '\0')) {
|
||||
hdr_sctp_src = (guint32)strtol(ws_optarg, &p, 10);
|
||||
if (p == ws_optarg || (*p != ',' && *p != '\0')) {
|
||||
fprintf(stderr, "Bad src port for '-%c'\n", c);
|
||||
print_usage(stderr);
|
||||
return EXIT_FAILURE;
|
||||
|
@ -1530,9 +1519,9 @@ parse_options (int argc, char *argv[])
|
|||
return EXIT_FAILURE;
|
||||
}
|
||||
p++;
|
||||
optarg = p;
|
||||
hdr_sctp_dest = (guint32)strtol(optarg, &p, 10);
|
||||
if (p == optarg || (*p != ',' && *p != '\0')) {
|
||||
ws_optarg = p;
|
||||
hdr_sctp_dest = (guint32)strtol(ws_optarg, &p, 10);
|
||||
if (p == ws_optarg || (*p != ',' && *p != '\0')) {
|
||||
fprintf(stderr, "Bad dest port for '-s'\n");
|
||||
print_usage(stderr);
|
||||
return EXIT_FAILURE;
|
||||
|
@ -1543,9 +1532,9 @@ parse_options (int argc, char *argv[])
|
|||
return EXIT_FAILURE;
|
||||
}
|
||||
p++;
|
||||
optarg = p;
|
||||
hdr_sctp_tag = (guint32)strtol(optarg, &p, 10);
|
||||
if (p == optarg || *p != '\0') {
|
||||
ws_optarg = p;
|
||||
hdr_sctp_tag = (guint32)strtol(ws_optarg, &p, 10);
|
||||
if (p == ws_optarg || *p != '\0') {
|
||||
fprintf(stderr, "Bad tag for '-%c'\n", c);
|
||||
print_usage(stderr);
|
||||
return EXIT_FAILURE;
|
||||
|
@ -1559,8 +1548,8 @@ parse_options (int argc, char *argv[])
|
|||
hdr_data_chunk = TRUE;
|
||||
hdr_tcp = FALSE;
|
||||
hdr_udp = FALSE;
|
||||
hdr_sctp_src = (guint32)strtol(optarg, &p, 10);
|
||||
if (p == optarg || (*p != ',' && *p != '\0')) {
|
||||
hdr_sctp_src = (guint32)strtol(ws_optarg, &p, 10);
|
||||
if (p == ws_optarg || (*p != ',' && *p != '\0')) {
|
||||
fprintf(stderr, "Bad src port for '-%c'\n", c);
|
||||
print_usage(stderr);
|
||||
return EXIT_FAILURE;
|
||||
|
@ -1571,9 +1560,9 @@ parse_options (int argc, char *argv[])
|
|||
return EXIT_FAILURE;
|
||||
}
|
||||
p++;
|
||||
optarg = p;
|
||||
hdr_sctp_dest = (guint32)strtol(optarg, &p, 10);
|
||||
if (p == optarg || (*p != ',' && *p != '\0')) {
|
||||
ws_optarg = p;
|
||||
hdr_sctp_dest = (guint32)strtol(ws_optarg, &p, 10);
|
||||
if (p == ws_optarg || (*p != ',' && *p != '\0')) {
|
||||
fprintf(stderr, "Bad dest port for '-s'\n");
|
||||
print_usage(stderr);
|
||||
return EXIT_FAILURE;
|
||||
|
@ -1584,9 +1573,9 @@ parse_options (int argc, char *argv[])
|
|||
return EXIT_FAILURE;
|
||||
}
|
||||
p++;
|
||||
optarg = p;
|
||||
hdr_data_chunk_ppid = (guint32)strtoul(optarg, &p, 10);
|
||||
if (p == optarg || *p != '\0') {
|
||||
ws_optarg = p;
|
||||
hdr_data_chunk_ppid = (guint32)strtoul(ws_optarg, &p, 10);
|
||||
if (p == ws_optarg || *p != '\0') {
|
||||
fprintf(stderr, "Bad ppi for '-%c'\n", c);
|
||||
print_usage(stderr);
|
||||
return EXIT_FAILURE;
|
||||
|
@ -1597,7 +1586,7 @@ parse_options (int argc, char *argv[])
|
|||
break;
|
||||
|
||||
case 't':
|
||||
ts_fmt = optarg;
|
||||
ts_fmt = ws_optarg;
|
||||
break;
|
||||
|
||||
case 'u':
|
||||
|
@ -1605,8 +1594,8 @@ parse_options (int argc, char *argv[])
|
|||
hdr_tcp = FALSE;
|
||||
hdr_sctp = FALSE;
|
||||
hdr_data_chunk = FALSE;
|
||||
hdr_src_port = (guint32)strtol(optarg, &p, 10);
|
||||
if (p == optarg || (*p != ',' && *p != '\0')) {
|
||||
hdr_src_port = (guint32)strtol(ws_optarg, &p, 10);
|
||||
if (p == ws_optarg || (*p != ',' && *p != '\0')) {
|
||||
fprintf(stderr, "Bad src port for '-u'\n");
|
||||
print_usage(stderr);
|
||||
return EXIT_FAILURE;
|
||||
|
@ -1617,9 +1606,9 @@ parse_options (int argc, char *argv[])
|
|||
return EXIT_FAILURE;
|
||||
}
|
||||
p++;
|
||||
optarg = p;
|
||||
hdr_dest_port = (guint32)strtol(optarg, &p, 10);
|
||||
if (p == optarg || *p != '\0') {
|
||||
ws_optarg = p;
|
||||
hdr_dest_port = (guint32)strtol(ws_optarg, &p, 10);
|
||||
if (p == ws_optarg || *p != '\0') {
|
||||
fprintf(stderr, "Bad dest port for '-u'\n");
|
||||
print_usage(stderr);
|
||||
return EXIT_FAILURE;
|
||||
|
@ -1633,8 +1622,8 @@ parse_options (int argc, char *argv[])
|
|||
hdr_udp = FALSE;
|
||||
hdr_sctp = FALSE;
|
||||
hdr_data_chunk = FALSE;
|
||||
hdr_src_port = (guint32)strtol(optarg, &p, 10);
|
||||
if (p == optarg || (*p != ',' && *p != '\0')) {
|
||||
hdr_src_port = (guint32)strtol(ws_optarg, &p, 10);
|
||||
if (p == ws_optarg || (*p != ',' && *p != '\0')) {
|
||||
fprintf(stderr, "Bad src port for '-T'\n");
|
||||
print_usage(stderr);
|
||||
return EXIT_FAILURE;
|
||||
|
@ -1645,9 +1634,9 @@ parse_options (int argc, char *argv[])
|
|||
return EXIT_FAILURE;
|
||||
}
|
||||
p++;
|
||||
optarg = p;
|
||||
hdr_dest_port = (guint32)strtol(optarg, &p, 10);
|
||||
if (p == optarg || *p != '\0') {
|
||||
ws_optarg = p;
|
||||
hdr_dest_port = (guint32)strtol(ws_optarg, &p, 10);
|
||||
if (p == ws_optarg || *p != '\0') {
|
||||
fprintf(stderr, "Bad dest port for '-T'\n");
|
||||
print_usage(stderr);
|
||||
return EXIT_FAILURE;
|
||||
|
@ -1667,7 +1656,7 @@ parse_options (int argc, char *argv[])
|
|||
|
||||
case '4':
|
||||
case '6':
|
||||
p = strchr(optarg, ',');
|
||||
p = strchr(ws_optarg, ',');
|
||||
|
||||
if (!p) {
|
||||
fprintf(stderr, "Bad source param addr for '-%c'\n", c);
|
||||
|
@ -1689,13 +1678,13 @@ parse_options (int argc, char *argv[])
|
|||
hdr_ethernet = TRUE;
|
||||
|
||||
if (hdr_ipv6 == TRUE) {
|
||||
if (!ws_inet_pton6(optarg, &hdr_ipv6_src_addr)) {
|
||||
if (!ws_inet_pton6(ws_optarg, &hdr_ipv6_src_addr)) {
|
||||
fprintf(stderr, "Bad src addr -%c '%s'\n", c, p);
|
||||
print_usage(stderr);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
} else {
|
||||
if (!ws_inet_pton4(optarg, &hdr_ip_src_addr)) {
|
||||
if (!ws_inet_pton4(ws_optarg, &hdr_ip_src_addr)) {
|
||||
fprintf(stderr, "Bad src addr -%c '%s'\n", c, p);
|
||||
print_usage(stderr);
|
||||
return EXIT_FAILURE;
|
||||
|
@ -1732,7 +1721,7 @@ parse_options (int argc, char *argv[])
|
|||
}
|
||||
}
|
||||
|
||||
if (optind >= argc || argc-optind < 2) {
|
||||
if (ws_optind >= argc || argc-ws_optind < 2) {
|
||||
fprintf(stderr, "Must specify input and output filename\n");
|
||||
print_usage(stderr);
|
||||
return EXIT_FAILURE;
|
||||
|
@ -1744,8 +1733,8 @@ parse_options (int argc, char *argv[])
|
|||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (strcmp(argv[optind], "-") != 0) {
|
||||
input_filename = argv[optind];
|
||||
if (strcmp(argv[ws_optind], "-") != 0) {
|
||||
input_filename = argv[ws_optind];
|
||||
input_file = ws_fopen(input_filename, "rb");
|
||||
if (!input_file) {
|
||||
fprintf(stderr, "Cannot open file [%s] for reading: %s\n",
|
||||
|
@ -1757,9 +1746,9 @@ parse_options (int argc, char *argv[])
|
|||
input_file = stdin;
|
||||
}
|
||||
|
||||
if (strcmp(argv[optind+1], "-") != 0) {
|
||||
if (strcmp(argv[ws_optind+1], "-") != 0) {
|
||||
/* Write to a file. Open the file, in binary mode. */
|
||||
output_filename = argv[optind+1];
|
||||
output_filename = argv[ws_optind+1];
|
||||
output_file = ws_fopen(output_filename, "wb");
|
||||
if (!output_file) {
|
||||
fprintf(stderr, "Cannot open file [%s] for writing: %s\n",
|
||||
|
|
95
tfshark.c
95
tfshark.c
|
@ -19,18 +19,7 @@
|
|||
#include <locale.h>
|
||||
#include <limits.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 <errno.h>
|
||||
|
||||
|
@ -402,20 +391,20 @@ main(int argc, char *argv[])
|
|||
* arguments we can't handle until after initializing libwireshark,
|
||||
* and then process them after initializing libwireshark?
|
||||
*/
|
||||
opterr = 0;
|
||||
ws_opterr = 0;
|
||||
|
||||
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 'C': /* Configuration Profile */
|
||||
if (profile_exists (optarg, FALSE)) {
|
||||
set_profile_name (optarg);
|
||||
if (profile_exists (ws_optarg, FALSE)) {
|
||||
set_profile_name (ws_optarg);
|
||||
} else {
|
||||
cmdarg_err("Configuration Profile \"%s\" does not exist", optarg);
|
||||
cmdarg_err("Configuration Profile \"%s\" does not exist", ws_optarg);
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
case 'O': /* Only output these protocols */
|
||||
output_only = g_strdup(optarg);
|
||||
output_only = g_strdup(ws_optarg);
|
||||
/* FALLTHROUGH */
|
||||
case 'V': /* Verbose */
|
||||
print_details = TRUE;
|
||||
|
@ -429,7 +418,7 @@ main(int argc, char *argv[])
|
|||
print_packet_info = TRUE;
|
||||
break;
|
||||
case 'X':
|
||||
ex_opt_add(optarg);
|
||||
ex_opt_add(ws_optarg);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -555,29 +544,17 @@ main(int argc, char *argv[])
|
|||
output_fields = output_fields_new();
|
||||
|
||||
/*
|
||||
* To reset the options parser, set optreset to 1 on platforms that
|
||||
* have optreset (documented in *BSD and macOS, apparently present but
|
||||
* not documented in Solaris - the Illumos repository seems to
|
||||
* suggest that the first Solaris getopt_long(), at least as of 2004,
|
||||
* was based on the NetBSD one, it had optreset) and set optind to 1,
|
||||
* and set optind to 0 otherwise (documented as working in the GNU
|
||||
* getopt_long(). Setting optind to 0 didn't originally work in the
|
||||
* NetBSD one, but that was added later - we don't want to depend on
|
||||
* it if we have optreset).
|
||||
* To reset the options parser, set ws_optreset to 1 and set ws_optind to 1.
|
||||
*
|
||||
* Also reset opterr to 1, so that error messages are printed by
|
||||
* Also reset ws_opterr to 1, so that error messages are printed by
|
||||
* getopt_long().
|
||||
*/
|
||||
#ifdef HAVE_OPTRESET
|
||||
optreset = 1;
|
||||
optind = 1;
|
||||
#else
|
||||
optind = 0;
|
||||
#endif
|
||||
opterr = 1;
|
||||
ws_optreset = 1;
|
||||
ws_optind = 1;
|
||||
ws_opterr = 1;
|
||||
|
||||
/* 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 '2': /* Perform two pass analysis */
|
||||
perform_two_pass_analysis = TRUE;
|
||||
|
@ -587,12 +564,12 @@ main(int argc, char *argv[])
|
|||
break;
|
||||
case 'e':
|
||||
/* Field entry */
|
||||
output_fields_add(output_fields, optarg);
|
||||
output_fields_add(output_fields, ws_optarg);
|
||||
break;
|
||||
case 'E':
|
||||
/* Field option */
|
||||
if (!output_fields_set_option(output_fields, optarg)) {
|
||||
cmdarg_err("\"%s\" is not a valid field output option=value pair.", optarg);
|
||||
if (!output_fields_set_option(output_fields, ws_optarg)) {
|
||||
cmdarg_err("\"%s\" is not a valid field output option=value pair.", ws_optarg);
|
||||
output_fields_list_options(stderr);
|
||||
exit_status = INVALID_OPTION;
|
||||
goto clean_exit;
|
||||
|
@ -634,13 +611,13 @@ main(int argc, char *argv[])
|
|||
{
|
||||
char *errmsg = NULL;
|
||||
|
||||
switch (prefs_set_pref(optarg, &errmsg)) {
|
||||
switch (prefs_set_pref(ws_optarg, &errmsg)) {
|
||||
|
||||
case PREFS_SET_OK:
|
||||
break;
|
||||
|
||||
case PREFS_SET_SYNTAX_ERR:
|
||||
cmdarg_err("Invalid -o flag \"%s\"%s%s", optarg,
|
||||
cmdarg_err("Invalid -o flag \"%s\"%s%s", ws_optarg,
|
||||
errmsg ? ": " : "", errmsg ? errmsg : "");
|
||||
g_free(errmsg);
|
||||
return 1;
|
||||
|
@ -648,7 +625,7 @@ main(int argc, char *argv[])
|
|||
|
||||
case PREFS_SET_NO_SUCH_PREF:
|
||||
case PREFS_SET_OBSOLETE:
|
||||
cmdarg_err("-o flag \"%s\" specifies unknown preference", optarg);
|
||||
cmdarg_err("-o flag \"%s\" specifies unknown preference", ws_optarg);
|
||||
exit_status = INVALID_OPTION;
|
||||
goto clean_exit;
|
||||
break;
|
||||
|
@ -663,35 +640,35 @@ main(int argc, char *argv[])
|
|||
really_quiet = TRUE;
|
||||
break;
|
||||
case 'r': /* Read capture file x */
|
||||
cf_name = g_strdup(optarg);
|
||||
cf_name = g_strdup(ws_optarg);
|
||||
break;
|
||||
case 'R': /* Read file filter */
|
||||
rfilter = optarg;
|
||||
rfilter = ws_optarg;
|
||||
break;
|
||||
case 'S': /* Set the line Separator to be printed between packets */
|
||||
separator = g_strdup(optarg);
|
||||
separator = g_strdup(ws_optarg);
|
||||
break;
|
||||
case 'T': /* printing Type */
|
||||
if (strcmp(optarg, "text") == 0) {
|
||||
if (strcmp(ws_optarg, "text") == 0) {
|
||||
output_action = WRITE_TEXT;
|
||||
print_format = PR_FMT_TEXT;
|
||||
} else if (strcmp(optarg, "ps") == 0) {
|
||||
} else if (strcmp(ws_optarg, "ps") == 0) {
|
||||
output_action = WRITE_TEXT;
|
||||
print_format = PR_FMT_PS;
|
||||
} else if (strcmp(optarg, "pdml") == 0) {
|
||||
} else if (strcmp(ws_optarg, "pdml") == 0) {
|
||||
output_action = WRITE_XML;
|
||||
print_details = TRUE; /* Need details */
|
||||
print_summary = FALSE; /* Don't allow summary */
|
||||
} else if (strcmp(optarg, "psml") == 0) {
|
||||
} else if (strcmp(ws_optarg, "psml") == 0) {
|
||||
output_action = WRITE_XML;
|
||||
print_details = FALSE; /* Don't allow details */
|
||||
print_summary = TRUE; /* Need summary */
|
||||
} else if (strcmp(optarg, "fields") == 0) {
|
||||
} else if (strcmp(ws_optarg, "fields") == 0) {
|
||||
output_action = WRITE_FIELDS;
|
||||
print_details = TRUE; /* Need full tree info */
|
||||
print_summary = FALSE; /* Don't allow summary */
|
||||
} else {
|
||||
cmdarg_err("Invalid -T parameter \"%s\"; it must be one of:", optarg); /* x */
|
||||
cmdarg_err("Invalid -T parameter \"%s\"; it must be one of:", ws_optarg); /* x */
|
||||
cmdarg_err_cont("\t\"fields\" The values of fields specified with the -e option, in a form\n"
|
||||
"\t specified by the -E option.\n"
|
||||
"\t\"pdml\" Packet Details Markup Language, an XML-based format for the\n"
|
||||
|
@ -728,7 +705,7 @@ main(int argc, char *argv[])
|
|||
/* already processed; just ignore it now */
|
||||
break;
|
||||
case 'Y':
|
||||
dfilter = optarg;
|
||||
dfilter = ws_optarg;
|
||||
break;
|
||||
case 'z':
|
||||
/* We won't call the init function for the stat this soon
|
||||
|
@ -736,13 +713,13 @@ main(int argc, char *argv[])
|
|||
by the preferences set callback) from being used as
|
||||
part of a tap filter. Instead, we just add the argument
|
||||
to a list of stat arguments. */
|
||||
if (strcmp("help", optarg) == 0) {
|
||||
if (strcmp("help", ws_optarg) == 0) {
|
||||
fprintf(stderr, "tfshark: The available statistics for the \"-z\" option are:\n");
|
||||
list_stat_cmd_args();
|
||||
goto clean_exit;
|
||||
}
|
||||
if (!process_stat_cmd_arg(optarg)) {
|
||||
cmdarg_err("Invalid -z argument \"%s\"; it must be one of:", optarg);
|
||||
if (!process_stat_cmd_arg(ws_optarg)) {
|
||||
cmdarg_err("Invalid -z argument \"%s\"; it must be one of:", ws_optarg);
|
||||
list_stat_cmd_args();
|
||||
exit_status = INVALID_OPTION;
|
||||
goto clean_exit;
|
||||
|
@ -756,7 +733,7 @@ main(int argc, char *argv[])
|
|||
case LONGOPT_ENABLE_HEURISTIC: /* enable heuristic dissection of protocol */
|
||||
case LONGOPT_DISABLE_HEURISTIC: /* disable heuristic dissection of protocol */
|
||||
case LONGOPT_ENABLE_PROTOCOL: /* enable dissection of protocol (that is disabled by default) */
|
||||
if (!dissect_opts_handle_opt(opt, optarg)) {
|
||||
if (!dissect_opts_handle_opt(opt, ws_optarg)) {
|
||||
exit_status = INVALID_OPTION;
|
||||
goto clean_exit;
|
||||
}
|
||||
|
@ -792,14 +769,14 @@ main(int argc, char *argv[])
|
|||
|
||||
/* If no display filter has been specified, and there are still command-
|
||||
line arguments, treat them as the tokens of a display filter. */
|
||||
if (optind < argc) {
|
||||
if (ws_optind < argc) {
|
||||
if (dfilter != NULL) {
|
||||
cmdarg_err("Display filters were specified both with \"-Y\" "
|
||||
"and with additional command-line arguments.");
|
||||
exit_status = INVALID_OPTION;
|
||||
goto clean_exit;
|
||||
}
|
||||
dfilter = get_args_as_string(argc, argv, optind);
|
||||
dfilter = get_args_as_string(argc, argv, ws_optind);
|
||||
}
|
||||
|
||||
/* if "-q" wasn't specified, we should print packet information */
|
||||
|
|
|
@ -23,5 +23,4 @@ mmdbresolve.c
|
|||
tools/lemon/*
|
||||
wsutil/file_util.h
|
||||
wsutil/strptime.c
|
||||
wsutil/getopt_long.c
|
||||
epan/dissectors/packet-http.c
|
||||
|
|
155
tshark.c
155
tshark.c
|
@ -20,18 +20,7 @@
|
|||
#include <locale.h>
|
||||
#include <limits.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 <errno.h>
|
||||
|
||||
|
@ -852,21 +841,21 @@ main(int argc, char *argv[])
|
|||
* arguments we can't handle until after initializing libwireshark,
|
||||
* and then process them after initializing libwireshark?
|
||||
*/
|
||||
opterr = 0;
|
||||
ws_opterr = 0;
|
||||
|
||||
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 'C': /* Configuration Profile */
|
||||
if (profile_exists (optarg, FALSE)) {
|
||||
set_profile_name (optarg);
|
||||
if (profile_exists (ws_optarg, FALSE)) {
|
||||
set_profile_name (ws_optarg);
|
||||
} else {
|
||||
cmdarg_err("Configuration Profile \"%s\" does not exist", optarg);
|
||||
cmdarg_err("Configuration Profile \"%s\" does not exist", ws_optarg);
|
||||
exit_status = INVALID_OPTION;
|
||||
goto clean_exit;
|
||||
}
|
||||
break;
|
||||
case 'G':
|
||||
if (g_str_has_suffix(optarg, "prefs") || strcmp(optarg, "folders") == 0) {
|
||||
if (g_str_has_suffix(ws_optarg, "prefs") || strcmp(ws_optarg, "folders") == 0) {
|
||||
has_extcap_options = TRUE;
|
||||
}
|
||||
break;
|
||||
|
@ -874,7 +863,7 @@ main(int argc, char *argv[])
|
|||
has_extcap_options = TRUE;
|
||||
break;
|
||||
case 'o':
|
||||
if (g_str_has_prefix(optarg, "extcap.")) {
|
||||
if (g_str_has_prefix(ws_optarg, "extcap.")) {
|
||||
has_extcap_options = TRUE;
|
||||
}
|
||||
break;
|
||||
|
@ -883,10 +872,10 @@ main(int argc, char *argv[])
|
|||
print_summary = TRUE;
|
||||
break;
|
||||
case 'r': /* Read capture file x */
|
||||
cf_name = g_strdup(optarg);
|
||||
cf_name = g_strdup(ws_optarg);
|
||||
break;
|
||||
case 'O': /* Only output these protocols */
|
||||
output_only = g_strdup(optarg);
|
||||
output_only = g_strdup(ws_optarg);
|
||||
/* FALLTHROUGH */
|
||||
case 'V': /* Verbose */
|
||||
print_details = TRUE;
|
||||
|
@ -900,10 +889,10 @@ main(int argc, char *argv[])
|
|||
print_packet_info = TRUE;
|
||||
break;
|
||||
case 'X':
|
||||
ex_opt_add(optarg);
|
||||
ex_opt_add(ws_optarg);
|
||||
break;
|
||||
case LONGOPT_ELASTIC_MAPPING_FILTER:
|
||||
elastic_mapping_filter = optarg;
|
||||
elastic_mapping_filter = ws_optarg;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -1058,29 +1047,17 @@ main(int argc, char *argv[])
|
|||
output_fields = output_fields_new();
|
||||
|
||||
/*
|
||||
* To reset the options parser, set optreset to 1 on platforms that
|
||||
* have optreset (documented in *BSD and macOS, apparently present but
|
||||
* not documented in Solaris - the Illumos repository seems to
|
||||
* suggest that the first Solaris getopt_long(), at least as of 2004,
|
||||
* was based on the NetBSD one, it had optreset) and set optind to 1,
|
||||
* and set optind to 0 otherwise (documented as working in the GNU
|
||||
* getopt_long(). Setting optind to 0 didn't originally work in the
|
||||
* NetBSD one, but that was added later - we don't want to depend on
|
||||
* it if we have optreset).
|
||||
* To reset the options parser, set ws_optreset to 1 and set ws_optind to 1.
|
||||
*
|
||||
* Also reset opterr to 1, so that error messages are printed by
|
||||
* Also reset ws_opterr to 1, so that error messages are printed by
|
||||
* getopt_long().
|
||||
*/
|
||||
#ifdef HAVE_OPTRESET
|
||||
optreset = 1;
|
||||
optind = 1;
|
||||
#else
|
||||
optind = 0;
|
||||
#endif
|
||||
opterr = 1;
|
||||
ws_optreset = 1;
|
||||
ws_optind = 1;
|
||||
ws_opterr = 1;
|
||||
|
||||
/* 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 '2': /* Perform two pass analysis */
|
||||
if(epan_auto_reset){
|
||||
|
@ -1094,7 +1071,7 @@ main(int argc, char *argv[])
|
|||
cmdarg_err("-M does not support two pass analysis.");
|
||||
arg_error=TRUE;
|
||||
}
|
||||
epan_auto_reset_count = get_positive_int(optarg, "epan reset count");
|
||||
epan_auto_reset_count = get_positive_int(ws_optarg, "epan reset count");
|
||||
epan_auto_reset = TRUE;
|
||||
break;
|
||||
case 'a': /* autostop criteria */
|
||||
|
@ -1118,7 +1095,7 @@ main(int argc, char *argv[])
|
|||
case LONGOPT_COMPRESS_TYPE: /* compress type */
|
||||
/* These are options only for packet capture. */
|
||||
#ifdef HAVE_LIBPCAP
|
||||
exit_status = capture_opts_add_opt(&global_capture_opts, opt, optarg);
|
||||
exit_status = capture_opts_add_opt(&global_capture_opts, opt, ws_optarg);
|
||||
if (exit_status != 0) {
|
||||
goto clean_exit;
|
||||
}
|
||||
|
@ -1129,18 +1106,18 @@ main(int argc, char *argv[])
|
|||
break;
|
||||
case 'c': /* Stop after x packets */
|
||||
#ifdef HAVE_LIBPCAP
|
||||
exit_status = capture_opts_add_opt(&global_capture_opts, opt, optarg);
|
||||
exit_status = capture_opts_add_opt(&global_capture_opts, opt, ws_optarg);
|
||||
if (exit_status != 0) {
|
||||
goto clean_exit;
|
||||
}
|
||||
#else
|
||||
max_packet_count = get_positive_int(optarg, "packet count");
|
||||
max_packet_count = get_positive_int(ws_optarg, "packet count");
|
||||
#endif
|
||||
break;
|
||||
case 'w': /* Write to file x */
|
||||
output_file_name = g_strdup(optarg);
|
||||
output_file_name = g_strdup(ws_optarg);
|
||||
#ifdef HAVE_LIBPCAP
|
||||
exit_status = capture_opts_add_opt(&global_capture_opts, opt, optarg);
|
||||
exit_status = capture_opts_add_opt(&global_capture_opts, opt, ws_optarg);
|
||||
if (exit_status != 0) {
|
||||
goto clean_exit;
|
||||
}
|
||||
|
@ -1173,21 +1150,21 @@ main(int argc, char *argv[])
|
|||
break;
|
||||
case 'e':
|
||||
/* Field entry */
|
||||
output_fields_add(output_fields, optarg);
|
||||
output_fields_add(output_fields, ws_optarg);
|
||||
break;
|
||||
case 'E':
|
||||
/* Field option */
|
||||
if (!output_fields_set_option(output_fields, optarg)) {
|
||||
cmdarg_err("\"%s\" is not a valid field output option=value pair.", optarg);
|
||||
if (!output_fields_set_option(output_fields, ws_optarg)) {
|
||||
cmdarg_err("\"%s\" is not a valid field output option=value pair.", ws_optarg);
|
||||
output_fields_list_options(stderr);
|
||||
exit_status = INVALID_OPTION;
|
||||
goto clean_exit;
|
||||
}
|
||||
break;
|
||||
case 'F':
|
||||
out_file_type = wtap_name_to_file_type_subtype(optarg);
|
||||
out_file_type = wtap_name_to_file_type_subtype(ws_optarg);
|
||||
if (out_file_type < 0) {
|
||||
cmdarg_err("\"%s\" isn't a valid capture file type", optarg);
|
||||
cmdarg_err("\"%s\" isn't a valid capture file type", ws_optarg);
|
||||
list_capture_types();
|
||||
exit_status = INVALID_OPTION;
|
||||
goto clean_exit;
|
||||
|
@ -1197,30 +1174,30 @@ main(int argc, char *argv[])
|
|||
if (protocolfilter) {
|
||||
cmdarg_err("-j or -J was already specified! Overwriting previous protocol filter");
|
||||
}
|
||||
protocolfilter = wmem_strsplit(wmem_epan_scope(), optarg, " ", -1);
|
||||
protocolfilter = wmem_strsplit(wmem_epan_scope(), ws_optarg, " ", -1);
|
||||
break;
|
||||
case 'J':
|
||||
if (protocolfilter) {
|
||||
cmdarg_err("-j or -J was already specified! Overwriting previous protocol filter");
|
||||
}
|
||||
protocolfilter_flags = PF_INCLUDE_CHILDREN;
|
||||
protocolfilter = wmem_strsplit(wmem_epan_scope(), optarg, " ", -1);
|
||||
protocolfilter = wmem_strsplit(wmem_epan_scope(), ws_optarg, " ", -1);
|
||||
break;
|
||||
case 'W': /* Select extra information to save in our capture file */
|
||||
/* This is patterned after the -N flag which may not be the best idea. */
|
||||
if (strchr(optarg, 'n')) {
|
||||
if (strchr(ws_optarg, 'n')) {
|
||||
out_file_name_res = TRUE;
|
||||
} else {
|
||||
cmdarg_err("Invalid -W argument \"%s\"; it must be one of:", optarg);
|
||||
cmdarg_err("Invalid -W argument \"%s\"; it must be one of:", ws_optarg);
|
||||
cmdarg_err_cont("\t'n' write network address resolution information (pcapng only)");
|
||||
exit_status = INVALID_OPTION;
|
||||
goto clean_exit;
|
||||
}
|
||||
break;
|
||||
case 'H': /* Read address to name mappings from a hosts file */
|
||||
if (! add_hosts_file(optarg))
|
||||
if (! add_hosts_file(ws_optarg))
|
||||
{
|
||||
cmdarg_err("Can't read host entries from \"%s\"", optarg);
|
||||
cmdarg_err("Can't read host entries from \"%s\"", ws_optarg);
|
||||
exit_status = INVALID_OPTION;
|
||||
goto clean_exit;
|
||||
}
|
||||
|
@ -1279,13 +1256,13 @@ main(int argc, char *argv[])
|
|||
{
|
||||
char *errmsg = NULL;
|
||||
|
||||
switch (prefs_set_pref(optarg, &errmsg)) {
|
||||
switch (prefs_set_pref(ws_optarg, &errmsg)) {
|
||||
|
||||
case PREFS_SET_OK:
|
||||
break;
|
||||
|
||||
case PREFS_SET_SYNTAX_ERR:
|
||||
cmdarg_err("Invalid -o flag \"%s\"%s%s", optarg,
|
||||
cmdarg_err("Invalid -o flag \"%s\"%s%s", ws_optarg,
|
||||
errmsg ? ": " : "", errmsg ? errmsg : "");
|
||||
g_free(errmsg);
|
||||
exit_status = INVALID_OPTION;
|
||||
|
@ -1294,7 +1271,7 @@ main(int argc, char *argv[])
|
|||
|
||||
case PREFS_SET_NO_SUCH_PREF:
|
||||
case PREFS_SET_OBSOLETE:
|
||||
cmdarg_err("-o flag \"%s\" specifies unknown preference", optarg);
|
||||
cmdarg_err("-o flag \"%s\" specifies unknown preference", ws_optarg);
|
||||
exit_status = INVALID_OPTION;
|
||||
goto clean_exit;
|
||||
break;
|
||||
|
@ -1312,13 +1289,13 @@ main(int argc, char *argv[])
|
|||
/* already processed; just ignore it now */
|
||||
break;
|
||||
case 'R': /* Read file filter */
|
||||
rfilter = optarg;
|
||||
rfilter = ws_optarg;
|
||||
break;
|
||||
case 'P':
|
||||
/* already processed; just ignore it now */
|
||||
break;
|
||||
case 'S': /* Set the line Separator to be printed between packets */
|
||||
separator = optarg;
|
||||
separator = ws_optarg;
|
||||
break;
|
||||
case 'T': /* printing Type */
|
||||
/* output_action has been already set. It means multiple -T. */
|
||||
|
@ -1328,43 +1305,43 @@ main(int argc, char *argv[])
|
|||
goto clean_exit;
|
||||
}
|
||||
print_packet_info = TRUE;
|
||||
if (strcmp(optarg, "text") == 0) {
|
||||
if (strcmp(ws_optarg, "text") == 0) {
|
||||
output_action = WRITE_TEXT;
|
||||
print_format = PR_FMT_TEXT;
|
||||
} else if (strcmp(optarg, "tabs") == 0) {
|
||||
} else if (strcmp(ws_optarg, "tabs") == 0) {
|
||||
output_action = WRITE_TEXT;
|
||||
print_format = PR_FMT_TEXT;
|
||||
delimiter_char = "\t";
|
||||
} else if (strcmp(optarg, "ps") == 0) {
|
||||
} else if (strcmp(ws_optarg, "ps") == 0) {
|
||||
output_action = WRITE_TEXT;
|
||||
print_format = PR_FMT_PS;
|
||||
} else if (strcmp(optarg, "pdml") == 0) {
|
||||
} else if (strcmp(ws_optarg, "pdml") == 0) {
|
||||
output_action = WRITE_XML;
|
||||
print_details = TRUE; /* Need details */
|
||||
print_summary = FALSE; /* Don't allow summary */
|
||||
} else if (strcmp(optarg, "psml") == 0) {
|
||||
} else if (strcmp(ws_optarg, "psml") == 0) {
|
||||
output_action = WRITE_XML;
|
||||
print_details = FALSE; /* Don't allow details */
|
||||
print_summary = TRUE; /* Need summary */
|
||||
} else if (strcmp(optarg, "fields") == 0) {
|
||||
} else if (strcmp(ws_optarg, "fields") == 0) {
|
||||
output_action = WRITE_FIELDS;
|
||||
print_details = TRUE; /* Need full tree info */
|
||||
print_summary = FALSE; /* Don't allow summary */
|
||||
} else if (strcmp(optarg, "json") == 0) {
|
||||
} else if (strcmp(ws_optarg, "json") == 0) {
|
||||
output_action = WRITE_JSON;
|
||||
print_details = TRUE; /* Need details */
|
||||
print_summary = FALSE; /* Don't allow summary */
|
||||
} else if (strcmp(optarg, "ek") == 0) {
|
||||
} else if (strcmp(ws_optarg, "ek") == 0) {
|
||||
output_action = WRITE_EK;
|
||||
if (!print_summary)
|
||||
print_details = TRUE;
|
||||
} else if (strcmp(optarg, "jsonraw") == 0) {
|
||||
} else if (strcmp(ws_optarg, "jsonraw") == 0) {
|
||||
output_action = WRITE_JSON_RAW;
|
||||
print_details = TRUE; /* Need details */
|
||||
print_summary = FALSE; /* Don't allow summary */
|
||||
}
|
||||
else {
|
||||
cmdarg_err("Invalid -T parameter \"%s\"; it must be one of:", optarg); /* x */
|
||||
cmdarg_err("Invalid -T parameter \"%s\"; it must be one of:", ws_optarg); /* x */
|
||||
cmdarg_err_cont("\t\"fields\" The values of fields specified with the -e option, in a form\n"
|
||||
"\t specified by the -E option.\n"
|
||||
"\t\"pdml\" Packet Details Markup Language, an XML-based format for the\n"
|
||||
|
@ -1398,12 +1375,12 @@ main(int argc, char *argv[])
|
|||
}
|
||||
break;
|
||||
case 'U': /* Export PDUs to file */
|
||||
if (strcmp(optarg, "") == 0 || strcmp(optarg, "?") == 0) {
|
||||
if (strcmp(ws_optarg, "") == 0 || strcmp(ws_optarg, "?") == 0) {
|
||||
list_export_pdu_taps();
|
||||
exit_status = INVALID_OPTION;
|
||||
goto clean_exit;
|
||||
}
|
||||
pdu_export_arg = g_strdup(optarg);
|
||||
pdu_export_arg = g_strdup(ws_optarg);
|
||||
break;
|
||||
case 'v': /* Show version and exit */
|
||||
show_version();
|
||||
|
@ -1429,7 +1406,7 @@ main(int argc, char *argv[])
|
|||
/* already processed; just ignore it now */
|
||||
break;
|
||||
case 'Y':
|
||||
dfilter = g_strdup(optarg);
|
||||
dfilter = g_strdup(ws_optarg);
|
||||
break;
|
||||
case 'z':
|
||||
/* We won't call the init function for the stat this soon
|
||||
|
@ -1437,14 +1414,14 @@ main(int argc, char *argv[])
|
|||
by the preferences set callback) from being used as
|
||||
part of a tap filter. Instead, we just add the argument
|
||||
to a list of stat arguments. */
|
||||
if (strcmp("help", optarg) == 0) {
|
||||
if (strcmp("help", ws_optarg) == 0) {
|
||||
fprintf(stderr, "tshark: The available statistics for the \"-z\" option are:\n");
|
||||
list_stat_cmd_args();
|
||||
exit_status = EXIT_SUCCESS;
|
||||
goto clean_exit;
|
||||
}
|
||||
if (!process_stat_cmd_arg(optarg)) {
|
||||
cmdarg_err("Invalid -z argument \"%s\"; it must be one of:", optarg);
|
||||
if (!process_stat_cmd_arg(ws_optarg)) {
|
||||
cmdarg_err("Invalid -z argument \"%s\"; it must be one of:", ws_optarg);
|
||||
list_stat_cmd_args();
|
||||
exit_status = INVALID_OPTION;
|
||||
goto clean_exit;
|
||||
|
@ -1460,25 +1437,25 @@ main(int argc, char *argv[])
|
|||
case LONGOPT_ENABLE_HEURISTIC: /* enable heuristic dissection of protocol */
|
||||
case LONGOPT_DISABLE_HEURISTIC: /* disable heuristic dissection of protocol */
|
||||
case LONGOPT_ENABLE_PROTOCOL: /* enable dissection of protocol (that is disabled by default) */
|
||||
if (!dissect_opts_handle_opt(opt, optarg)) {
|
||||
if (!dissect_opts_handle_opt(opt, ws_optarg)) {
|
||||
exit_status = INVALID_OPTION;
|
||||
goto clean_exit;
|
||||
}
|
||||
break;
|
||||
case LONGOPT_EXPORT_OBJECTS: /* --export-objects */
|
||||
if (strcmp("help", optarg) == 0) {
|
||||
if (strcmp("help", ws_optarg) == 0) {
|
||||
fprintf(stderr, "tshark: The available export object types for the \"--export-objects\" option are:\n");
|
||||
eo_list_object_types();
|
||||
exit_status = EXIT_SUCCESS;
|
||||
goto clean_exit;
|
||||
}
|
||||
if (!eo_tap_opt_add(optarg)) {
|
||||
if (!eo_tap_opt_add(ws_optarg)) {
|
||||
exit_status = INVALID_OPTION;
|
||||
goto clean_exit;
|
||||
}
|
||||
break;
|
||||
case LONGOPT_EXPORT_TLS_SESSION_KEYS: /* --export-tls-session-keys */
|
||||
tls_session_keys_file = optarg;
|
||||
tls_session_keys_file = ws_optarg;
|
||||
break;
|
||||
case LONGOPT_COLOR: /* print in color where appropriate */
|
||||
dissect_color = TRUE;
|
||||
|
@ -1491,11 +1468,11 @@ 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;
|
||||
default:
|
||||
case '?': /* Bad flag - print usage message */
|
||||
switch(optopt) {
|
||||
switch(ws_optopt) {
|
||||
case 'F':
|
||||
list_capture_types();
|
||||
break;
|
||||
|
@ -1556,7 +1533,7 @@ main(int argc, char *argv[])
|
|||
still command-line arguments, treat them as the tokens of a capture
|
||||
filter (if no "-r" flag was specified) or a display filter (if a "-r"
|
||||
flag was specified. */
|
||||
if (optind < argc) {
|
||||
if (ws_optind < argc) {
|
||||
if (cf_name != NULL) {
|
||||
if (dfilter != NULL) {
|
||||
cmdarg_err("Display filters were specified both with \"-Y\" "
|
||||
|
@ -1564,7 +1541,7 @@ main(int argc, char *argv[])
|
|||
exit_status = INVALID_OPTION;
|
||||
goto clean_exit;
|
||||
}
|
||||
dfilter = get_args_as_string(argc, argv, optind);
|
||||
dfilter = get_args_as_string(argc, argv, ws_optind);
|
||||
} else {
|
||||
#ifdef HAVE_LIBPCAP
|
||||
guint i;
|
||||
|
@ -1579,7 +1556,7 @@ main(int argc, char *argv[])
|
|||
interface_options *interface_opts;
|
||||
interface_opts = &g_array_index(global_capture_opts.ifaces, interface_options, i);
|
||||
if (interface_opts->cfilter == NULL) {
|
||||
interface_opts->cfilter = get_args_as_string(argc, argv, optind);
|
||||
interface_opts->cfilter = get_args_as_string(argc, argv, ws_optind);
|
||||
} else {
|
||||
cmdarg_err("A capture filter was specified both with \"-f\""
|
||||
" and with additional command-line arguments.");
|
||||
|
@ -1587,7 +1564,7 @@ main(int argc, char *argv[])
|
|||
goto clean_exit;
|
||||
}
|
||||
}
|
||||
global_capture_opts.default_options.cfilter = get_args_as_string(argc, argv, optind);
|
||||
global_capture_opts.default_options.cfilter = get_args_as_string(argc, argv, ws_optind);
|
||||
#else
|
||||
capture_option_specified = TRUE;
|
||||
#endif
|
||||
|
|
|
@ -17,7 +17,7 @@ extern "C" {
|
|||
void eo_list_object_types(void);
|
||||
|
||||
/* will be called by main each time a --export-objects option is found */
|
||||
gboolean eo_tap_opt_add(const char *optarg);
|
||||
gboolean eo_tap_opt_add(const char *ws_optarg);
|
||||
|
||||
void start_exportobjects(void);
|
||||
|
||||
|
|
|
@ -16,18 +16,7 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.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 <ui/version_info.h>
|
||||
|
||||
|
@ -247,7 +236,7 @@ void commandline_early_options(int argc, char *argv[])
|
|||
* arguments have not been removed from the argument list; those arguments
|
||||
* begin with "--", and will be treated as an error by getopt_long().
|
||||
*
|
||||
* We thus ignore errors - *and* set "opterr" to 0 to suppress the
|
||||
* We thus ignore errors - *and* set "ws_opterr" to 0 to suppress the
|
||||
* error messages.
|
||||
*
|
||||
* In order to handle, for example, -o options, we also need to call it
|
||||
|
@ -263,18 +252,18 @@ void commandline_early_options(int argc, char *argv[])
|
|||
* GUI is up, as that can take a while, and we want a window of some
|
||||
* sort up to show progress while that's happening.
|
||||
*/
|
||||
opterr = 0;
|
||||
ws_opterr = 0;
|
||||
|
||||
#ifndef HAVE_LIBPCAP
|
||||
capture_option_specified = FALSE;
|
||||
#endif
|
||||
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 'C': /* Configuration Profile */
|
||||
if (profile_exists (optarg, FALSE)) {
|
||||
set_profile_name (optarg);
|
||||
if (profile_exists (ws_optarg, FALSE)) {
|
||||
set_profile_name (ws_optarg);
|
||||
} else {
|
||||
cmdarg_err("Configuration Profile \"%s\" does not exist", optarg);
|
||||
cmdarg_err("Configuration Profile \"%s\" does not exist", ws_optarg);
|
||||
exit(1);
|
||||
}
|
||||
break;
|
||||
|
@ -309,13 +298,13 @@ void commandline_early_options(int argc, char *argv[])
|
|||
break;
|
||||
#ifdef _WIN32
|
||||
case 'i':
|
||||
if (strcmp(optarg, "-") == 0)
|
||||
if (strcmp(ws_optarg, "-") == 0)
|
||||
set_stdin_capture(TRUE);
|
||||
break;
|
||||
#endif
|
||||
case 'P': /* Personal file directory path settings - change these before the Preferences and alike are processed */
|
||||
if (!persfilepath_opt(opt, optarg)) {
|
||||
cmdarg_err("-P flag \"%s\" failed (hint: is it quoted and existing?)", optarg);
|
||||
if (!persfilepath_opt(opt, ws_optarg)) {
|
||||
cmdarg_err("-P flag \"%s\" failed (hint: is it quoted and existing?)", ws_optarg);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
break;
|
||||
|
@ -335,7 +324,7 @@ void commandline_early_options(int argc, char *argv[])
|
|||
* we call epan_init() as they are supposed to be used by dissectors
|
||||
* or taps very early in the registration process.
|
||||
*/
|
||||
ex_opt_add(optarg);
|
||||
ex_opt_add(ws_optarg);
|
||||
break;
|
||||
case '?': /* Ignore errors - the "real" scan will catch them. */
|
||||
break;
|
||||
|
@ -370,23 +359,15 @@ void commandline_other_options(int argc, char *argv[], gboolean opt_reset)
|
|||
#endif
|
||||
|
||||
/*
|
||||
* To reset the options parser, set optreset to 1 on platforms that
|
||||
* have optreset (documented in *BSD and macOS, apparently present but
|
||||
* not documented in Solaris - the Illumos repository seems to
|
||||
* suggest that the first Solaris getopt_long(), at least as of 2004,
|
||||
* was based on the NetBSD one, it had optreset) and set optind to 1,
|
||||
* and set optind to 0 otherwise (documented as working in the GNU
|
||||
* getopt_long(). Setting optind to 0 didn't originally work in the
|
||||
* NetBSD one, but that was added later - we don't want to depend on
|
||||
* it if we have optreset).
|
||||
* To reset the options parser, set ws_optreset to 1 and set ws_optind to 1.
|
||||
*
|
||||
* Also reset opterr to 1, so that error messages are printed by
|
||||
* Also reset ws_opterr to 1, so that error messages are printed by
|
||||
* getopt_long().
|
||||
*
|
||||
* XXX - if we want to control all the command-line option errors, so
|
||||
* that we can display them where we choose (e.g., in a window), we'd
|
||||
* want to leave opterr as 0, and produce our own messages using optopt.
|
||||
* We'd have to check the value of optopt to see if it's a valid option
|
||||
* want to leave ws_opterr as 0, and produce our own messages using ws_optopt.
|
||||
* We'd have to check the value of ws_optopt to see if it's a valid option
|
||||
* letter, in which case *presumably* the error is "this option requires
|
||||
* an argument but none was specified", or not a valid option letter,
|
||||
* in which case *presumably* the error is "this option isn't valid".
|
||||
|
@ -396,13 +377,9 @@ void commandline_other_options(int argc, char *argv[], gboolean opt_reset)
|
|||
* not all do. But we're now using getopt_long() - what does it do?
|
||||
*/
|
||||
if (opt_reset) {
|
||||
#ifdef HAVE_OPTRESET
|
||||
optreset = 1;
|
||||
optind = 1;
|
||||
#else
|
||||
optind = 0;
|
||||
#endif
|
||||
opterr = 1;
|
||||
ws_optreset = 1;
|
||||
ws_optind = 1;
|
||||
ws_opterr = 1;
|
||||
}
|
||||
|
||||
/* Initialize with default values */
|
||||
|
@ -423,7 +400,7 @@ void commandline_other_options(int argc, char *argv[], gboolean opt_reset)
|
|||
global_commandline_info.full_screen = FALSE;
|
||||
global_commandline_info.user_opts = NULL;
|
||||
|
||||
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) {
|
||||
/*** capture option specific ***/
|
||||
case 'a': /* autostop criteria */
|
||||
|
@ -448,7 +425,7 @@ void commandline_other_options(int argc, char *argv[], gboolean opt_reset)
|
|||
case 'B': /* Buffer size */
|
||||
#endif
|
||||
#ifdef HAVE_LIBPCAP
|
||||
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_application(status);
|
||||
}
|
||||
|
@ -466,10 +443,10 @@ void commandline_other_options(int argc, char *argv[], gboolean opt_reset)
|
|||
global_commandline_info.jump_backwards = SD_BACKWARD;
|
||||
break;
|
||||
case 'g': /* Go to packet with the given packet number */
|
||||
global_commandline_info.go_to_packet = get_nonzero_guint32(optarg, "go to packet");
|
||||
global_commandline_info.go_to_packet = get_nonzero_guint32(ws_optarg, "go to packet");
|
||||
break;
|
||||
case 'J': /* Jump to the first packet which matches the filter criteria */
|
||||
global_commandline_info.jfilter = optarg;
|
||||
global_commandline_info.jfilter = ws_optarg;
|
||||
break;
|
||||
case 'k': /* Start capture immediately */
|
||||
#ifdef HAVE_LIBPCAP
|
||||
|
@ -509,32 +486,32 @@ void commandline_other_options(int argc, char *argv[], gboolean opt_reset)
|
|||
{
|
||||
char *errmsg = NULL;
|
||||
|
||||
switch (prefs_set_pref(optarg, &errmsg)) {
|
||||
switch (prefs_set_pref(ws_optarg, &errmsg)) {
|
||||
case PREFS_SET_OK:
|
||||
global_commandline_info.user_opts =
|
||||
g_slist_prepend(global_commandline_info.user_opts,
|
||||
g_strdup(optarg));
|
||||
g_strdup(ws_optarg));
|
||||
break;
|
||||
case PREFS_SET_SYNTAX_ERR:
|
||||
cmdarg_err("Invalid -o flag \"%s\"%s%s", optarg,
|
||||
cmdarg_err("Invalid -o flag \"%s\"%s%s", ws_optarg,
|
||||
errmsg ? ": " : "", errmsg ? errmsg : "");
|
||||
g_free(errmsg);
|
||||
exit_application(1);
|
||||
break;
|
||||
case PREFS_SET_NO_SUCH_PREF:
|
||||
/* not a preference, might be a recent setting */
|
||||
switch (recent_set_arg(optarg)) {
|
||||
switch (recent_set_arg(ws_optarg)) {
|
||||
case PREFS_SET_OK:
|
||||
break;
|
||||
case PREFS_SET_SYNTAX_ERR:
|
||||
/* shouldn't happen, checked already above */
|
||||
cmdarg_err("Invalid -o flag \"%s\"", optarg);
|
||||
cmdarg_err("Invalid -o flag \"%s\"", ws_optarg);
|
||||
exit_application(1);
|
||||
break;
|
||||
case PREFS_SET_NO_SUCH_PREF:
|
||||
case PREFS_SET_OBSOLETE:
|
||||
cmdarg_err("-o flag \"%s\" specifies unknown preference/recent value",
|
||||
optarg);
|
||||
ws_optarg);
|
||||
exit_application(1);
|
||||
break;
|
||||
default:
|
||||
|
@ -543,7 +520,7 @@ void commandline_other_options(int argc, char *argv[], gboolean opt_reset)
|
|||
break;
|
||||
case PREFS_SET_OBSOLETE:
|
||||
cmdarg_err("-o flag \"%s\" specifies obsolete preference",
|
||||
optarg);
|
||||
ws_optarg);
|
||||
exit_application(1);
|
||||
break;
|
||||
default:
|
||||
|
@ -558,16 +535,16 @@ void commandline_other_options(int argc, char *argv[], gboolean opt_reset)
|
|||
/* We may set "last_open_dir" to "cf_name", and if we change
|
||||
"last_open_dir" later, we free the old value, so we have to
|
||||
set "cf_name" to something that's been allocated. */
|
||||
global_commandline_info.cf_name = g_strdup(optarg);
|
||||
global_commandline_info.cf_name = g_strdup(ws_optarg);
|
||||
break;
|
||||
case 'R': /* Read file filter */
|
||||
global_commandline_info.rfilter = optarg;
|
||||
global_commandline_info.rfilter = ws_optarg;
|
||||
break;
|
||||
case 'X':
|
||||
/* ext ops were already processed just ignore them this time*/
|
||||
break;
|
||||
case 'Y':
|
||||
global_commandline_info.dfilter = optarg;
|
||||
global_commandline_info.dfilter = ws_optarg;
|
||||
break;
|
||||
case 'z':
|
||||
/* We won't call the init function for the stat this soon
|
||||
|
@ -575,12 +552,12 @@ void commandline_other_options(int argc, char *argv[], gboolean opt_reset)
|
|||
by the preferences set callback) from being used as
|
||||
part of a tap filter. Instead, we just add the argument
|
||||
to a list of stat arguments. */
|
||||
if (strcmp("help", optarg) == 0) {
|
||||
if (strcmp("help", ws_optarg) == 0) {
|
||||
fprintf(stderr, "wireshark: The available statistics for the \"-z\" option are:\n");
|
||||
list_stat_cmd_args();
|
||||
exit_application(0);
|
||||
}
|
||||
if (!process_stat_cmd_arg(optarg)) {
|
||||
if (!process_stat_cmd_arg(ws_optarg)) {
|
||||
cmdarg_err("Invalid -z argument.");
|
||||
cmdarg_err_cont(" -z argument must be one of :");
|
||||
list_stat_cmd_args();
|
||||
|
@ -597,7 +574,7 @@ void commandline_other_options(int argc, char *argv[], gboolean opt_reset)
|
|||
case LONGOPT_ENABLE_HEURISTIC: /* enable heuristic dissection of protocol */
|
||||
case LONGOPT_DISABLE_HEURISTIC: /* disable heuristic dissection of protocol */
|
||||
case LONGOPT_ENABLE_PROTOCOL: /* enable dissection of protocol (that is disabled by default) */
|
||||
if (!dissect_opts_handle_opt(opt, optarg))
|
||||
if (!dissect_opts_handle_opt(opt, ws_optarg))
|
||||
exit_application(1);
|
||||
break;
|
||||
case LONGOPT_FULL_SCREEN:
|
||||
|
@ -608,7 +585,7 @@ void commandline_other_options(int argc, char *argv[], gboolean opt_reset)
|
|||
if (global_commandline_info.capture_comments == NULL) {
|
||||
global_commandline_info.capture_comments = g_ptr_array_new_with_free_func(g_free);
|
||||
}
|
||||
g_ptr_array_add(global_commandline_info.capture_comments, g_strdup(optarg));
|
||||
g_ptr_array_add(global_commandline_info.capture_comments, g_strdup(ws_optarg));
|
||||
#else
|
||||
capture_option_specified = TRUE;
|
||||
arg_error = TRUE;
|
||||
|
@ -627,8 +604,8 @@ void commandline_other_options(int argc, char *argv[], gboolean opt_reset)
|
|||
global_commandline_info.user_opts = g_slist_reverse(global_commandline_info.user_opts);
|
||||
|
||||
if (!arg_error) {
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
argc -= ws_optind;
|
||||
argv += ws_optind;
|
||||
if (argc >= 1) {
|
||||
if (global_commandline_info.cf_name != NULL) {
|
||||
/*
|
||||
|
|
|
@ -21,19 +21,6 @@
|
|||
#include "ui/win32/console_win32.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 <ui/clopts_common.h>
|
||||
#include <ui/cmdarg_err.h>
|
||||
#include <ui/exit_codes.h>
|
||||
|
|
|
@ -72,6 +72,7 @@ set(WSUTIL_PUBLIC_HEADERS
|
|||
ws_assert.h
|
||||
ws_cpuid.h
|
||||
glib-compat.h
|
||||
ws_getopt.h
|
||||
ws_mempbrk.h
|
||||
ws_mempbrk_int.h
|
||||
ws_pipe.h
|
||||
|
@ -128,6 +129,8 @@ set(WSUTIL_COMMON_FILES
|
|||
unicode-utils.c
|
||||
glib-compat.c
|
||||
ws_assert.c
|
||||
ws_getopt.c
|
||||
ws_getopt_long.c
|
||||
ws_mempbrk.c
|
||||
ws_pipe.c
|
||||
wsgcrypt.c
|
||||
|
@ -220,10 +223,6 @@ if(HAVE_SSE4_2)
|
|||
list(APPEND WSUTIL_FILES ws_mempbrk_sse42.c)
|
||||
endif()
|
||||
|
||||
if(NOT HAVE_GETOPT_LONG)
|
||||
list(APPEND WSUTIL_FILES getopt_long.c)
|
||||
endif()
|
||||
|
||||
if(NOT HAVE_STRPTIME)
|
||||
list(APPEND WSUTIL_FILES strptime.c)
|
||||
endif()
|
||||
|
|
1310
wsutil/getopt_long.c
1310
wsutil/getopt_long.c
File diff suppressed because it is too large
Load Diff
|
@ -1,122 +0,0 @@
|
|||
/*
|
||||
Copied from glibc-2.15
|
||||
|
||||
Internal declarations for getopt.
|
||||
Copyright (C) 1989-1994,1996-1999,2001,2003,2004,2009
|
||||
Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
SPDX-License-Identifier: LGPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#ifndef _GETOPT_INT_H
|
||||
#define _GETOPT_INT_H 1
|
||||
|
||||
extern int _getopt_internal (int ___argc, char *const *___argv,
|
||||
const char *__shortopts,
|
||||
const struct option *__longopts, int *__longind,
|
||||
int __long_only, int posixly_correct);
|
||||
|
||||
|
||||
/* Reentrant versions which can handle parsing multiple argument
|
||||
vectors at the same time. */
|
||||
|
||||
/* Data type for reentrant functions. */
|
||||
struct _getopt_data
|
||||
{
|
||||
/* These have exactly the same meaning as the corresponding global
|
||||
variables, except that they are used for the reentrant
|
||||
versions of getopt. */
|
||||
int optind;
|
||||
int opterr;
|
||||
int optopt;
|
||||
char *optarg;
|
||||
|
||||
/* Internal members. */
|
||||
|
||||
/* True if the internal members have been initialized. */
|
||||
int __initialized;
|
||||
|
||||
/* The next char to be scanned in the option-element
|
||||
in which the last option character we returned was found.
|
||||
This allows us to pick up the scan where we left off.
|
||||
|
||||
If this is zero, or a null string, it means resume the scan
|
||||
by advancing to the next ARGV-element. */
|
||||
char *__nextchar;
|
||||
|
||||
/* Describe how to deal with options that follow non-option ARGV-elements.
|
||||
|
||||
If the caller did not specify anything,
|
||||
the default is REQUIRE_ORDER if the environment variable
|
||||
POSIXLY_CORRECT is defined, PERMUTE otherwise.
|
||||
|
||||
REQUIRE_ORDER means don't recognize them as options;
|
||||
stop option processing when the first non-option is seen.
|
||||
This is what Unix does.
|
||||
This mode of operation is selected by either setting the environment
|
||||
variable POSIXLY_CORRECT, or using `+' as the first character
|
||||
of the list of option characters.
|
||||
|
||||
PERMUTE is the default. We permute the contents of ARGV as we
|
||||
scan, so that eventually all the non-options are at the end.
|
||||
This allows options to be given in any order, even with programs
|
||||
that were not written to expect this.
|
||||
|
||||
RETURN_IN_ORDER is an option available to programs that were
|
||||
written to expect options and other ARGV-elements in any order
|
||||
and that care about the ordering of the two. We describe each
|
||||
non-option ARGV-element as if it were the argument of an option
|
||||
with character code 1. Using `-' as the first character of the
|
||||
list of option characters selects this mode of operation.
|
||||
|
||||
The special argument `--' forces an end of option-scanning regardless
|
||||
of the value of `ordering'. In the case of RETURN_IN_ORDER, only
|
||||
`--' can cause `getopt' to return -1 with `optind' != ARGC. */
|
||||
|
||||
enum
|
||||
{
|
||||
REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER
|
||||
} __ordering;
|
||||
|
||||
/* If the POSIXLY_CORRECT environment variable is set. */
|
||||
int __posixly_correct;
|
||||
|
||||
|
||||
/* Handle permutation of arguments. */
|
||||
|
||||
/* Describe the part of ARGV that contains non-options that have
|
||||
been skipped. `first_nonopt' is the index in ARGV of the first
|
||||
of them; `last_nonopt' is the index after the last of them. */
|
||||
|
||||
int __first_nonopt;
|
||||
int __last_nonopt;
|
||||
|
||||
#if defined _LIBC && defined USE_NONOPTION_FLAGS
|
||||
int __nonoption_flags_max_len;
|
||||
int __nonoption_flags_len;
|
||||
# endif
|
||||
};
|
||||
|
||||
/* The initializer is necessary to set OPTIND and OPTERR to their
|
||||
default values and to clear the initialization flag. */
|
||||
#define _GETOPT_DATA_INITIALIZER { 1, 1 }
|
||||
|
||||
extern int _getopt_internal_r (int ___argc, char *const *___argv,
|
||||
const char *__shortopts,
|
||||
const struct option *__longopts, int *__longind,
|
||||
int __long_only, struct _getopt_data *__data,
|
||||
int posixly_correct);
|
||||
|
||||
extern int _getopt_long_r (int ___argc, char *const *___argv,
|
||||
const char *__shortopts,
|
||||
const struct option *__longopts, int *__longind,
|
||||
struct _getopt_data *__data);
|
||||
|
||||
extern int _getopt_long_only_r (int ___argc, char *const *___argv,
|
||||
const char *__shortopts,
|
||||
const struct option *__longopts,
|
||||
int *__longind,
|
||||
struct _getopt_data *__data);
|
||||
|
||||
#endif /* getopt_int.h */
|
|
@ -1,71 +1,93 @@
|
|||
#define _BSD_SOURCE
|
||||
#include <unistd.h>
|
||||
/*
|
||||
* musl as a whole is licensed under the following standard MIT license:
|
||||
*
|
||||
* ----------------------------------------------------------------------
|
||||
* Copyright © 2005-2020 Rich Felker, et al.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
* ----------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//#define _BSD_SOURCE
|
||||
//#include <unistd.h>
|
||||
#include <wchar.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
#include "locale_impl.h"
|
||||
#include "stdio_impl.h"
|
||||
#include <stdio.h>
|
||||
|
||||
char *optarg;
|
||||
int optind=1, opterr=1, optopt, __optpos, __optreset=0;
|
||||
#include <wsutil/ws_getopt.h>
|
||||
|
||||
#define optpos __optpos
|
||||
weak_alias(__optreset, optreset);
|
||||
char *ws_optarg;
|
||||
int ws_optind=1, ws_opterr=1, ws_optopt, ws_optpos, ws_optreset=0;
|
||||
|
||||
void __getopt_msg(const char *a, const char *b, const char *c, size_t l)
|
||||
{
|
||||
FILE *f = stderr;
|
||||
b = __lctrans_cur(b);
|
||||
FLOCK(f);
|
||||
fputs(a, f)>=0
|
||||
&& fwrite(b, strlen(b), 1, f)
|
||||
&& fwrite(c, 1, l, f)==l
|
||||
&& putc('\n', f);
|
||||
FUNLOCK(f);
|
||||
fputs(a, f);
|
||||
fwrite(b, strlen(b), 1, f);
|
||||
fwrite(c, 1, l, f);
|
||||
putc('\n', f);
|
||||
}
|
||||
|
||||
int getopt(int argc, char * const argv[], const char *optstring)
|
||||
int ws_getopt(int argc, char * const argv[], const char *optstring)
|
||||
{
|
||||
int i;
|
||||
wchar_t c, d;
|
||||
int k, l;
|
||||
char *optchar;
|
||||
|
||||
if (!optind || __optreset) {
|
||||
__optreset = 0;
|
||||
__optpos = 0;
|
||||
optind = 1;
|
||||
if (!ws_optind || ws_optreset) {
|
||||
ws_optreset = 0;
|
||||
ws_optpos = 0;
|
||||
ws_optind = 1;
|
||||
}
|
||||
|
||||
if (optind >= argc || !argv[optind])
|
||||
if (ws_optind >= argc || !argv[ws_optind])
|
||||
return -1;
|
||||
|
||||
if (argv[optind][0] != '-') {
|
||||
if (argv[ws_optind][0] != '-') {
|
||||
if (optstring[0] == '-') {
|
||||
optarg = argv[optind++];
|
||||
ws_optarg = argv[ws_optind++];
|
||||
return 1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!argv[optind][1])
|
||||
if (!argv[ws_optind][1])
|
||||
return -1;
|
||||
|
||||
if (argv[optind][1] == '-' && !argv[optind][2])
|
||||
return optind++, -1;
|
||||
if (argv[ws_optind][1] == '-' && !argv[ws_optind][2])
|
||||
return ws_optind++, -1;
|
||||
|
||||
if (!optpos) optpos++;
|
||||
if ((k = mbtowc(&c, argv[optind]+optpos, MB_LEN_MAX)) < 0) {
|
||||
if (!ws_optpos) ws_optpos++;
|
||||
if ((k = mbtowc(&c, argv[ws_optind]+ws_optpos, MB_LEN_MAX)) < 0) {
|
||||
k = 1;
|
||||
c = 0xfffd; /* replacement char */
|
||||
}
|
||||
optchar = argv[optind]+optpos;
|
||||
optpos += k;
|
||||
optchar = argv[ws_optind]+ws_optpos;
|
||||
ws_optpos += k;
|
||||
|
||||
if (!argv[optind][optpos]) {
|
||||
optind++;
|
||||
optpos = 0;
|
||||
if (!argv[ws_optind][ws_optpos]) {
|
||||
ws_optind++;
|
||||
ws_optpos = 0;
|
||||
}
|
||||
|
||||
if (optstring[0] == '-' || optstring[0] == '+')
|
||||
|
@ -79,21 +101,21 @@ int getopt(int argc, char * const argv[], const char *optstring)
|
|||
} while (l && d != c);
|
||||
|
||||
if (d != c || c == ':') {
|
||||
optopt = c;
|
||||
if (optstring[0] != ':' && opterr)
|
||||
ws_optopt = c;
|
||||
if (optstring[0] != ':' && ws_opterr)
|
||||
__getopt_msg(argv[0], ": unrecognized option: ", optchar, k);
|
||||
return '?';
|
||||
}
|
||||
if (optstring[i] == ':') {
|
||||
optarg = 0;
|
||||
if (optstring[i+1] != ':' || optpos) {
|
||||
optarg = argv[optind++] + optpos;
|
||||
optpos = 0;
|
||||
ws_optarg = 0;
|
||||
if (optstring[i+1] != ':' || ws_optpos) {
|
||||
ws_optarg = argv[ws_optind++] + ws_optpos;
|
||||
ws_optpos = 0;
|
||||
}
|
||||
if (optind > argc) {
|
||||
optopt = c;
|
||||
if (ws_optind > argc) {
|
||||
ws_optopt = c;
|
||||
if (optstring[0] == ':') return ':';
|
||||
if (opterr) __getopt_msg(argv[0],
|
||||
if (ws_opterr) __getopt_msg(argv[0],
|
||||
": option requires an argument: ",
|
||||
optchar, k);
|
||||
return '?';
|
||||
|
@ -101,5 +123,3 @@ int getopt(int argc, char * const argv[], const char *optstring)
|
|||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
weak_alias(getopt, __posix_getopt);
|
||||
|
|
|
@ -1,13 +1,42 @@
|
|||
#ifndef _GETOPT_H
|
||||
#define _GETOPT_H
|
||||
/*
|
||||
* musl as a whole is licensed under the following standard MIT license:
|
||||
*
|
||||
* ----------------------------------------------------------------------
|
||||
* Copyright © 2005-2020 Rich Felker, et al.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
* ----------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#ifndef _WS_GETOPT_H_
|
||||
#define _WS_GETOPT_H_
|
||||
|
||||
#include <ws_symbol_export.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int getopt(int, char * const [], const char *);
|
||||
extern char *optarg;
|
||||
extern int optind, opterr, optopt, optreset;
|
||||
WS_DLL_PUBLIC int ws_getopt(int, char * const [], const char *);
|
||||
WS_DLL_PUBLIC char *ws_optarg;
|
||||
WS_DLL_PUBLIC int ws_optind, ws_opterr, ws_optopt, ws_optpos, ws_optreset;
|
||||
|
||||
struct option {
|
||||
const char *name;
|
||||
|
@ -16,8 +45,10 @@ struct option {
|
|||
int val;
|
||||
};
|
||||
|
||||
int getopt_long(int, char *const *, const char *, const struct option *, int *);
|
||||
int getopt_long_only(int, char *const *, const char *, const struct option *, int *);
|
||||
WS_DLL_PUBLIC int ws_getopt_long(int, char *const *, const char *, const struct option *, int *);
|
||||
WS_DLL_PUBLIC int ws_getopt_long_only(int, char *const *, const char *, const struct option *, int *);
|
||||
|
||||
WS_DLL_LOCAL void __getopt_msg(const char *a, const char *b, const char *c, size_t l);
|
||||
|
||||
#define no_argument 0
|
||||
#define required_argument 1
|
||||
|
|
|
@ -1,13 +1,39 @@
|
|||
#define _GNU_SOURCE
|
||||
/*
|
||||
* musl as a whole is licensed under the following standard MIT license:
|
||||
*
|
||||
* ----------------------------------------------------------------------
|
||||
* Copyright © 2005-2020 Rich Felker, et al.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
* ----------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
//#define _GNU_SOURCE
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
#include <getopt.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "stdio_impl.h"
|
||||
#include <stdio.h>
|
||||
|
||||
extern int __optpos, __optreset;
|
||||
#include <wsutil/ws_getopt.h>
|
||||
|
||||
static void permute(char *const *argv, int dest, int src)
|
||||
{
|
||||
|
@ -24,42 +50,42 @@ static int __getopt_long_core(int argc, char *const *argv, const char *optstring
|
|||
static int __getopt_long(int argc, char *const *argv, const char *optstring, const struct option *longopts, int *idx, int longonly)
|
||||
{
|
||||
int ret, skipped, resumed;
|
||||
if (!optind || __optreset) {
|
||||
__optreset = 0;
|
||||
__optpos = 0;
|
||||
optind = 1;
|
||||
if (!ws_optind || ws_optreset) {
|
||||
ws_optreset = 0;
|
||||
ws_optpos = 0;
|
||||
ws_optind = 1;
|
||||
}
|
||||
if (optind >= argc || !argv[optind]) return -1;
|
||||
skipped = optind;
|
||||
if (ws_optind >= argc || !argv[ws_optind]) return -1;
|
||||
skipped = ws_optind;
|
||||
if (optstring[0] != '+' && optstring[0] != '-') {
|
||||
int i;
|
||||
for (i=optind; ; i++) {
|
||||
for (i=ws_optind; ; i++) {
|
||||
if (i >= argc || !argv[i]) return -1;
|
||||
if (argv[i][0] == '-' && argv[i][1]) break;
|
||||
}
|
||||
optind = i;
|
||||
ws_optind = i;
|
||||
}
|
||||
resumed = optind;
|
||||
resumed = ws_optind;
|
||||
ret = __getopt_long_core(argc, argv, optstring, longopts, idx, longonly);
|
||||
if (resumed > skipped) {
|
||||
int i, cnt = optind-resumed;
|
||||
int i, cnt = ws_optind-resumed;
|
||||
for (i=0; i<cnt; i++)
|
||||
permute(argv, skipped, optind-1);
|
||||
optind = skipped + cnt;
|
||||
permute(argv, skipped, ws_optind-1);
|
||||
ws_optind = skipped + cnt;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int __getopt_long_core(int argc, char *const *argv, const char *optstring, const struct option *longopts, int *idx, int longonly)
|
||||
{
|
||||
optarg = 0;
|
||||
if (longopts && argv[optind][0] == '-' &&
|
||||
((longonly && argv[optind][1] && argv[optind][1] != '-') ||
|
||||
(argv[optind][1] == '-' && argv[optind][2])))
|
||||
ws_optarg = 0;
|
||||
if (longopts && argv[ws_optind][0] == '-' &&
|
||||
((longonly && argv[ws_optind][1] && argv[ws_optind][1] != '-') ||
|
||||
(argv[ws_optind][1] == '-' && argv[ws_optind][2])))
|
||||
{
|
||||
int colon = optstring[optstring[0]=='+'||optstring[0]=='-']==':';
|
||||
int i, cnt, match;
|
||||
char *arg, *opt, *start = argv[optind]+1;
|
||||
int i, cnt, match = -1;
|
||||
char *arg = NULL, *opt, *start = argv[ws_optind]+1;
|
||||
for (cnt=i=0; longopts[i].name; i++) {
|
||||
const char *name = longopts[i].name;
|
||||
opt = start;
|
||||
|
@ -89,11 +115,11 @@ static int __getopt_long_core(int argc, char *const *argv, const char *optstring
|
|||
if (cnt==1) {
|
||||
i = match;
|
||||
opt = arg;
|
||||
optind++;
|
||||
ws_optind++;
|
||||
if (*opt == '=') {
|
||||
if (!longopts[i].has_arg) {
|
||||
optopt = longopts[i].val;
|
||||
if (colon || !opterr)
|
||||
ws_optopt = longopts[i].val;
|
||||
if (colon || !ws_opterr)
|
||||
return '?';
|
||||
__getopt_msg(argv[0],
|
||||
": option does not take an argument: ",
|
||||
|
@ -101,19 +127,19 @@ static int __getopt_long_core(int argc, char *const *argv, const char *optstring
|
|||
strlen(longopts[i].name));
|
||||
return '?';
|
||||
}
|
||||
optarg = opt+1;
|
||||
ws_optarg = opt+1;
|
||||
} else if (longopts[i].has_arg == required_argument) {
|
||||
if (!(optarg = argv[optind])) {
|
||||
optopt = longopts[i].val;
|
||||
if (!(ws_optarg = argv[ws_optind])) {
|
||||
ws_optopt = longopts[i].val;
|
||||
if (colon) return ':';
|
||||
if (!opterr) return '?';
|
||||
if (!ws_opterr) return '?';
|
||||
__getopt_msg(argv[0],
|
||||
": option requires an argument: ",
|
||||
longopts[i].name,
|
||||
strlen(longopts[i].name));
|
||||
return '?';
|
||||
}
|
||||
optind++;
|
||||
ws_optind++;
|
||||
}
|
||||
if (idx) *idx = i;
|
||||
if (longopts[i].flag) {
|
||||
|
@ -122,27 +148,27 @@ static int __getopt_long_core(int argc, char *const *argv, const char *optstring
|
|||
}
|
||||
return longopts[i].val;
|
||||
}
|
||||
if (argv[optind][1] == '-') {
|
||||
optopt = 0;
|
||||
if (!colon && opterr)
|
||||
if (argv[ws_optind][1] == '-') {
|
||||
ws_optopt = 0;
|
||||
if (!colon && ws_opterr)
|
||||
__getopt_msg(argv[0], cnt ?
|
||||
": option is ambiguous: " :
|
||||
": unrecognized option: ",
|
||||
argv[optind]+2,
|
||||
strlen(argv[optind]+2));
|
||||
optind++;
|
||||
argv[ws_optind]+2,
|
||||
strlen(argv[ws_optind]+2));
|
||||
ws_optind++;
|
||||
return '?';
|
||||
}
|
||||
}
|
||||
return getopt(argc, argv, optstring);
|
||||
return ws_getopt(argc, argv, optstring);
|
||||
}
|
||||
|
||||
int getopt_long(int argc, char *const *argv, const char *optstring, const struct option *longopts, int *idx)
|
||||
int ws_getopt_long(int argc, char *const *argv, const char *optstring, const struct option *longopts, int *idx)
|
||||
{
|
||||
return __getopt_long(argc, argv, optstring, longopts, idx, 0);
|
||||
}
|
||||
|
||||
int getopt_long_only(int argc, char *const *argv, const char *optstring, const struct option *longopts, int *idx)
|
||||
int ws_getopt_long_only(int argc, char *const *argv, const char *optstring, const struct option *longopts, int *idx)
|
||||
{
|
||||
return __getopt_long(argc, argv, optstring, longopts, idx, 1);
|
||||
}
|
||||
|
|
|
@ -1,173 +0,0 @@
|
|||
/*
|
||||
Declarations for getopt.
|
||||
Copyright (C) 1989-1994,1996-1999,2001,2003,2004,2009,2010
|
||||
Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
SPDX-License-Identifier: LGPL-2.0-or-later */
|
||||
|
||||
#ifndef _GETOPT_H
|
||||
|
||||
#ifndef __need_getopt
|
||||
# define _GETOPT_H 1
|
||||
#endif
|
||||
|
||||
#include "ws_symbol_export.h"
|
||||
|
||||
#ifndef __THROW
|
||||
# ifndef __GNUC_PREREQ
|
||||
# define __GNUC_PREREQ(maj, min) (0)
|
||||
# endif
|
||||
# if defined __cplusplus && __GNUC_PREREQ (2,8)
|
||||
# define __THROW throw ()
|
||||
# else
|
||||
# define __THROW
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* For communication from `getopt' to the caller.
|
||||
When `getopt' finds an option that takes an argument,
|
||||
the argument value is returned here.
|
||||
Also, when `ordering' is RETURN_IN_ORDER,
|
||||
each non-option ARGV-element is returned here. */
|
||||
|
||||
WS_DLL_PUBLIC char *optarg;
|
||||
|
||||
/* Index in ARGV of the next element to be scanned.
|
||||
This is used for communication to and from the caller
|
||||
and for communication between successive calls to `getopt'.
|
||||
|
||||
On entry to `getopt', zero means this is the first call; initialize.
|
||||
|
||||
When `getopt' returns -1, this is the index of the first of the
|
||||
non-option elements that the caller should itself scan.
|
||||
|
||||
Otherwise, `optind' communicates from one call to the next
|
||||
how much of ARGV has been scanned so far. */
|
||||
|
||||
WS_DLL_PUBLIC int optind;
|
||||
|
||||
/* Callers store zero here to inhibit the error message `getopt' prints
|
||||
for unrecognized options. */
|
||||
|
||||
WS_DLL_PUBLIC int opterr;
|
||||
|
||||
/* Set to an option character which was unrecognized. */
|
||||
|
||||
WS_DLL_PUBLIC int optopt;
|
||||
|
||||
#ifndef __need_getopt
|
||||
/* Describe the long-named options requested by the application.
|
||||
The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
|
||||
of `struct option' terminated by an element containing a name which is
|
||||
zero.
|
||||
|
||||
The field `has_arg' is:
|
||||
no_argument (or 0) if the option does not take an argument,
|
||||
required_argument (or 1) if the option requires an argument,
|
||||
optional_argument (or 2) if the option takes an optional argument.
|
||||
|
||||
If the field `flag' is not NULL, it points to a variable that is set
|
||||
to the value given in the field `val' when the option is found, but
|
||||
left unchanged if the option is not found.
|
||||
|
||||
To have a long-named option do something other than set an `int' to
|
||||
a compiled-in constant, such as set a value from `optarg', set the
|
||||
option's `flag' field to zero and its `val' field to a nonzero
|
||||
value (the equivalent single-letter option character, if there is
|
||||
one). For long options that have a zero `flag' field, `getopt'
|
||||
returns the contents of the `val' field. */
|
||||
|
||||
struct option
|
||||
{
|
||||
const char *name;
|
||||
/* has_arg can't be an enum because some compilers complain about
|
||||
type mismatches in all the code that assumes it is an int. */
|
||||
int has_arg;
|
||||
int *flag;
|
||||
int val;
|
||||
};
|
||||
|
||||
/* Names for the values of the `has_arg' field of `struct option'. */
|
||||
|
||||
# define no_argument 0
|
||||
# define required_argument 1
|
||||
# define optional_argument 2
|
||||
#endif /* need getopt */
|
||||
|
||||
|
||||
/* Get definitions and prototypes for functions to process the
|
||||
arguments in ARGV (ARGC of them, minus the program name) for
|
||||
options given in OPTS.
|
||||
|
||||
Return the option character from OPTS just read. Return -1 when
|
||||
there are no more options. For unrecognized options, or options
|
||||
missing arguments, `optopt' is set to the option letter, and '?' is
|
||||
returned.
|
||||
|
||||
The OPTS string is a list of characters which are recognized option
|
||||
letters, optionally followed by colons, specifying that that letter
|
||||
takes an argument, to be placed in `optarg'.
|
||||
|
||||
If a letter in OPTS is followed by two colons, its argument is
|
||||
optional. This behavior is specific to the GNU `getopt'.
|
||||
|
||||
The argument `--' causes premature termination of argument
|
||||
scanning, explicitly telling `getopt' that there are no more
|
||||
options.
|
||||
|
||||
If OPTS begins with `--', then non-option arguments are treated as
|
||||
arguments to the option '\0'. This behavior is specific to the GNU
|
||||
`getopt'. */
|
||||
|
||||
#ifdef __GNU_LIBRARY__
|
||||
/* Many other libraries have conflicting prototypes for getopt, with
|
||||
differences in the consts, in stdlib.h. To avoid compilation
|
||||
errors, only prototype getopt for the GNU C library. */
|
||||
WS_DLL_PUBLIC int getopt (int ___argc, char *const *___argv, const char *__shortopts)
|
||||
__THROW;
|
||||
|
||||
# if defined __need_getopt && defined __USE_POSIX2 \
|
||||
&& !defined __USE_POSIX_IMPLICITLY && !defined __USE_GNU
|
||||
/* The GNU getopt has more functionality than the standard version. The
|
||||
additional functionality can be disable at runtime. This redirection
|
||||
helps to also do this at runtime. */
|
||||
# ifdef __REDIRECT
|
||||
extern int __REDIRECT_NTH (getopt, (int ___argc, char *const *___argv,
|
||||
const char *__shortopts),
|
||||
__posix_getopt);
|
||||
# else
|
||||
extern int __posix_getopt (int ___argc, char *const *___argv,
|
||||
const char *__shortopts) __THROW;
|
||||
# define getopt __posix_getopt
|
||||
# endif
|
||||
# endif
|
||||
#else /* not __GNU_LIBRARY__ */
|
||||
WS_DLL_PUBLIC int getopt (int ___argc, char *const *___argv,
|
||||
const char *__shortopts);
|
||||
#endif /* __GNU_LIBRARY__ */
|
||||
|
||||
#ifndef __need_getopt
|
||||
WS_DLL_PUBLIC int getopt_long (int ___argc, char *const *___argv,
|
||||
const char *__shortopts,
|
||||
const struct option *__longopts, int *__longind)
|
||||
__THROW;
|
||||
extern int getopt_long_only (int ___argc, char *const *___argv,
|
||||
const char *__shortopts,
|
||||
const struct option *__longopts, int *__longind)
|
||||
__THROW;
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Make sure we later can get all the definitions and declarations. */
|
||||
#undef __need_getopt
|
||||
|
||||
#endif /* getopt.h */
|
Loading…
Reference in New Issue