Ethereal-users: [Ethereal-users] tethereal "-q" quiet diff

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

From: "Eichert, Diana" <deicher@xxxxxxxxxx>
Date: Fri, 22 Mar 2002 16:03:17 -0700
I located my hacked tethereal.c and modified it so it would use the -q flag.

If tethereal is invoked with -q it will still print out the interface it is 
capturing on and will report the number of packets captured.

hope it's useful to someone

----------------------------------------------------------------------------
------------------------------------

--- tethereal.c.ORIG	Fri Mar 22 15:16:43 2002
+++ tethereal.c	Fri Mar 22 15:55:55 2002
@@ -117,6 +117,7 @@
 static guint32 firstsec, firstusec;
 static guint32 prevsec, prevusec;
 static GString *comp_info_str;
+static gboolean quiet;
 static gboolean verbose;
 static gboolean print_hex;
 static gboolean line_buffered;
@@ -173,7 +174,7 @@
   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 [ -vVhl ] [ -F <capture file type> ] [ -n ] [ -N
<resolving> ]\n", PACKAGE);
+  fprintf(stderr, "t%s [ -qvVhl ] [ -F <capture 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
@@ -413,7 +414,7 @@
 #endif
     
   /* Now get our args */
-  while ((opt = getopt(argc, argv, "a:b:c:Df:F:hi:lnN:o:pr:R:s:t:vw:Vx"))
!= EOF) {
+  while ((opt = getopt(argc, argv, "a:b:c:Df:F:hi:lnN:o:pqr:R:s:t:vw:Vx"))
!= EOF) {
     switch (opt) {
       case 'a':        /* autostop criteria */
 #ifdef HAVE_LIBPCAP
@@ -550,6 +551,9 @@
         arg_error = TRUE;
 #endif
 	break;
+      case 'q':        /* Quiet */
+        quiet = TRUE;
+        break;
       case 'r':        /* Read capture file xxx */
         cf_name = g_strdup(optarg);
         break;
@@ -987,10 +991,10 @@
   cnd_delete(cnd_stop_capturesize);
   cnd_delete(cnd_stop_timeout);
 
-  if (cfile.save_file != NULL) {
+  if ((cfile.save_file != NULL) && !quiet) {
     /* We're saving to a file, which means we're printing packet counts
-       to the standard output.  Send a newline so that we move to the
-       line after the packet count. */
+       to the standard output if we are not running silent and deep.
+       Send a newline so that we move to the line after the packet count.
*/
     fprintf(stderr, "\n");
   }
 
@@ -1010,6 +1014,12 @@
     fprintf(stderr, "tethereal: Can't get packet-drop statistics: %s\n",
 	pcap_geterr(ld.pch));
   }
+/* deicher */
+/* Report the number of captured packets if not reported during capture and
+   we are not saving to a file. */
+  if (quiet && (cfile.save_file != NULL)) {
+    fprintf(stderr, "\r%u packets captured\n", cfile.count);
+  }
 
   pcap_close(ld.pch);
 
@@ -1057,8 +1067,12 @@
   args.pdh = ld->pdh;
   if (ld->pdh) {
     wtap_dispatch_cb_write((u_char *)&args, &whdr, 0, NULL, pd);
-    fprintf(stderr, "\r%u ", cfile.count);
-    fflush(stdout);
+/* deicher */
+/* Report packet capture count if not quiet */
+    if (!quiet) {
+      fprintf(stderr, "\r%u ", cfile.count);
+      fflush(stdout);
+    }
   } else {
     wtap_dispatch_cb_print((u_char *)&args, &whdr, 0, NULL, pd);
   }