diff options
Diffstat (limited to 'ui/commandline.c')
-rw-r--r-- | ui/commandline.c | 99 |
1 files changed, 38 insertions, 61 deletions
diff --git a/ui/commandline.c b/ui/commandline.c index 9113f2ec49..e953cbb031 100644 --- a/ui/commandline.c +++ b/ui/commandline.c @@ -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) { /* |