]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Only print packets_captured as often as necessary.
authorDenis Ovsienko <[email protected]>
Thu, 12 Oct 2017 14:55:36 +0000 (15:55 +0100)
committerDenis Ovsienko <[email protected]>
Thu, 12 Oct 2017 15:03:55 +0000 (16:03 +0100)
Before this change tcpdump would, when run with -w and -v, print the
number of captured packets regardless if it had already printed the same
number, e.g. it could print "Got 0" again and again, triggering the
terminal emulator activity detection all the time and making it useless.
Only print the string when it is different from the previous one.

tcpdump.c

index 0d6ff7830d690a3c40dd2f29ae3d0abc997e2498..3a39716b42dec387e7ba2bad8147bd0ea6960029 100644 (file)
--- a/tcpdump.c
+++ b/tcpdump.c
@@ -2693,6 +2693,18 @@ RETSIGTYPE requestinfo(int signo _U_)
 }
 #endif
 
+static void
+print_packets_captured (void)
+{
+       static u_int prev_packets_captured, first = 1;
+
+       if (infodelay == 0 && (first || packets_captured != prev_packets_captured)) {
+               fprintf(stderr, "Got %u\r", packets_captured);
+               first = 0;
+               prev_packets_captured = packets_captured;
+       }
+}
+
 /*
  * Called once each second in verbose mode while dumping to file
  */
@@ -2700,14 +2712,12 @@ RETSIGTYPE requestinfo(int signo _U_)
 void CALLBACK verbose_stats_dump (UINT timer_id _U_, UINT msg _U_, DWORD_PTR arg _U_,
                                  DWORD_PTR dw1 _U_, DWORD_PTR dw2 _U_)
 {
-       if (infodelay == 0)
-               fprintf(stderr, "Got %u\r", packets_captured);
+       print_packets_captured();
 }
 #elif defined(HAVE_ALARM)
 static void verbose_stats_dump(int sig _U_)
 {
-       if (infodelay == 0)
-               fprintf(stderr, "Got %u\r", packets_captured);
+       print_packets_captured();
        alarm(1);
 }
 #endif