diff options
author | guy <guy@f5534014-38df-0310-8fa8-9805f1628bb7> | 2000-02-22 07:07:55 +0000 |
---|---|---|
committer | guy <guy@f5534014-38df-0310-8fa8-9805f1628bb7> | 2000-02-22 07:07:55 +0000 |
commit | 24c6fa182af38b3d54ebb8fbd839689349c646e3 (patch) | |
tree | 104d10ff0c595478c9d602d94105d6426c2f9e25 | |
parent | e501947f3e839aa38a10f72833cba58c03624773 (diff) |
In Tethereal, allow capture filters and read filters either to be
specifies with "-f" and "-R" flags, respectively, or specified with
non-flag command-line arguments, as tcpdump and snoop allow.
git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@1663 f5534014-38df-0310-8fa8-9805f1628bb7
-rw-r--r-- | doc/tethereal.pod.template | 10 | ||||
-rw-r--r-- | tethereal.c | 30 | ||||
-rw-r--r-- | util.c | 42 | ||||
-rw-r--r-- | util.h | 8 |
4 files changed, 86 insertions, 4 deletions
diff --git a/doc/tethereal.pod.template b/doc/tethereal.pod.template index 537cab3c20..147412a215 100644 --- a/doc/tethereal.pod.template +++ b/doc/tethereal.pod.template @@ -19,8 +19,9 @@ S<[ B<-s> snaplen ]> S<[ B<-t> time stamp format ]> S<[ B<-v> ]> S<[ B<-V> ]> -S<[ B<-w> savefile]> +S<[ B<-w> savefile ]> S<[ B<-x> ]> +S<[ filter expression ]> =head1 DESCRIPTION @@ -83,6 +84,13 @@ Compressed file support uses (and therefore requires) the zlib library. If the zlib library is not present, B<Tethereal> will compile, but will be unable to read compressed files. +A capture or read filter can either be specified with the B<-f> or B<-R> +option, respectively, in which case the entire filter expression must be +specified as a single argument (which means that if it contains spaces, +it must be quoted), or can be specified with command-line arguments +after the option arguments, in which case all the arguments after the +filter arguments are treated as a filter expression. + =head1 OPTIONS =over 4 diff --git a/tethereal.c b/tethereal.c index 72d60cf924..96c9857fcc 100644 --- a/tethereal.c +++ b/tethereal.c @@ -1,6 +1,6 @@ /* tethereal.c * - * $Id: tethereal.c,v 1.19 2000/02/19 07:59:54 guy Exp $ + * $Id: tethereal.c,v 1.20 2000/02/22 07:07:46 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -174,6 +174,7 @@ main(int argc, char *argv[]) char *pf_path; int err; #ifdef HAVE_LIBPCAP + gboolean capture_filter_specified = FALSE; int packet_count = 0; GList *if_list; gchar err_str[PCAP_ERRBUF_SIZE]; @@ -287,6 +288,7 @@ main(int argc, char *argv[]) break; case 'f': #ifdef HAVE_LIBPCAP + capture_filter_specified = TRUE; cf.cfilter = g_strdup(optarg); #else capture_option_specified = TRUE; @@ -361,6 +363,32 @@ main(int argc, char *argv[]) } } + /* If no capture filter or read filter has been specified, and there are + 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 (cf_name != NULL) { + if (rfilter != NULL) { + fprintf(stderr, +"tethereal: Read filters were specified both with \"-R\" and with additional command-line arguments\n"); + exit(2); + } + rfilter = get_args_as_string(argc, argv, optind); + } else { +#ifdef HAVE_LIBPCAP + if (capture_filter_specified) { + fprintf(stderr, +"tethereal: Capture filters were specified both with \"-f\" and with additional command-line arguments\n"); + exit(2); + } + cf.cfilter = get_args_as_string(argc, argv, optind); +#else + capture_option_specified = TRUE; +#endif + } + } + #ifndef HAVE_LIBPCAP if (capture_option_specified) fprintf(stderr, "This version of Tethereal was not built with support for capturing packets.\n"); @@ -1,7 +1,7 @@ /* util.c * Utility routines * - * $Id: util.c,v 1.36 2000/02/09 19:17:52 gram Exp $ + * $Id: util.c,v 1.37 2000/02/22 07:07:46 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -183,6 +183,46 @@ get_dirname(char *path) return path; } +/* + * Collect command-line arguments as a string consisting of the arguments, + * separated by spaces. + */ +char * +get_args_as_string(int argc, char **argv, int optind) +{ + int len; + int i; + char *argstring; + + /* + * Find out how long the string will be. + */ + len = 0; + for (i = optind; i < argc; i++) { + len += strlen(argv[i]); + len++; /* space, or '\0' if this is the last argument */ + } + + /* + * Allocate the buffer for the string. + */ + argstring = g_malloc(len); + + /* + * Now construct the string. + */ + strcpy(argstring, ""); + i = optind; + for (;;) { + strcat(argstring, argv[i]); + i++; + if (i == argc) + break; + strcat(argstring, " "); + } + return argstring; +} + static char * setup_tmpdir(char *dir) { @@ -1,7 +1,7 @@ /* util.h * Utility definitions * - * $Id: util.h,v 1.18 2000/01/29 16:41:15 gram Exp $ + * $Id: util.h,v 1.19 2000/02/22 07:07:47 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -48,6 +48,12 @@ int create_tempfile(char *, int, const char *); * variable, or a default directory if HOME is not set */ const char* get_home_dir(void); +/* + * Collect command-line arguments as a string consisting of the arguments, + * separated by spaces. + */ +char *get_args_as_string(int argc, char **argv, int optind); + void ASCII_to_EBCDIC(guint8 *buf, guint bytes); guint8 ASCII_to_EBCDIC1(guint8 c); void EBCDIC_to_ASCII(guint8 *buf, guint bytes); |