summaryrefslogtreecommitdiff
path: root/bpf.c
diff options
context:
space:
mode:
authorVadim Kochan <vadim4j@gmail.com>2015-11-10 10:28:08 +0200
committerTobias Klauser <tklauser@distanz.ch>2015-11-10 09:44:47 +0100
commit84bf18621169ff4292707bcdcfa0552825757f60 (patch)
tree6b3536f70d6e6f340069d7180b341fae54a91edb /bpf.c
parent9d6b743e76107038d747eda9ab2dbdf03dd15e33 (diff)
netsniff-ng: Allow to specify compiled BPF from stdin
Allow read compiled BPF instructions from stdin by via '-f -' option. Signed-off-by: Vadim Kochan <vadim4j@gmail.com> Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Diffstat (limited to 'bpf.c')
-rw-r--r--bpf.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/bpf.c b/bpf.c
index 2d769ec..66d1b6c 100644
--- a/bpf.c
+++ b/bpf.c
@@ -720,7 +720,11 @@ void bpf_parse_rules(char *rulefile, struct sock_fprog *bpf, uint32_t link_type)
return;
}
- fp = fopen(rulefile, "r");
+ if (!strcmp(rulefile, "-"))
+ fp = stdin;
+ else
+ fp = fopen(rulefile, "r");
+
if (!fp) {
bpf_try_compile(rulefile, bpf, link_type);
return;
@@ -753,7 +757,8 @@ void bpf_parse_rules(char *rulefile, struct sock_fprog *bpf, uint32_t link_type)
fmemset(buff, 0, sizeof(buff));
}
- fclose(fp);
+ if (fp != stdin)
+ fclose(fp);
if (unlikely(__bpf_validate(bpf) == 0))
panic("This is not a valid BPF program!\n");