diff options
-rw-r--r-- | pppd/pcap_pcc.c | 74 | ||||
-rw-r--r-- | pppd/pcap_pcc.h | 7 |
2 files changed, 81 insertions, 0 deletions
diff --git a/pppd/pcap_pcc.c b/pppd/pcap_pcc.c new file mode 100644 index 0000000..770c338 --- /dev/null +++ b/pppd/pcap_pcc.c @@ -0,0 +1,74 @@ +#include <pcap.h> +#include <pcap-bpf.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> +#include "pppd.h" + +int pcap_pre_compiled (char * fname, struct bpf_program *p) +{ + char buf[128]; + int line = 0, size = 0, index=0, ret=1; + FILE *f = fopen (fname, "r"); + if (!f) + { + option_error("error opening precompiled active-filter '%s': %s", + fname, strerror (errno)); + return 0; + } + while (fgets (buf, 127, f)) + { + line++; + if (*buf == '#') + continue; + if (size) + { + /* + struct bpf_insn { + u_short code; + u_char jt; + u_char jf; + bpf_int32 k; + } + */ + struct bpf_insn * insn = & p->bf_insns[index]; + unsigned code, jt, jf, k; + if (sscanf (buf, "%u %u %u %u", &code, &jt, &jf, &k) != 4) + { + goto err; + } + insn->code = code; + insn->jt = jt; + insn->jf = jf; + insn->k = k; + index++; + } + else + { + if (sscanf (buf, "%u", &size) != 1) + { + goto err; + } + p->bf_len = size; + p->bf_insns = (struct bpf_insn *) + malloc (size * sizeof (struct bpf_insn)); + } + } + if (size != index) + { + option_error("error in precompiled active-filter," + " expected %d expressions, got %dn", + size, index); + ret = 0; + } + fclose(f); + return ret; + +err: + option_error("error in precompiled active-filter" + " expression line %s:%d (wrong size)\n", + fname, line); + fclose (f); + return 0; +} diff --git a/pppd/pcap_pcc.h b/pppd/pcap_pcc.h new file mode 100644 index 0000000..a0b18d7 --- /dev/null +++ b/pppd/pcap_pcc.h @@ -0,0 +1,7 @@ +#ifndef PCAP_PCC_H +#define PCAP_PCC_H + +#include <pcap.h> + +int pcap_pre_compiled (char * fname, struct bpf_program *p); +#endif /* PCAP_PCC_H */ |