Skip to content

Commit e80b63b

Browse files
committed
"sbh_drops" is cumulative, so we can't add it to the packet receive
count; instead, we add the cumulative drop count to the cumulative receive count in the statistics we're returning.
1 parent dc95138 commit e80b63b

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

pcap-dlpi.c

+13-15
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262

6363
#ifndef lint
6464
static const char rcsid[] _U_ =
65-
"@(#) $Header: /tcpdump/master/libpcap/pcap-dlpi.c,v 1.103 2004-05-21 09:22:16 guy Exp $ (LBL)";
65+
"@(#) $Header: /tcpdump/master/libpcap/pcap-dlpi.c,v 1.104 2004-05-21 09:45:31 guy Exp $ (LBL)";
6666
#endif
6767

6868
#ifdef HAVE_CONFIG_H
@@ -188,11 +188,13 @@ pcap_stats_dlpi(pcap_t *p, struct pcap_stat *ps)
188188
* that passed the filter. As filtering is done in userland,
189189
* this would not include packets dropped because we ran out
190190
* of buffer space; in order to make this more like other
191-
* platforms (and to keep from confusing applications that,
192-
* for example, compute packet drop percentages), we also make it
193-
* count packets dropped by "bufmod" (otherwise we might run
194-
* the risk of the packet drop count being bigger than the
195-
* received-packet count).
191+
* platforms (Linux 2.4 and later, BSDs with BPF), where the
192+
* "packets received" count includes packets received but dropped
193+
* due to running out of buffer space, and to keep from confusing
194+
* applications that, for example, compute packet drop percentages,
195+
* we also make it count packets dropped by "bufmod" (otherwise we
196+
* might run the risk of the packet drop count being bigger than
197+
* the received-packet count).
196198
*
197199
* "ps_drop" counts packets dropped by "bufmod" because of
198200
* flow control requirements or resource exhaustion; it doesn't
@@ -205,6 +207,11 @@ pcap_stats_dlpi(pcap_t *p, struct pcap_stat *ps)
205207
* yet read from libpcap by the application.
206208
*/
207209
*ps = p->md.stat;
210+
211+
/*
212+
* Add in the drop count, as per the above comment.
213+
*/
214+
ps->ps_recv += ps->ps_drop;
208215
return (0);
209216
}
210217

@@ -311,15 +318,6 @@ pcap_read_dlpi(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
311318
#endif
312319
sbp = (struct sb_hdr *)bp;
313320
p->md.stat.ps_drop = sbp->sbh_drops;
314-
/*
315-
* On at least some other platforms (Linux 2.4 and later,
316-
* BSDs with BPF), "ps_recv" counts packets that were
317-
* received but dropped due to running out of buffer
318-
* space; we do that here, so that applications that
319-
* compute packet drop percentages don't see more packets
320-
* dropped than received.
321-
*/
322-
p->md.stat.ps_recv += sbp->sbh_drops;
323321
pk = bp + sizeof(*sbp);
324322
bp += sbp->sbh_totlen;
325323
origlen = sbp->sbh_origlen;

0 commit comments

Comments
 (0)