@@ -4,7 +4,8 @@ AM_CFLAGS = ${regular_CFLAGS}
AM_CPPFLAGS = ${regular_CPPFLAGS} -I${top_builddir}/include \
-I${top_srcdir}/include ${libnfnetlink_CFLAGS}
-sbin_PROGRAMS = nfnl_osf
+sbin_PROGRAMS = nfnl_osf bpf_compile
pkgdata_DATA = pf.os
nfnl_osf_LDADD = -lnfnetlink
+bpf_compile_LDADD = -lpcap
new file mode 100644
@@ -0,0 +1,47 @@
+/*
+ * BPF program compilation tool
+ *
+ * Written by Willem de Bruijn (willemb@google.com)
+ * Copyright Google, Inc. 2012
+ * Licensed under the GNU General Public License version 2 (GPLv2)
+*/
+
+#include <pcap.h>
+#include <stdio.h>
+
+int main(int argc, char **argv)
+{
+ struct bpf_program program;
+ struct bpf_insn *ins;
+ int i, dlt = DLT_RAW;
+
+ if (argc < 2 || argc > 3) {
+ fprintf(stderr, "Usage: %s [linktype] <program>\n"
+ " linktype is one of EN10MB, RAW, ...\n"
+ " program must be one parameter\n",
+ argv[0]);
+ return 1;
+ }
+
+ if (argc == 3) {
+ dlt = pcap_datalink_name_to_val(argv[1]);
+ if (dlt == -1) {
+ fprintf(stderr, "Unknown datalinktype: %s\n", argv[1]);
+ return 1;
+ }
+ }
+
+ printf("Using datalinktype %s\n", pcap_datalink_val_to_name(dlt));
+ if (pcap_compile_nopcap(65535, dlt, &program, argv[argc - 1], 1, 0)) {
+ fprintf(stderr, "Compilation error\n");
+ return 1;
+ }
+
+ printf("%d\n", program.bf_len);
+ ins = program.bf_insns;
+ for (i = 0; i < program.bf_len; ++ins, ++i)
+ printf("%u %u %u %u\n", ins->code, ins->jt, ins->jf, ins->k);
+
+ return 0;
+}
+