Libpcap API does not remove filter
I am using lib-pcap library to install / remove filters.
To set the pcap filter I use pcap_compile followed by pcap_setfilter which works great.
and I use pcap_freecode to remove the filter, but unfortunately it doesn't seem to remove the above installation filter.
Any help is appreciated.
source to share
pcap_freecode()
does not, as the name suggests, remove filter settings; if there was an API for installing a filter, it would have a different name. He used freeing memory allocated pcap_compile()
(a copy of which is set pcap_setfilter()
).
Unfortunately, there is no API to set the filter. However, you can install a filter that accepts all packets, which will have the same effect as removing the filter installation. Pass an empty string in pcap_compile()
(empty string, i.e. ""
, not a null pointer) and it will compile that string for a filter that accepts all packets.