2 * netsniff-ng - the packet sniffing beast
3 * Copyright 2011 Daniel Borkmann <dborkma@tik.ee.ethz.ch>,
4 * Swiss federal institute of technology (ETH Zurich)
5 * Subject to the GPL, version 2.
7 * The one small garden of a free gardener was all his need and due, not
8 * a garden swollen to a realm; his own hands to use, not the hands of
11 * -- The Lord of the Rings, Sam, Chapter 'The Tower of Cirith Ungol'.
19 #include <sys/fsuid.h>
26 static const char *short_options
= "vhi:VdbD";
27 static const struct option long_options
[] = {
28 {"input", required_argument
, NULL
, 'i'},
29 {"verbose", no_argument
, NULL
, 'V'},
30 {"decimal", no_argument
, NULL
, 'D'},
31 {"bypass", no_argument
, NULL
, 'b'},
32 {"dump", no_argument
, NULL
, 'd'},
33 {"version", no_argument
, NULL
, 'v'},
34 {"help", no_argument
, NULL
, 'h'},
38 extern int compile_filter(char *file
, int verbose
, int bypass
, int decimal
);
40 static void help(void)
42 printf("\nbpfc %s, a tiny BPF compiler\n", VERSION_STRING
);
43 puts("http://www.netsniff-ng.org\n\n"
44 "Usage: bpfc [options] || bpfc <program>\n"
46 " -i|--input <program/-> Berkeley Packet Filter file/stdin\n"
47 " -D|--decimal Decimal output, e.g. for xt_bpf\n"
48 " -V|--verbose Be more verbose\n"
49 " -b|--bypass Bypass filter validation (e.g. for bug testing)\n"
50 " -d|--dump Dump supported instruction table\n"
51 " -v|--version Print version\n"
52 " -h|--help Print this help\n\n"
56 " bpfc - (read from stdin)\n\n"
57 "Please report bugs to <bugs@netsniff-ng.org>\n"
58 "Copyright (C) 2011-2013 Daniel Borkmann <dborkma@tik.ee.ethz.ch>,\n"
59 "Swiss federal institute of technology (ETH Zurich)\n"
60 "License: GNU GPL version 2.0\n"
61 "This is free software: you are free to change and redistribute it.\n"
62 "There is NO WARRANTY, to the extent permitted by law.\n");
66 static void version(void)
68 printf("\nbpfc %s, a tiny BPF compiler\n", VERSION_STRING
);
69 puts("http://www.netsniff-ng.org\n\n"
70 "Please report bugs to <bugs@netsniff-ng.org>\n"
71 "Copyright (C) 2011-2013 Daniel Borkmann <dborkma@tik.ee.ethz.ch>,\n"
72 "Swiss federal institute of technology (ETH Zurich)\n"
73 "License: GNU GPL version 2.0\n"
74 "This is free software: you are free to change and redistribute it.\n"
75 "There is NO WARRANTY, to the extent permitted by law.\n");
79 int main(int argc
, char **argv
)
81 int ret
, verbose
= 0, c
, opt_index
, bypass
= 0, decimal
= 0;
90 while ((c
= getopt_long(argc
, argv
, short_options
,
91 long_options
, &opt_index
)) != EOF
) {
112 file
= xstrdup(optarg
);
117 panic("Option -%c requires an argument!\n",
121 printf("Unknown option character `0x%X\'!\n", optopt
);
130 file
= xstrdup(argv
[1]);
132 panic("No Berkeley Packet Filter program specified!\n");
134 ret
= compile_filter(file
, verbose
, bypass
, decimal
);