Winpcap 用 2 个不同的过滤器监听设备
是否可以监听具有 2 个不同过滤器的设备并捕获数据包?例如,我开始监听带有过滤器的设备并将数据包转储到 pcap 文件,15 分钟后我可以在同一设备上使用不同的过滤器启动另一个监听并将数据包转储到另一个 pcap 文件而不停止旧的文件吗?
pcap_open 或 pcap_next_ex 是否会阻止传入数据包?我的意思是,如果一个数据包在从两个不同线程侦听时到达,其中一个线程将获取该数据包并控制它以进行过滤,另一个线程可以访问该数据包吗?
我希望我对英语不好表示抱歉。
Is it doable to listen a device with 2 different filters and capture packets? For example i start listening a device with a filter and dumping the packets to a pcap file, after 15min can i start another listen on the same device with different filter and dump the packets to another pcap file without stopping the old one?
Does pcap_open or pcap_next_ex block the incoming packets? What i mean if a packet arrives while listening from two different threads one of them will get the packet and control it for filter can the other thread access the packet?
I hope im clear sorry for bad english.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的。尽管如此,您最好在不同的线程/进程中启动该侦听器来处理它。
事实并非如此。如果某一部分(您或操作系统)无法跟上传入数据包,它会将数据包丢弃到您的 pcap 侦听器。
pcap 还会复制数据包(至少是 *nix pcap,假设 winpcap 工作原理相同),因此如果您有多个 pcap 监听器,过滤相同的数据包,它们都会获得一份副本。
Yes. Albeit, you'd better start that listener in a different thread/process to process it.
It does not. It drops the packets to your pcap listener if one part (you or the OS) can't keep up with the incoming packets.
pcap will also duplicate the packets(speaking at least of the *nix pcap, assuming winpcap works the same) so if you have several pcap listners, filtering for the same packets , they will all get a copy.
对于您获得的每个打开设备句柄,您都有一个单独的过滤器和数据包缓冲区。
说句柄“A”和句柄“B”
现在假设两个句柄位于同一网络设备上。
现在假设网络设备收到 4 个数据包。
每个数据包到达硬件驱动程序,然后到达 winpcap。
此时,winpcap 一次应用一个句柄过滤器。
如果匹配,数据包将被复制到处理数据包缓冲区。
处理完所有句柄后,数据包将被移交给操作系统。
pcap_open 或 pcap_next_ex 是否会阻止传入数据包?不。
事实上,操作系统很可能会在您的应用程序处理数据包之前看到该数据包。
我可能是错的,但我不认为 winpcap 有任何阻止数据包的标准方法。
For each open device handle you get, you have a seperate filter, and packet buffer.
say handle 'A' and handle 'B'
now lets say both handles are on the same network device.
Now lets say that the network device gets 4 packets.
each packet gets to the hardware driver, then to winpcap.
at that point winpcap applys each handles filter one at a time.
if a match is made, the packet will be copied to that handles packet buffer.
after all handles have been processed, the packet is handed off to the OS.
Does pcap_open or pcap_next_ex block the incoming packets? No.
The fact is that the operating system, will most likely see the packet before your application will process it.
I may be wrong but I don't think winpcap has any standard method for blocking a packet.