diff options
author | Vadim Kochan <vadim4j@gmail.com> | 2015-11-10 10:28:08 +0200 |
---|---|---|
committer | Tobias Klauser <tklauser@distanz.ch> | 2015-11-10 09:44:47 +0100 |
commit | 84bf18621169ff4292707bcdcfa0552825757f60 (patch) | |
tree | 6b3536f70d6e6f340069d7180b341fae54a91edb /bpf.c | |
parent | 9d6b743e76107038d747eda9ab2dbdf03dd15e33 (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.c | 9 |
1 files changed, 7 insertions, 2 deletions
@@ -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"); |