2 * Small pcap precompiler
3 * Copyright (C) 2008 Felix Fietkau <nbd@openwrt.org>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2
7 * as published by the Free Software Foundation
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
15 #include <sys/types.h>
21 int main (int argc
, char ** argv
)
23 struct bpf_program filter
;
29 printf ("Usage: %s <expression>\n", argv
[0]);
33 pc
= pcap_open_dead(DLT_EN10MB
, 1500);
34 if (pcap_compile(pc
, &filter
, argv
[1], 1, 0) != 0) {
35 printf("error in active-filter expression: %s\n", pcap_geterr(pc
));
39 printf("/* precompiled expression: %s */\n\n"
40 "static struct bpf_insn pktfilter_insns[] = {\n",
43 for (i
= 0; i
< filter
.bf_len
; i
++) {
44 struct bpf_insn
*in
= &filter
.bf_insns
[i
];
45 printf("\t{ .code = 0x%04x, .jt = 0x%02x, .jf = 0x%02x, .k = 0x%08x },\n", in
->code
, in
->jt
, in
->jf
, in
->k
);
48 "static struct bpf_program pktfilter = {\n"
50 "\t.bf_insns = pktfilter_insns,\n"
51 "};\n", filter
.bf_len
);
This page took 0.057497 seconds and 5 git commands to generate.