aboutsummaryrefslogtreecommitdiffstats
path: root/tethereal.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2002-05-22 23:22:56 +0000
committerGuy Harris <guy@alum.mit.edu>2002-05-22 23:22:56 +0000
commite2630eed794a5566892329e8f7ae9b35e7791899 (patch)
treef9075b94f575ea2d0764e13abc5dfcb31d7b2c45 /tethereal.c
parent7da945178186299a0bb39a5858b2c53ec7738ddd (diff)
Command-line interface cleanups, from Graeme Hewson:
- Exit if an error is found in the options or arguments. - In print_usage(), improve the visibility of any getopt() error message by suppressing the version information when -h is not specified, and by adding an empty line. Ethereal: - If the -k option is specified, use the interface in the preferences file, if present. - Prevent the user from specifying any hidden options which are used internally in -S mode. Tethereal: - Fix a memory leak in the processing of the -f option. - In print_usage(), change "capture file type" to "output file type", which I think is clearer; move the -q flag from the non-libpcap case to the libpcap case. svn path=/trunk/; revision=5525
Diffstat (limited to 'tethereal.c')
-rw-r--r--tethereal.c28
1 files changed, 19 insertions, 9 deletions
diff --git a/tethereal.c b/tethereal.c
index f46dc4be3b..21ad781326 100644
--- a/tethereal.c
+++ b/tethereal.c
@@ -1,6 +1,6 @@
/* tethereal.c
*
- * $Id: tethereal.c,v 1.137 2002/05/14 18:27:16 guy Exp $
+ * $Id: tethereal.c,v 1.138 2002/05/22 23:22:55 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -180,22 +180,24 @@ static capture_options capture_opts = {
#endif
static void
-print_usage(void)
+print_usage(gboolean print_ver)
{
int i;
- fprintf(stderr, "This is GNU t%s %s, compiled %s\n", PACKAGE, VERSION,
+ if (print_ver) {
+ fprintf(stderr, "This is GNU t%s %s, compiled %s\n", PACKAGE, VERSION,
comp_info_str->str);
+ }
#ifdef HAVE_LIBPCAP
- fprintf(stderr, "t%s [ -DvVhlp ] [ -a <capture autostop condition> ] ...\n",
+ fprintf(stderr, "\nt%s [ -DvVhqlp ] [ -a <capture autostop condition> ] ...\n",
PACKAGE);
fprintf(stderr, "\t[ -b <number of ring buffer files> ] [ -c <count> ]\n");
- fprintf(stderr, "\t[ -f <capture filter> ] [ -F <capture file type> ]\n");
+ fprintf(stderr, "\t[ -f <capture filter> ] [ -F <output file type> ]\n");
fprintf(stderr, "\t[ -i <interface> ] [ -n ] [ -N <resolving> ]\n");
fprintf(stderr, "\t[ -o <preference setting> ] ... [ -r <infile> ] [ -R <read filter> ]\n");
fprintf(stderr, "\t[ -s <snaplen> ] [ -t <time stamp format> ] [ -w <savefile> ] [ -x ]\n");
#else
- fprintf(stderr, "t%s [ -qvVhl ] [ -F <capture file type> ] [ -n ] [ -N <resolving> ]\n", PACKAGE);
+ fprintf(stderr, "\nt%s [ -vVhl ] [ -F <output file type> ] [ -n ] [ -N <resolving> ]\n", PACKAGE);
fprintf(stderr, "\t[ -o <preference setting> ] ... [ -r <infile> ] [ -R <read filter> ]\n");
fprintf(stderr, "\t[ -t <time stamp format> ] [ -w <savefile> ] [ -x ]\n");
#endif
@@ -505,6 +507,8 @@ main(int argc, char *argv[])
case 'f':
#ifdef HAVE_LIBPCAP
capture_filter_specified = TRUE;
+ if (cfile.cfilter)
+ g_free(cfile.cfilter);
cfile.cfilter = g_strdup(optarg);
#else
capture_option_specified = TRUE;
@@ -520,7 +524,7 @@ main(int argc, char *argv[])
}
break;
case 'h': /* Print help and exit */
- print_usage();
+ print_usage(TRUE);
exit(0);
break;
case 'i': /* Use interface xxx */
@@ -629,6 +633,10 @@ main(int argc, char *argv[])
case 'x': /* Print packet data in hex (and ASCII) */
print_hex = TRUE;
break;
+ default:
+ case '?': /* Bad flag - print usage message */
+ arg_error = TRUE;
+ break;
}
}
@@ -702,8 +710,10 @@ main(int argc, char *argv[])
if (capture_option_specified)
fprintf(stderr, "This version of Tethereal was not built with support for capturing packets.\n");
#endif
- if (arg_error)
- print_usage();
+ if (arg_error) {
+ print_usage(FALSE);
+ exit(1);
+ }
/* Build the column format array */
for (i = 0; i < cfile.cinfo.num_cols; i++) {