2 * netsniff-ng - the packet sniffing beast
3 * By Daniel Borkmann <daniel@netsniff-ng.org>
4 * Copyright 2011 Daniel Borkmann <dborkma@tik.ee.ethz.ch>,
5 * Swiss federal institute of technology (ETH Zurich)
6 * Subject to the GPL, version 2.
8 * This is a tiny Berkeley Packet Filter compiler that understands the
9 * Syntax / Semantic from the USENIX paper {"The BSD Packet Filter: A New
10 * Architecture for User-level Packet Capture", McCanne, Steven and
11 * Jacobson, Van, Lawrence Berkeley Laboratory}. With this, BPFs can be
12 * written the good old way and understood by the Linux kernel and *BSD
13 * kernels where Berkeley Packet Filters are used.
15 * The one small garden of a free gardener was all his need and due, not
16 * a garden swollen to a realm; his own hands to use, not the hands of
19 * -- The Lord of the Rings, Sam, Chapter 'The Tower of Cirith Ungol'.
27 #include <sys/fsuid.h>
34 static const char *short_options
= "vhi:Vdb";
35 static const struct option long_options
[] = {
36 {"input", required_argument
, NULL
, 'i'},
37 {"verbose", no_argument
, NULL
, 'V'},
38 {"bypass", no_argument
, NULL
, 'b'},
39 {"dump", no_argument
, NULL
, 'd'},
40 {"version", no_argument
, NULL
, 'v'},
41 {"help", no_argument
, NULL
, 'h'},
45 extern int compile_filter(char *file
, int verbose
, int bypass
);
47 static void help(void)
49 printf("\nbpfc %s, a tiny BPF compiler\n", VERSION_STRING
);
50 puts("http://www.netsniff-ng.org\n\n"
51 "Usage: bpfc [options] || bpfc <program>\n"
53 " -i|--input <program/-> Berkeley Packet Filter file/stdin\n"
54 " -V|--verbose Be more verbose\n"
55 " -b|--bypass Bypass filter validation (e.g. for bug testing)\n"
56 " -d|--dump Dump supported instruction table\n"
57 " -v|--version Print version\n"
58 " -h|--help Print this help\n\n"
62 " bpfc - (read from stdin)\n\n"
63 "Please report bugs to <bugs@netsniff-ng.org>\n"
64 "Copyright (C) 2011-2013 Daniel Borkmann <dborkma@tik.ee.ethz.ch>,\n"
65 "Swiss federal institute of technology (ETH Zurich)\n"
66 "License: GNU GPL version 2.0\n"
67 "This is free software: you are free to change and redistribute it.\n"
68 "There is NO WARRANTY, to the extent permitted by law.\n");
72 static void version(void)
74 printf("\nbpfc %s, a tiny BPF compiler\n", VERSION_STRING
);
75 puts("http://www.netsniff-ng.org\n\n"
76 "Please report bugs to <bugs@netsniff-ng.org>\n"
77 "Copyright (C) 2011-2013 Daniel Borkmann <dborkma@tik.ee.ethz.ch>,\n"
78 "Swiss federal institute of technology (ETH Zurich)\n"
79 "License: GNU GPL version 2.0\n"
80 "This is free software: you are free to change and redistribute it.\n"
81 "There is NO WARRANTY, to the extent permitted by law.\n");
85 int main(int argc
, char **argv
)
87 int ret
, verbose
= 0, c
, opt_index
, bypass
= 0;
96 while ((c
= getopt_long(argc
, argv
, short_options
,
97 long_options
, &opt_index
)) != EOF
) {
115 file
= xstrdup(optarg
);
120 panic("Option -%c requires an argument!\n",
124 whine("Unknown option character "
125 "`0x%X\'!\n", optopt
);
134 file
= xstrdup(argv
[1]);
136 panic("No Berkeley Packet Filter program specified!\n");
138 ret
= compile_filter(file
, verbose
, bypass
);