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'.
30 static const char *short_options
= "vhi:V";
31 static const struct option long_options
[] = {
32 {"input", required_argument
, NULL
, 'i'},
33 {"verbose", no_argument
, NULL
, 'V'},
34 {"version", no_argument
, NULL
, 'v'},
35 {"help", no_argument
, NULL
, 'h'},
39 extern int compile_filter(char *file
, int verbose
);
41 static void help(void)
43 printf("\n%s %s, a tiny BPF compiler\n",
44 PROGNAME_STRING
, VERSION_STRING
);
45 puts("http://www.netsniff-ng.org\n\n"
46 "Usage: bpfc [options] || bpfc <program>\n"
48 " -i|--input <program> Berkeley Packet Filter file\n"
49 " -V|--verbose Be more verbose\n"
50 " -v|--version Print version\n"
51 " -h|--help Print this help\n\n"
53 " bpfc -i fubar.bpf\n\n"
54 "Please report bugs to <bugs@netsniff-ng.org>\n"
55 "Copyright (C) 2011-2012 Daniel Borkmann <dborkma@tik.ee.ethz.ch>,\n"
56 "Swiss federal institute of technology (ETH Zurich)\n"
57 "License: GNU GPL version 2.0\n"
58 "This is free software: you are free to change and redistribute it.\n"
59 "There is NO WARRANTY, to the extent permitted by law.\n");
63 static void version(void)
65 printf("\n%s %s, a tiny BPF compiler\n",
66 PROGNAME_STRING
, VERSION_STRING
);
67 puts("http://www.netsniff-ng.org\n\n"
68 "Please report bugs to <bugs@netsniff-ng.org>\n"
69 "Copyright (C) 2011-2012 Daniel Borkmann <dborkma@tik.ee.ethz.ch>,\n"
70 "Swiss federal institute of technology (ETH Zurich)\n"
71 "License: GNU GPL version 2.0\n"
72 "This is free software: you are free to change and redistribute it.\n"
73 "There is NO WARRANTY, to the extent permitted by law.\n");
77 int main(int argc
, char **argv
)
79 int ret
, verbose
= 0, c
, opt_index
;
85 while (argc
> 2 && (c
= getopt_long(argc
, argv
, short_options
,
86 long_options
, &opt_index
)) != EOF
) {
98 file
= xstrdup(optarg
);
103 panic("Option -%c requires an argument!\n",
107 whine("Unknown option character "
108 "`0x%X\'!\n", optopt
);
116 file
= xstrdup(argv
[1]);
119 panic("No Berkeley Packet Filter program specified!\n");
120 ret
= compile_filter(file
, verbose
);