Ethereal-dev: [Ethereal-dev] Decoding packets while writing to file with tethereal

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: Joerg Mayer <jmayer@xxxxxxxxx>
Date: Tue, 20 Aug 2002 18:32:54 +0200
I've just written a small patch that allows to decode the captured packets
while writing them to file. The Option to do that is -Q (as opposed to -q).
I'm not sure that the behaviour and the combination of flags is that useful,
so I'd like some comments on that before I commit.

Current behaviour (including my patch):

Option(s)	Action
none		capture and decode to stdout
-w file		capture to file, print number of packets to stderr
-q -w file	capture to file
-Q -w file	capture to file and decode to stdout   <--new

I'd prefer something like the following, because the behaviour of
printing a packet is not influenced by whether it is being written to file.

none		capture and decode to stdout
-w file		capture to file and decode to stdout
-q -w file	capture to file, print number of packets to stderr
-Q -w file	capture to file

  Ciao
        Jörg
--
Joerg Mayer                                          <jmayer@xxxxxxxxx>
I found out that "pro" means "instead of" (as in proconsul). Now I know
what proactive means.
Index: tethereal.c
===================================================================
RCS file: /usr/local/cvsroot/ethereal/tethereal.c,v
retrieving revision 1.151
diff -u -r1.151 tethereal.c
--- tethereal.c	2 Aug 2002 23:36:07 -0000	1.151
+++ tethereal.c	20 Aug 2002 16:22:23 -0000
@@ -108,6 +108,7 @@
 static guint32 prevsec, prevusec;
 static GString *comp_info_str;
 static gboolean quiet;
+static gboolean decode;
 static gboolean verbose;
 static gboolean print_hex;
 static gboolean line_buffered;
@@ -452,7 +453,7 @@
 #endif
     
   /* Now get our args */
-  while ((opt = getopt(argc, argv, "a:b:c:Df:F:hi:lnN:o:pqr:R:s:t:vw:Vx")) != -1) {
+  while ((opt = getopt(argc, argv, "a:b:c:Df:F:hi:lnN:o:pqQr:R:s:t:vw:Vx")) != -1) {
     switch (opt) {
       case 'a':        /* autostop criteria */
 #ifdef HAVE_LIBPCAP
@@ -596,6 +597,9 @@
       case 'q':        /* Quiet */
         quiet = TRUE;
         break;
+      case 'Q':        /* Quiet */
+        decode = TRUE;
+        break;
       case 'r':        /* Read capture file xxx */
         cf_name = g_strdup(optarg);
         break;
@@ -1264,10 +1268,15 @@
     wtap_dispatch_cb_write((guchar *)&args, &whdr, 0, &pseudo_header, pd);
     /* Report packet capture count if not quiet */
     if (!quiet) {
-      if (ld->packet_count != 0) {
-        fprintf(stderr, "\r%u ", ld->packet_count);
-        /* stderr could be line buffered */
-        fflush(stderr);
+      if (!decode) {
+         if (ld->packet_count != 0) {
+           fprintf(stderr, "\r%u ", ld->packet_count);
+           /* stderr could be line buffered */
+           fflush(stderr);
+         }
+      } else {
+           wtap_dispatch_cb_print((guchar *)&args, &whdr, 0,
+                                  &pseudo_header, pd);
       }
     }
   } else {
Index: doc/tethereal.pod.template
===================================================================
RCS file: /usr/local/cvsroot/ethereal/doc/tethereal.pod.template,v
retrieving revision 1.53
diff -u -r1.53 tethereal.pod.template
--- doc/tethereal.pod.template	31 Jul 2002 19:27:49 -0000	1.53
+++ doc/tethereal.pod.template	20 Aug 2002 16:22:23 -0000
@@ -20,6 +20,7 @@
 S<[ B<-o> preference setting ] ...>
 S<[ B<-p> ]>
 S<[ B<-q> ]>
+S<[ B<-Q> ]>
 S<[ B<-r> infile ]>
 S<[ B<-R> display filter expression ]>
 S<[ B<-s> snaplen ]>
@@ -249,6 +250,10 @@
 Don't display the continuous count of packets captured that is normally
 shown when saving a capture to a file; instead, just display, at the end
 of the capture, a count of packets captured.
+
+=item -Q
+
+Decode packets even while writing to file.
 
 =item -r