我的应用程序在以太网接口上随意地嗅探数据包(带有已编译的数据包过滤器),并且我想知道是否有任何数据包被丢弃,并且没有发送到我的应用程序缓冲区。
pcap_stats的手册是模糊的,可能(或不可能)解释这个函数。
那么,如何确定内核、分发和libpcap的特定组合是否支持丢弃数据包检测?
统计数据在所有平台上的表现并不相同。ps_recv可能会对数据包进行计数,无论它们是否传递带有pcap_setfilter(3PCAP)的任何筛选器集,也可能只计算通过筛选器的数据包。它也可能,也可能不会,计算数据包掉落,因为没有空间在操作系统的缓冲区,当他们到达。ps_drop并非在所有平台上都可用;在不可用的平台上为零。如果数据包过滤是在libpcap中完成的,而不是在操作系统中完成的,那么它将对不通过筛选器的数据包进行计数。ps_recv和ps_drop都可能或可能不计算尚未从操作系统读取的数据包,因此应用程序尚未看到。ps_ifdrop可能实现,也可能不实现;如果为零,这可能意味着接口没有丢弃任何数据包,也可能意味着统计数据不可用,因此不应将其视为接口没有丢弃任何数据包的指示。
$ uname -a
Linux dvstorblackXS 3.10.80-1.el6.elrepo.i686 #1 SMP Sun Jun 7 08:15:14 EDT 2015 i686 i686 i386 GNU/Linux
$ ldd *myApplicationBinary*
libpcap.so.1 => /usr/local/lib/libpcap.so.1 (0xb76e2000)
$ ls -l /usr/local/lib/libpcap.*
-rw-r--r-- 1 root root 774522 Mar 5 2016 /usr/local/lib/libpcap.a
lrwxrwxrwx 1 root root 12 Mar 5 2016 /usr/local/lib/libpcap.so -> libpcap.so.1
lrwxrwxrwx 1 root root 16 Mar 5 2016 /usr/local/lib/libpcap.so.1 -> libpcap.so.1.6.2
-rwxr-xr-x 1 root root 572307 Mar 5 2016 /usr/local/lib/libpcap.so.1.6.2
$ cat /etc/redhat-release
CentOS release 6.6 (Final)发布于 2016-11-02 06:11:03
Reports the number of dropped packets iff the kernel supports
the PACKET_STATISTICS "getsockopt()" argument (2.4 and later
kernels, and 2.2[.x] kernels with Alexey Kuznetzov's turbopacket
patches); otherwise, that information isn't available, and we lie
and report 0 as the count of dropped packets.这似乎是关于ps_drop的,它报告:
"ps_drop" counts packets dropped because we ran
out of buffer space. It doesn't count packets
dropped by the interface driver. It counts only
packets that passed the filter.ps_ifdrop似乎被任何内核版本所支持。它报告说:
It will return the number
of drops the interface reports in /proc/net/dev,
if that is available.因此,您可以通过ps_drop + ps_ifdrop获取环境中丢弃数据包的数量。
https://stackoverflow.com/questions/40365863
复制相似问题