2 * netsniff-ng - the packet sniffing beast
3 * Copyright 2013 Daniel Borkmann.
4 * Subject to the GPL, version 2.
8 #include <linux/filter.h>
15 void bpf_try_compile(const char *rulefile
, struct sock_fprog
*bpf
, uint32_t link_type
)
18 const struct bpf_insn
*ins
;
19 struct sock_filter
*out
;
20 struct bpf_program _bpf
;
22 ret
= pcap_compile_nopcap(65535, link_type
, &_bpf
, rulefile
, 1, 0xffffffff);
24 panic("Cannot compile filter: %s\n", rulefile
);
26 bpf
->len
= _bpf
.bf_len
;
27 bpf
->filter
= xrealloc(bpf
->filter
, bpf
->len
* sizeof(*out
));
29 for (i
= 0, ins
= _bpf
.bf_insns
, out
= bpf
->filter
; i
< bpf
->len
;
31 out
->code
= ins
->code
;
36 if (out
->code
== 0x06 && out
->k
> 0)
42 if (__bpf_validate(bpf
) == 0)
43 panic("This is not a valid BPF program!\n");