In Tethereal, allow capture filters and read filters either to be
authorguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Tue, 22 Feb 2000 07:07:55 +0000 (07:07 +0000)
committerguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Tue, 22 Feb 2000 07:07:55 +0000 (07:07 +0000)
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

doc/tethereal.pod.template
tethereal.c
util.c
util.h

index 537cab3c204f8a1d1d52f2dcde7b95fa3762e3a8..147412a21574b80bafda91785418b9217b73a8a4 100644 (file)
@@ -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
index 72d60cf924112667ee8c064459af5c0f38d65f04..96c9857fcc3df04b105c1f43862253f41b35e7f0 100644 (file)
@@ -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");
diff --git a/util.c b/util.c
index 70d86d82ee2360170f6ba2ace4dc5b8e252d73c2..8b94d3b1dd3c9bc162e1f896750a4d38e6ffe2f6 100644 (file)
--- a/util.c
+++ b/util.c
@@ -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)
 {
diff --git a/util.h b/util.h
index d292e131ee9a9878d34d0dc14f203dbe8fe065f3..cbc247cee1adfbc4fdcde193eb7cb4f399e213ab 100644 (file)
--- a/util.h
+++ b/util.h
@@ -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);