]> The Tcpdump Group git mirrors - libpcap/commitdiff
patch from Erik de Castro Lopo <[email protected]>:
authorhannes <hannes>
Fri, 2 Jan 2004 11:25:26 +0000 (11:25 +0000)
committerhannes <hannes>
Fri, 2 Jan 2004 11:25:26 +0000 (11:25 +0000)
  In the Linux kernel the packet statistics are zeroed during each retrieval.
  In contrast, on FreeBSD, the packet statistics are retrived using
  ioctl(BIOCGSTATS):

  The patch adds a static variable to pcap_stats_linux() which
  holds a running total of the packet statistics so that the behaviour
  of pcap_stats() on Linux matches the behaviour of FreeBSD.

CREDITS
pcap-linux.c

diff --git a/CREDITS b/CREDITS
index fadf77f545d0b4b65b6f5e15737d14640b5773ff..97a90c71f56aa2c7bd31ce5a0ecc29399d486d94 100644 (file)
--- a/CREDITS
+++ b/CREDITS
@@ -27,6 +27,7 @@ Additional people who have contributed patches:
        David Young                     <[email protected]>
        Don Ebright                     <[email protected]
        Eric Anderson                   <[email protected]>
+        Erik de Castro Lopo             <[email protected]>
        Franz Schaefer                  <[email protected]>
        Gianluca Varenni                <[email protected]>
        Gisle Vanem                     <[email protected]>
index 61d1c37bab326b9e355a9cea7f0c8e516249def1..c01b08fa54293f1a958153751ae7d3deaaf4c0c1 100644 (file)
@@ -27,7 +27,7 @@
 
 #ifndef lint
 static const char rcsid[] _U_ =
-    "@(#) $Header: /tcpdump/master/libpcap/pcap-linux.c,v 1.103 2003-12-18 23:32:32 guy Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/libpcap/pcap-linux.c,v 1.104 2004-01-02 11:25:26 hannes Exp $ (LBL)";
 #endif
 
 /*
@@ -684,6 +684,8 @@ static int
 pcap_stats_linux(pcap_t *handle, struct pcap_stat *stats)
 {
 #ifdef HAVE_TPACKET_STATS
+        static struct tpacket_stats kstats_total = { 0, 0 };
+
        struct tpacket_stats kstats;
        socklen_t len = sizeof (struct tpacket_stats);
 #endif
@@ -718,8 +720,18 @@ pcap_stats_linux(pcap_t *handle, struct pcap_stat *stats)
                 * "tp_packets" as the count of packets and "tp_drops"
                 * as the count of drops.
                 */
-               handle->md.stat.ps_recv = kstats.tp_packets;
-               handle->md.stat.ps_drop = kstats.tp_drops;
+
+                /*
+                 * Keep a running total because each call to 
+                 *    getsockopt(handle->fd, SOL_PACKET, PACKET_STATISTICS, ....
+                 * resets the counters to zero.
+                 */
+
+                kstats_total.tp_packets += kstats.tp_packets;
+                kstats_total.tp_drops += kstats.tp_drops;
+                handle->md.stat.ps_recv = kstats_total.tp_packets;
+                handle->md.stat.ps_drop = kstats_total.tp_drops;
        }
        else
        {