Skip to content

Commit

Permalink
Fix BPF filter when listen on all interfaces
Browse files Browse the repository at this point in the history
It was caching bpf filter of first interface
  • Loading branch information
buger committed Jul 6, 2021
1 parent 92c63de commit a727ade
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions capture/capture.go
Expand Up @@ -284,14 +284,16 @@ func (l *Listener) PcapHandle(ifi pcap.Interface) (handle *pcap.Handle, err erro
if err != nil {
return nil, fmt.Errorf("PCAP Activate device error: %q, interface: %q", err, ifi.Name)
}
if l.BPFFilter == "" {
l.BPFFilter = l.Filter(ifi)

bpfFilter := l.BPFFilter
if bpfFilter == "" {
bpfFilter = l.Filter(ifi)
}
fmt.Println("Interface:", ifi.Name, ". BPF Filter:", l.BPFFilter)
err = handle.SetBPFFilter(l.BPFFilter)
fmt.Println("Interface:", ifi.Name, ". BPF Filter:", bpfFilter)
err = handle.SetBPFFilter(bpfFilter)
if err != nil {
handle.Close()
return nil, fmt.Errorf("BPF filter error: %q%s, interface: %q", err, l.BPFFilter, ifi.Name)
return nil, fmt.Errorf("BPF filter error: %q%s, interface: %q", err, bpfFilter, ifi.Name)
}
return
}
Expand Down

0 comments on commit a727ade

Please sign in to comment.