Skip to content

Instantly share code, notes, and snippets.

@kyleconroy
Created March 5, 2014 09:46
Show Gist options
  • Save kyleconroy/9364253 to your computer and use it in GitHub Desktop.
Save kyleconroy/9364253 to your computer and use it in GitHub Desktop.
// SetBPFFilter compiles and sets a BPF filter for the pcap handle.
func (p *Handle) SetBPFFilter(expr string) (err error) {
p.activate.Do(p.activation)
var bpf _Ctype_struct_bpf_program
cexpr := C.CString(expr)
defer C.free(unsafe.Pointer(cexpr))
if -1 == C.pcap_compile(p.cptr, &bpf, cexpr, 1, 0) {
return p.Error()
}
if -1 == C.pcap_setfilter(p.cptr, &bpf) {
C.pcap_freecode(&bpf)
return p.Error()
}
C.pcap_freecode(&bpf)
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment