Exemple #1
0
// Run filter on the given buffer and return its result.
func (f *Filter) Filter(buf []byte) uint {
	cbuf := (*C.char)(unsafe.Pointer(&buf[0]))
	blen := C.uint(len(buf))

	rc := C.bpf_filter(f.program.bf_insns, cbuf, blen, blen)
	return uint(rc)
}
Exemple #2
0
// Try to match the given buffer against the filter.
func (f *Filter) Match(buf []byte) bool {
	cbuf := (*C.char)(unsafe.Pointer(&buf[0]))
	blen := C.uint(len(buf))

	if C.bpf_filter(f.program.bf_insns, cbuf, blen, blen) > 0 {
		return true
	}

	return false
}