mirror of
https://github.com/zeek/zeek.git
synced 2025-10-14 04:28:20 +00:00
Allow pcap pktsrc to use other BPF_Program::Compile method
This commit is contained in:
parent
515e5bf8a3
commit
b30d5702f6
6 changed files with 60 additions and 33 deletions
|
@ -268,6 +268,25 @@ bool PcapSource::PrecompileFilter(int index, const std::string& filter)
|
|||
return PktSrc::PrecompileBPFFilter(index, filter);
|
||||
}
|
||||
|
||||
detail::BPF_Program* PcapSource::CompileFilter(const std::string& filter)
|
||||
{
|
||||
std::string errbuf;
|
||||
auto code = std::make_unique<detail::BPF_Program>();
|
||||
|
||||
if ( ! code->Compile(pd, filter.c_str(), Netmask(), errbuf) )
|
||||
{
|
||||
std::string msg = util::fmt("cannot compile BPF filter \"%s\"", filter.c_str());
|
||||
|
||||
if ( ! errbuf.empty() )
|
||||
msg += ": " + errbuf;
|
||||
|
||||
Error(msg);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return code.release();
|
||||
}
|
||||
|
||||
bool PcapSource::SetFilter(int index)
|
||||
{
|
||||
if ( ! pd )
|
||||
|
|
|
@ -31,6 +31,7 @@ protected:
|
|||
bool PrecompileFilter(int index, const std::string& filter) override;
|
||||
bool SetFilter(int index) override;
|
||||
void Statistics(Stats* stats) override;
|
||||
detail::BPF_Program* CompileFilter(const std::string& filter) override;
|
||||
|
||||
private:
|
||||
void OpenLive();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue