aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile.common1
-rw-r--r--capture.h2
-rw-r--r--capture_opts.c53
-rw-r--r--clopts_common.c63
-rw-r--r--clopts_common.h10
-rw-r--r--cmdarg_err.h46
-rw-r--r--gtk/main.c106
-rw-r--r--tethereal.c67
8 files changed, 219 insertions, 129 deletions
diff --git a/Makefile.common b/Makefile.common
index 1ecf008e9d..934b658b62 100644
--- a/Makefile.common
+++ b/Makefile.common
@@ -71,6 +71,7 @@ ETHEREAL_COMMON_INCLUDES = \
capture_ui_utils.h \
cfile.h \
clopts_common.h \
+ cmdarg_err.h \
color.h \
conditions.h \
disabled_protos.h \
diff --git a/capture.h b/capture.h
index c46c21f6e5..ce90327acb 100644
--- a/capture.h
+++ b/capture.h
@@ -104,7 +104,7 @@ extern void
capture_opts_init(capture_options *capture_opts, void *cfile);
extern void
-capture_opts_add_opt(capture_options *capture_opts, const char *appname, int opt, const char *optarg, gboolean *start_capture);
+capture_opts_add_opt(capture_options *capture_opts, int opt, const char *optarg, gboolean *start_capture);
/* log content of capture_opts */
extern void
diff --git a/capture_opts.c b/capture_opts.c
index e3c5ec3ea3..df66d6b3a3 100644
--- a/capture_opts.c
+++ b/capture_opts.c
@@ -40,6 +40,7 @@
#include "capture.h"
#include "ringbuffer.h"
#include "clopts_common.h"
+#include "cmdarg_err.h"
void
capture_opts_init(capture_options *capture_opts, void *cfile)
@@ -125,7 +126,7 @@ capture_opts_log(const char *log_domain, GLogLevelFlags log_level, capture_optio
* in some fashion.
*/
static gboolean
-set_autostop_criterion(capture_options *capture_opts, const char *appname, const char *autostoparg)
+set_autostop_criterion(capture_options *capture_opts, const char *autostoparg)
{
gchar *p, *colonp;
@@ -154,14 +155,14 @@ set_autostop_criterion(capture_options *capture_opts, const char *appname, const
}
if (strcmp(autostoparg,"duration") == 0) {
capture_opts->has_autostop_duration = TRUE;
- capture_opts->autostop_duration = get_positive_int(appname, p,"autostop duration");
+ capture_opts->autostop_duration = get_positive_int(p,"autostop duration");
} else if (strcmp(autostoparg,"filesize") == 0) {
capture_opts->has_autostop_filesize = TRUE;
- capture_opts->autostop_filesize = get_positive_int(appname, p,"autostop filesize");
+ capture_opts->autostop_filesize = get_positive_int(p,"autostop filesize");
} else if (strcmp(autostoparg,"files") == 0) {
capture_opts->multi_files_on = TRUE;
capture_opts->has_autostop_files = TRUE;
- capture_opts->autostop_files = get_positive_int(appname, p,"autostop files");
+ capture_opts->autostop_files = get_positive_int(p,"autostop files");
} else {
return FALSE;
}
@@ -176,7 +177,7 @@ set_autostop_criterion(capture_options *capture_opts, const char *appname, const
* in some fashion.
*/
static gboolean
-get_ring_arguments(capture_options *capture_opts, const char *appname, const char *arg)
+get_ring_arguments(capture_options *capture_opts, const char *arg)
{
gchar *p = NULL, *colonp;
@@ -206,13 +207,13 @@ get_ring_arguments(capture_options *capture_opts, const char *appname, const cha
if (strcmp(arg,"files") == 0) {
capture_opts->has_ring_num_files = TRUE;
- capture_opts->ring_num_files = get_natural_int(appname, p, "number of ring buffer files");
+ capture_opts->ring_num_files = get_natural_int(p, "number of ring buffer files");
} else if (strcmp(arg,"filesize") == 0) {
capture_opts->has_autostop_filesize = TRUE;
- capture_opts->autostop_filesize = get_positive_int(appname, p, "ring buffer filesize");
+ capture_opts->autostop_filesize = get_positive_int(p, "ring buffer filesize");
} else if (strcmp(arg,"duration") == 0) {
capture_opts->has_file_duration = TRUE;
- capture_opts->file_duration = get_positive_int(appname, p, "ring buffer duration");
+ capture_opts->file_duration = get_positive_int(p, "ring buffer duration");
}
*colonp = ':'; /* put the colon back */
@@ -228,7 +229,7 @@ get_ring_arguments(capture_options *capture_opts, const char *appname, const cha
* in some fashion.
*/
static gboolean
-get_pipe_arguments(capture_options *capture_opts, const char *appname, const char *arg)
+get_pipe_arguments(capture_options *capture_opts, const char *arg)
{
gchar *p = NULL, *colonp;
int pipe_fd;
@@ -260,16 +261,16 @@ get_pipe_arguments(capture_options *capture_opts, const char *appname, const cha
if (strcmp(arg,"sync") == 0) {
/* associate stdout with sync pipe */
- pipe_fd = get_natural_int(appname, p, "sync pipe file descriptor");
+ pipe_fd = get_natural_int(p, "sync pipe file descriptor");
if (dup2(pipe_fd, 1) < 0) {
- fprintf(stderr, "%s: Unable to dup sync pipe handle\n", appname);
+ cmdarg_err("Unable to dup sync pipe handle");
return FALSE;
}
} else if (strcmp(arg,"signal") == 0) {
/* associate stdin with signal pipe */
- pipe_fd = get_natural_int(appname, p, "signal pipe file descriptor");
+ pipe_fd = get_natural_int(p, "signal pipe file descriptor");
if (dup2(pipe_fd, 0) < 0) {
- fprintf(stderr, "%s: Unable to dup signal pipe handle\n", appname);
+ cmdarg_err("Unable to dup signal pipe handle");
return FALSE;
}
}
@@ -281,30 +282,30 @@ get_pipe_arguments(capture_options *capture_opts, const char *appname, const cha
void
-capture_opts_add_opt(capture_options *capture_opts, const char *appname, int opt, const char *optarg, gboolean *start_capture)
+capture_opts_add_opt(capture_options *capture_opts, int opt, const char *optarg, gboolean *start_capture)
{
switch(opt) {
case 'a': /* autostop criteria */
- if (set_autostop_criterion(capture_opts, appname, optarg) == FALSE) {
- fprintf(stderr, "%s: Invalid or unknown -a flag \"%s\"\n", appname, optarg);
+ if (set_autostop_criterion(capture_opts, optarg) == FALSE) {
+ cmdarg_err("Invalid or unknown -a flag \"%s\"", optarg);
exit(1);
}
break;
case 'b': /* Ringbuffer option */
capture_opts->multi_files_on = TRUE;
- if (get_ring_arguments(capture_opts, appname, optarg) == FALSE) {
- fprintf(stderr, "%s: Invalid or unknown -b arg \"%s\"\n", appname, optarg);
+ if (get_ring_arguments(capture_opts, optarg) == FALSE) {
+ cmdarg_err("Invalid or unknown -b arg \"%s\"", optarg);
exit(1);
}
break;
#ifdef _WIN32
case 'B': /* Buffer size */
- capture_opts->buffer_size = get_positive_int(appname, optarg, "buffer size");
+ capture_opts->buffer_size = get_positive_int(optarg, "buffer size");
break;
#endif
case 'c': /* Capture xxx packets */
capture_opts->has_autostop_packets = TRUE;
- capture_opts->autostop_packets = get_positive_int(appname, optarg, "packet count");
+ capture_opts->autostop_packets = get_positive_int(optarg, "packet count");
break;
case 'f': /* capture filter */
if (capture_opts->cfilter)
@@ -330,7 +331,7 @@ capture_opts_add_opt(capture_options *capture_opts, const char *appname, int opt
break;
case 's': /* Set the snapshot (capture) length */
capture_opts->has_snaplen = TRUE;
- capture_opts->snaplen = get_positive_int(appname, optarg, "snapshot length");
+ capture_opts->snaplen = get_positive_int(optarg, "snapshot length");
break;
case 'S': /* "Real-Time" mode: used for following file ala tail -f */
capture_opts->real_time_mode = TRUE;
@@ -342,20 +343,20 @@ capture_opts_add_opt(capture_options *capture_opts, const char *appname, int opt
#ifdef HAVE_PCAP_DATALINK_NAME_TO_VAL
capture_opts->linktype = pcap_datalink_name_to_val(optarg);
if (capture_opts->linktype == -1) {
- fprintf(stderr, "%s: The specified data link type \"%s\" isn't valid\n",
- appname, optarg);
+ cmdarg_err("The specified data link type \"%s\" isn't valid",
+ optarg);
exit(1);
}
#else /* HAVE_PCAP_DATALINK_NAME_TO_VAL */
/* XXX - just treat it as a number */
- capture_opts->linktype = get_natural_int(appname, optarg, "data link type");
+ capture_opts->linktype = get_natural_int(optarg, "data link type");
#endif /* HAVE_PCAP_DATALINK_NAME_TO_VAL */
break;
#ifdef _WIN32
/* Hidden option supporting Sync mode */
case 'Z': /* Write to pipe FD XXX */
- if (get_pipe_arguments(capture_opts, appname, optarg) == FALSE) {
- fprintf(stderr, "%s: Invalid or unknown -Z flag \"%s\"\n", appname, optarg);
+ if (get_pipe_arguments(capture_opts, optarg) == FALSE) {
+ cmdarg_err("Invalid or unknown -Z flag \"%s\"", optarg);
exit(1);
}
break;
diff --git a/clopts_common.c b/clopts_common.c
index 1528d726e8..6b3187eaad 100644
--- a/clopts_common.c
+++ b/clopts_common.c
@@ -34,70 +34,26 @@
#include <epan/prefs.h>
#include "clopts_common.h"
-
-/*
- * Handle the "-G" option, to cause protocol field, etc. information
- * to be printed.
- */
-void
-handle_dashG_option(int argc, char **argv, const char *progname)
-{
- char *gpf_path, *pf_path;
- int gpf_open_errno, gpf_read_errno;
- int pf_open_errno, pf_read_errno;
-
- if (argc >= 2 && strcmp(argv[1], "-G") == 0) {
- if (argc == 2)
- proto_registrar_dump_fields(1);
- else {
- if (strcmp(argv[2], "fields") == 0)
- proto_registrar_dump_fields(1);
- else if (strcmp(argv[2], "fields2") == 0)
- proto_registrar_dump_fields(2);
- else if (strcmp(argv[2], "fields3") == 0)
- proto_registrar_dump_fields(3);
- else if (strcmp(argv[2], "protocols") == 0)
- proto_registrar_dump_protocols();
- else if (strcmp(argv[2], "values") == 0)
- proto_registrar_dump_values();
- else if (strcmp(argv[2], "decodes") == 0)
- dissector_dump_decodes();
- else if (strcmp(argv[2], "defaultprefs") == 0)
- write_prefs(NULL);
- else if (strcmp(argv[2], "currentprefs") == 0) {
- read_prefs(&gpf_open_errno, &gpf_read_errno, &gpf_path,
- &pf_open_errno, &pf_read_errno, &pf_path);
- write_prefs(NULL);
- } else {
- fprintf(stderr, "%s: Invalid \"%s\" option for -G flag\n", progname,
- argv[2]);
- exit(1);
- }
- }
- exit(0);
- }
-}
+#include "cmdarg_err.h"
int
-get_natural_int(const char *appname, const char *string, const char *name)
+get_natural_int(const char *string, const char *name)
{
long number;
char *p;
number = strtol(string, &p, 10);
if (p == string || *p != '\0') {
- fprintf(stderr, "%s: The specified %s \"%s\" isn't a decimal number\n",
- appname, name, string);
+ cmdarg_err("The specified %s \"%s\" isn't a decimal number", name, string);
exit(1);
}
if (number < 0) {
- fprintf(stderr, "%s: The specified %s \"%s\" is a negative number\n",
- appname, name, string);
+ cmdarg_err("The specified %s \"%s\" is a negative number", name, string);
exit(1);
}
if (number > INT_MAX) {
- fprintf(stderr, "%s: The specified %s \"%s\" is too large (greater than %d)\n",
- appname, name, string, INT_MAX);
+ cmdarg_err("The specified %s \"%s\" is too large (greater than %d)",
+ name, string, INT_MAX);
exit(1);
}
return number;
@@ -105,15 +61,14 @@ get_natural_int(const char *appname, const char *string, const char *name)
int
-get_positive_int(const char *appname, const char *string, const char *name)
+get_positive_int(const char *string, const char *name)
{
long number;
- number = get_natural_int(appname, string, name);
+ number = get_natural_int(string, name);
if (number == 0) {
- fprintf(stderr, "%s: The specified %s is zero\n",
- appname, name);
+ cmdarg_err("The specified %s is zero", name);
exit(1);
}
diff --git a/clopts_common.h b/clopts_common.h
index d4862f8575..461fad4bb3 100644
--- a/clopts_common.h
+++ b/clopts_common.h
@@ -29,15 +29,9 @@
extern "C" {
#endif /* __cplusplus */
-/*
- * Handle the "-G" option, to cause protocol field, etc. information
- * to be printed.
- */
-void handle_dashG_option(int argc, char **argv, const char *progname);
-
-int get_natural_int(const char *appname, const char *string, const char *name);
+int get_natural_int(const char *string, const char *name);
-int get_positive_int(const char *appname, const char *string, const char *name);
+int get_positive_int(const char *string, const char *name);
#ifdef __cplusplus
}
diff --git a/cmdarg_err.h b/cmdarg_err.h
new file mode 100644
index 0000000000..e50b89a8a5
--- /dev/null
+++ b/cmdarg_err.h
@@ -0,0 +1,46 @@
+/* cmdarg_err.h
+ * Declarations of routines to report command-line errors.
+ *
+ * $Id$
+ *
+ * Ethereal - Network traffic analyzer
+ * By Gerald Combs <gerald@ethereal.com>
+ * Copyright 1998 Gerald Combs
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __CMDARG_ERR_H__
+#define __CMDARG_ERR_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/*
+ * Report an error in command-line arguments.
+ */
+extern void cmdarg_err(const char *fmt, ...);
+
+/*
+ * Report additional information for an error in command-line arguments.
+ */
+extern void cmdarg_err_cont(const char *fmt, ...);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* __CMDARG_ERR_H__ */
diff --git a/gtk/main.c b/gtk/main.c
index 6c20aa20e2..c046b01910 100644
--- a/gtk/main.c
+++ b/gtk/main.c
@@ -83,6 +83,7 @@
#include <epan/stat_cmd_args.h>
#include "util.h"
#include "clopts_common.h"
+#include "cmdarg_err.h"
#include "version_info.h"
#include "merge.h"
@@ -1124,6 +1125,47 @@ show_version(void)
#endif
}
+/*
+ * Report an error in command-line arguments.
+ * Creates a console on Windows.
+ * XXX - pop this up in a window of some sort on UNIX+X11 if the controlling
+ * terminal isn't the standard error?
+ */
+void
+cmdarg_err(const char *fmt, ...)
+{
+ va_list ap;
+
+#ifdef _WIN32
+ create_console();
+#endif
+ va_start(ap, fmt);
+ fprintf(stderr, "ethereal: ");
+ vfprintf(stderr, fmt, ap);
+ fprintf(stderr, "\n");
+ va_end(ap);
+}
+
+/*
+ * Report additional information for an error in command-line arguments.
+ * Creates a console on Windows.
+ * XXX - pop this up in a window of some sort on UNIX+X11 if the controlling
+ * terminal isn't the standard error?
+ */
+void
+cmdarg_err_cont(const char *fmt, ...)
+{
+ va_list ap;
+
+#ifdef _WIN32
+ create_console();
+#endif
+ va_start(ap, fmt);
+ vfprintf(stderr, fmt, ap);
+ fprintf(stderr, "\n");
+ va_end(ap);
+}
+
#if defined(_WIN32) || GTK_MAJOR_VERSION < 2 || ! defined USE_THREADS
/*
Once every 3 seconds we get a callback here which we use to update
@@ -1758,8 +1800,7 @@ main(int argc, char *argv[])
/* "pre-scan" the command line parameters, if we have "console only"
parameters. We do this so we don't start GTK+ if we're only showing
- command-line help information, version information, or "-G"
- information.
+ command-line help or version information.
XXX - this pre-scan is doen before we start GTK+, so we haven't
run gtk_init() on the arguments. That means that GTK+ arguments
@@ -1780,11 +1821,6 @@ main(int argc, char *argv[])
show_version();
exit(0);
break;
- case 'G': /* dump various field or other infos, see handle_dashG_option() */
- handle_dashG_option(argc, argv, "ethereal");
- /* will never return! */
- exit(0);
- break;
case '?': /* Ignore errors - the "real" scan will catch them. */
break;
}
@@ -2091,7 +2127,7 @@ main(int argc, char *argv[])
case 'Z': /* Write to pipe FD XXX */
#endif /* _WIN32 */
#ifdef HAVE_LIBPCAP
- capture_opts_add_opt(capture_opts, "ethereal", opt, optarg, &start_capture);
+ capture_opts_add_opt(capture_opts, opt, optarg, &start_capture);
#else
capture_option_specified = TRUE;
arg_error = TRUE;
@@ -2102,13 +2138,13 @@ main(int argc, char *argv[])
* the error flags for the user in the non-libpcap case.
*/
case 'W': /* Write to capture file FD xxx */
- capture_opts_add_opt(capture_opts, "ethereal", opt, optarg, &start_capture);
+ capture_opts_add_opt(capture_opts, opt, optarg, &start_capture);
break;
#endif
/*** all non capture option specific ***/
case 'g': /* Go to packet */
- go_to_packet = get_positive_int("Ethereal", optarg, "go to packet");
+ go_to_packet = get_positive_int(optarg, "go to packet");
break;
case 'l': /* Automatic scrolling in live capture mode */
#ifdef HAVE_LIBPCAP
@@ -2139,7 +2175,7 @@ main(int argc, char *argv[])
g_resolv_flags = RESOLV_NONE;
badopt = string_to_name_resolve(optarg, &g_resolv_flags);
if (badopt != '\0') {
- g_warning("ethereal: -N specifies unknown resolving option '%c'; valid options are 'm', 'n', and 't'",
+ cmdarg_err("-N specifies unknown resolving option '%c'; valid options are 'm', 'n', and 't'",
badopt);
exit(1);
}
@@ -2149,7 +2185,7 @@ main(int argc, char *argv[])
case PREFS_SET_OK:
break;
case PREFS_SET_SYNTAX_ERR:
- g_warning("ethereal: Invalid -o flag \"%s\"", optarg);
+ cmdarg_err("Invalid -o flag \"%s\"", optarg);
exit(1);
break;
case PREFS_SET_NO_SUCH_PREF:
@@ -2159,12 +2195,12 @@ main(int argc, char *argv[])
break;
case PREFS_SET_SYNTAX_ERR:
/* shouldn't happen, checked already above */
- g_warning("ethereal: Invalid -o flag \"%s\"", optarg);
+ cmdarg_err("Invalid -o flag \"%s\"", optarg);
exit(1);
break;
case PREFS_SET_NO_SUCH_PREF:
case PREFS_SET_OBSOLETE:
- g_warning("ethereal: -o flag \"%s\" specifies unknown preference/recent value",
+ cmdarg_err("-o flag \"%s\" specifies unknown preference/recent value",
optarg);
exit(1);
break;
@@ -2173,7 +2209,7 @@ main(int argc, char *argv[])
}
break;
case PREFS_SET_OBSOLETE:
- g_warning("ethereal: -o flag \"%s\" specifies obsolete preference",
+ cmdarg_err("-o flag \"%s\" specifies obsolete preference",
optarg);
exit(1);
break;
@@ -2200,10 +2236,9 @@ main(int argc, char *argv[])
else if (strcmp(optarg, "d") == 0)
timestamp_set_type(TS_DELTA);
else {
- g_warning("ethereal: Invalid time stamp type \"%s\"",
- optarg);
- g_warning("It must be \"r\" for relative, \"a\" for absolute,");
- g_warning("\"ad\" for absolute with date, or \"d\" for delta.");
+ cmdarg_err("Invalid time stamp type \"%s\"", optarg);
+ cmdarg_err_cont("It must be \"r\" for relative, \"a\" for absolute,");
+ cmdarg_err_cont("\"ad\" for absolute with date, or \"d\" for delta.");
exit(1);
}
break;
@@ -2214,15 +2249,14 @@ main(int argc, char *argv[])
part of a tap filter. Instead, we just add the argument
to a list of stat arguments. */
if (!process_stat_cmd_arg(optarg)) {
- g_warning("ethereal: invalid -z argument.");
- g_warning(" -z argument must be one of :");
+ cmdarg_err("Invalid -z argument.");
+ cmdarg_err_cont(" -z argument must be one of :");
list_stat_cmd_args();
exit(1);
}
break;
default:
case '?': /* Bad flag - print usage message */
- g_warning("Bad flag");
arg_error = TRUE;
break;
}
@@ -2235,7 +2269,7 @@ main(int argc, char *argv[])
* Input file name specified with "-r" *and* specified as a regular
* command-line argument.
*/
- g_warning("File name specified both with -r and regular argument");
+ cmdarg_err("File name specified both with -r and regular argument");
arg_error = TRUE;
} else {
/*
@@ -2260,14 +2294,14 @@ main(int argc, char *argv[])
/*
* Extra command line arguments were specified; complain.
*/
- g_warning("Invalid argument: %s", argv[0]);
+ cmdarg_err("Invalid argument: %s", argv[0]);
arg_error = TRUE;
}
if (arg_error) {
#ifndef HAVE_LIBPCAP
if (capture_option_specified) {
- g_warning("This version of Ethereal was not built with support for capturing packets.");
+ cmdarg_err("This version of Ethereal was not built with support for capturing packets.");
}
#endif
print_usage(FALSE);
@@ -2277,7 +2311,7 @@ main(int argc, char *argv[])
#ifdef HAVE_LIBPCAP
if (start_capture && list_link_layer_types) {
/* Specifying *both* is bogus. */
- g_warning("ethereal: You can't specify both -L and a live capture.");
+ cmdarg_err("You can't specify both -L and a live capture.");
exit(1);
}
@@ -2286,12 +2320,12 @@ main(int argc, char *argv[])
did the user also specify a capture file to be read? */
if (cf_name) {
/* Yes - that's bogus. */
- g_warning("ethereal: You can't specify -L and a capture file to be read.");
+ cmdarg_err("You can't specify -L and a capture file to be read.");
exit(1);
}
/* No - did they specify a ring buffer option? */
if (capture_opts->multi_files_on) {
- g_warning("ethereal: Ring buffer requested, but a capture isn't being done.");
+ cmdarg_err("Ring buffer requested, but a capture isn't being done.");
exit(1);
}
} else {
@@ -2299,7 +2333,7 @@ main(int argc, char *argv[])
a capture file to be read? */
if (start_capture && cf_name) {
/* Yes - that's bogus. */
- g_warning("ethereal: You can't specify both a live capture and a capture file to be read.");
+ cmdarg_err("You can't specify both a live capture and a capture file to be read.");
exit(1);
}
@@ -2313,15 +2347,15 @@ main(int argc, char *argv[])
c) it makes no sense to enable the ring buffer if the maximum
file size is set to "infinite". */
if (capture_opts->save_file == NULL) {
- g_warning("ethereal: Ring buffer requested, but capture isn't being saved to a permanent file.");
+ cmdarg_err("Ring buffer requested, but capture isn't being saved to a permanent file.");
capture_opts->multi_files_on = FALSE;
}
/* if (capture_opts->real_time_mode) {
- g_warning("ethereal: Ring buffer requested, but an \"Update list of packets in real time\" capture is being done.");
+ cmdarg_err("Ring buffer requested, but an \"Update list of packets in real time\" capture is being done.");
capture_opts->multi_files_on = FALSE;
}*/
if (!capture_opts->has_autostop_filesize && !capture_opts->has_file_duration) {
- g_warning("ethereal: Ring buffer requested, but no maximum capture file size or duration were specified.");
+ cmdarg_err("Ring buffer requested, but no maximum capture file size or duration were specified.");
/* XXX - this must be redesigned as the conditions changed */
/* capture_opts->multi_files_on = FALSE;*/
}
@@ -2343,12 +2377,12 @@ main(int argc, char *argv[])
case CANT_GET_INTERFACE_LIST:
cant_get_if_list_errstr = cant_get_if_list_error_message(err_str);
- g_warning("%s", cant_get_if_list_errstr);
+ cmdarg_err("%s", cant_get_if_list_errstr);
g_free(cant_get_if_list_errstr);
break;
case NO_INTERFACES_FOUND:
- g_warning("ethereal: There are no interfaces on which a capture can be done");
+ cmdarg_err("There are no interfaces on which a capture can be done");
break;
}
exit(2);
@@ -2365,11 +2399,11 @@ main(int argc, char *argv[])
lt_list = get_pcap_linktype_list(capture_opts->iface, err_str);
if (lt_list == NULL) {
if (err_str[0] != '\0') {
- g_warning("ethereal: The list of data link types for the capture device could not be obtained (%s)."
+ cmdarg_err("The list of data link types for the capture device could not be obtained (%s)."
"Please check to make sure you have sufficient permissions, and that\n"
"you have the proper interface or pipe specified.\n", err_str);
} else
- g_warning("ethereal: The capture device has no data link types.");
+ cmdarg_err("The capture device has no data link types.");
exit(2);
}
g_warning("Data link types (use option -y to set):");
diff --git a/tethereal.c b/tethereal.c
index d016dc823f..02ab7b397d 100644
--- a/tethereal.c
+++ b/tethereal.c
@@ -75,6 +75,7 @@
#include <epan/addr_resolv.h>
#include "util.h"
#include "clopts_common.h"
+#include "cmdarg_err.h"
#include "version_info.h"
#include <epan/conversation.h>
#include <epan/plugins.h>
@@ -689,9 +690,38 @@ main(int argc, char *argv[])
for backwards compatibility we dump out a glossary of display
filter symbols.
- We do this here to mirror what happens in the GTK+ version, although
- it's not necessary here. */
- handle_dashG_option(argc, argv, "tethereal");
+ XXX - we do this here, for now, to support "-G" with no arguments.
+ If none of our build or other processes uses "-G" with no arguments,
+ we can just process it with the other arguments. */
+ if (argc >= 2 && strcmp(argv[1], "-G") == 0) {
+ if (argc == 2)
+ proto_registrar_dump_fields(1);
+ else {
+ if (strcmp(argv[2], "fields") == 0)
+ proto_registrar_dump_fields(1);
+ else if (strcmp(argv[2], "fields2") == 0)
+ proto_registrar_dump_fields(2);
+ else if (strcmp(argv[2], "fields3") == 0)
+ proto_registrar_dump_fields(3);
+ else if (strcmp(argv[2], "protocols") == 0)
+ proto_registrar_dump_protocols();
+ else if (strcmp(argv[2], "values") == 0)
+ proto_registrar_dump_values();
+ else if (strcmp(argv[2], "decodes") == 0)
+ dissector_dump_decodes();
+ else if (strcmp(argv[2], "defaultprefs") == 0)
+ write_prefs(NULL);
+ else if (strcmp(argv[2], "currentprefs") == 0) {
+ read_prefs(&gpf_open_errno, &gpf_read_errno, &gpf_path,
+ &pf_open_errno, &pf_read_errno, &pf_path);
+ write_prefs(NULL);
+ } else {
+ cmdarg_err("Invalid \"%s\" option for -G flag", argv[2]);
+ exit(1);
+ }
+ }
+ exit(0);
+ }
/* Set the C-language locale to the native environment. */
setlocale(LC_ALL, "");
@@ -783,7 +813,7 @@ main(int argc, char *argv[])
case 's': /* Set the snapshot (capture) length */
case 'y': /* Set the pcap data link type */
#ifdef HAVE_LIBPCAP
- capture_opts_add_opt(&capture_opts, "tethereal", opt, optarg, &start_capture);
+ capture_opts_add_opt(&capture_opts, opt, optarg, &start_capture);
#else
capture_option_specified = TRUE;
arg_error = TRUE;
@@ -3355,3 +3385,32 @@ read_failure_message(const char *filename, int err)
fprintf(stderr, "tethereal: An error occurred while reading from the file \"%s\": %s.\n",
filename, strerror(err));
}
+
+/*
+ * Report an error in command-line arguments.
+ */
+void
+cmdarg_err(const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ fprintf(stderr, "tethereal: ");
+ vfprintf(stderr, fmt, ap);
+ fprintf(stderr, "\n");
+ va_end(ap);
+}
+
+/*
+ * Report additional information for an error in command-line arguments.
+ */
+void
+cmdarg_err_cont(const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ vfprintf(stderr, fmt, ap);
+ fprintf(stderr, "\n");
+ va_end(ap);
+}