-
-
Save elnemesisdivina/1b1f445cf063b96a388c5996a2a49ea3 to your computer and use it in GitHub Desktop.
BPF compiler using libpcap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <pcap.h> | |
#include <unistd.h> | |
int main(int argc, char **argv) | |
{ | |
struct bpf_program bpfprog; | |
int dflag = 0; | |
int c; | |
while ((c = getopt(argc, argv, "d")) != -1) { | |
switch (c) { | |
case 'd': | |
dflag++; | |
break; | |
default: | |
fprintf(stderr, "Usage: %s [-d|-dd|-ddd] filter\n", argv[0]); | |
return 1; | |
} | |
} | |
if (pcap_compile_nopcap(1, 0, &bpfprog, argv[optind], 0, 0) < 0) { | |
fprintf(stderr, "pcap_compile_nopcap()\n"); | |
return 1; | |
} | |
bpf_dump(&bpfprog, dflag); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment