From 84bf18621169ff4292707bcdcfa0552825757f60 Mon Sep 17 00:00:00 2001 From: Vadim Kochan Date: Tue, 10 Nov 2015 10:28:08 +0200 Subject: 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 Signed-off-by: Tobias Klauser --- bpf.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'bpf.c') 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"); -- cgit v1.2.3-54-g00ecf