-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Since the setfilter is set after pcap_activate,other packets is written to the libpcap buffer #108
Comments
Do you mean that packets that don't match the new filter show up as libpcap input? If so, on what operating system is this? On systems using the BPF capture mechanism, the On Windows, it appears that Npcap, at least, works the same way. On Linux, libpcap should note internally that some number of blocks have not yet been read and have possibly been added to the ring buffer before the new kernel filter was installed and should itself run all the the packets in all those blocks through the new filter, so that they're discarded if they don't match the new filter. So packets that don't match the new filter shouldn't be provided to the user; if they are provided, that's either a libpcap bug that should be fixed in libpcap, or an OS kernel bug (UN*X) or an Npcap driver bug (Windows) that should be fixed there, not something that's a pypcap bug, as pypcap is just exporting libpcap behavior here. |
(And there' no "clear libpcap buffer" operation in libpcap - as noted, that's what libpcap itself is supposed to do internally - so there's no routine for pypcap to call in order to clear the libpcap buffer.) |
Python on Linux When python defines pcap.pcap(),network packets have been capture into the buffer because pypcap completes pcap_create() and pcap_activate()。After pcap.setfilter() calls pcap_compile() to complete the filter settings,the previously captured packets will occupy the buffer. The packets cannot be get useing readpkts(). pypcap use pcap_create() --> pcap_compile() --> pcap_activate() --> pcap_dispatch() Creating with pcap_create() then setting the rules with pcap_compile() and finally pcap_activate() won't have this problem Or run pcap.readpkts() first to clear the buffer. pc = pcap.pcap(name = interface,) |
You forgot
It will, indeed, not have that particular problem. Instead, it will have the problem that Try the following program (the source code is called "testit.c.txt" rather than "testit.c" because GitHub is unaware that ".c" means "C source file", i.e. that it's a text file): The first argument is an interface name and the second argument is a filter string. |
I forgot pcap_setfilter(), but that's not what I meant. It is right. but pcap.pyx is not like this. It activate the |
No, it's wrong - and deliberately so! I wrote it to demonstrate that your suggested sequence of pcap calls Will. Not. Work., by trying that sequence. In older versions of libpcap, if you call
But that doesn't matter, because if you call In newer versions of libpcap, if you call
Yes, because "this" Does. Not. Work. Instead, it does what does work. |
Thanks. |
When there is a large amount of traffic in the network, if you activate it first and then set the filter, it will cause other data to be written to the buffer.
clear libpcap buffer in the setfilter method
The text was updated successfully, but these errors were encountered: