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.
13 #include <sys/fsuid.h>
20 static const char *short_options
= "vhi:Vdbf:";
21 static const struct option long_options
[] = {
22 {"input", required_argument
, NULL
, 'i'},
23 {"format", required_argument
, NULL
, 'f'},
24 {"verbose", no_argument
, NULL
, 'V'},
25 {"bypass", no_argument
, NULL
, 'b'},
26 {"dump", no_argument
, NULL
, 'd'},
27 {"version", no_argument
, NULL
, 'v'},
28 {"help", no_argument
, NULL
, 'h'},
32 extern int compile_filter(char *file
, int verbose
, int bypass
, int format
);
34 static void help(void)
36 printf("\nbpfc %s, a tiny BPF compiler\n", VERSION_STRING
);
37 puts("http://www.netsniff-ng.org\n\n"
38 "Usage: bpfc [options] || bpfc <program>\n"
40 " -i|--input <program/-> Berkeley Packet Filter file/stdin\n"
41 " -f|--format <format> Output format: C|netsniff-ng|xt_bpf|tcpdump\n"
42 " -b|--bypass Bypass filter validation (e.g. for bug testing)\n"
43 " -V|--verbose Be more verbose\n"
44 " -d|--dump Dump supported instruction table\n"
45 " -v|--version Print version and exit\n"
46 " -h|--help Print this help and exit\n\n"
49 " bpfc fubar > foo (bpfc -f C -i fubar > foo) --> netsniff-ng -f foo ...\n"
50 " bpfc -f tcpdump -i fubar > foo --> tcpdump -ddd like ...\n"
51 " bpfc -f xt_bpf -b -i fubar\n"
52 " iptables -A INPUT -m bpf --bytecode \"`./bpfc -f xt_bpf -i fubar`\" -j LOG\n"
53 " bpfc - (read from stdin)\n\n"
54 "Please report bugs to <bugs@netsniff-ng.org>\n"
55 "Copyright (C) 2011-2013 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("\nbpfc %s, a tiny BPF compiler\n", VERSION_STRING
);
66 puts("http://www.netsniff-ng.org\n\n"
67 "Please report bugs to <bugs@netsniff-ng.org>\n"
68 "Copyright (C) 2011-2013 Daniel Borkmann <dborkma@tik.ee.ethz.ch>,\n"
69 "Swiss federal institute of technology (ETH Zurich)\n"
70 "License: GNU GPL version 2.0\n"
71 "This is free software: you are free to change and redistribute it.\n"
72 "There is NO WARRANTY, to the extent permitted by law.\n");
76 int main(int argc
, char **argv
)
78 int ret
, verbose
= 0, c
, opt_index
, bypass
= 0, format
= 0;
87 while ((c
= getopt_long(argc
, argv
, short_options
,
88 long_options
, &opt_index
)) != EOF
) {
100 if (!strncmp(optarg
, "C", 1) ||
101 !strncmp(optarg
, "netsniff-ng", 11))
103 else if (!strncmp(optarg
, "xt_bpf", 6))
105 else if (!strncmp(optarg
, "tcpdump", 7))
117 file
= xstrdup(optarg
);
123 panic("Option -%c requires an argument!\n",
127 printf("Unknown option character `0x%X\'!\n", optopt
);
136 file
= xstrdup(argv
[1]);
138 panic("No Berkeley Packet Filter program specified!\n");
140 ret
= compile_filter(file
, verbose
, bypass
, format
);