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