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