3 @@ -491,20 +491,6 @@ pcap_compile_nopcap(int snaplen_arg, int
7 - * Clean up a "struct bpf_program" by freeing all the memory allocated
11 -pcap_freecode(struct bpf_program *program)
13 - program->bf_len = 0;
14 - if (program->bf_insns != NULL) {
15 - free((char *)program->bf_insns);
16 - program->bf_insns = NULL;
21 * Backpatch the blocks in 'list' to 'target'. The 'sense' field indicates
22 * which of the jt and jf fields has been resolved and which is a pointer
23 * back to another unresolved block (or nil). At least one of the fields
26 @@ -748,6 +748,59 @@ static const u_char charmap[] = {
27 (u_char)'\374', (u_char)'\375', (u_char)'\376', (u_char)'\377',
31 + * Clean up a "struct bpf_program" by freeing all the memory allocated
35 +pcap_freecode(struct bpf_program *program)
37 + program->bf_len = 0;
38 + if (program->bf_insns != NULL) {
39 + free((char *)program->bf_insns);
40 + program->bf_insns = NULL;
45 + * Make a copy of a BPF program and put it in the "fcode" member of
48 + * If we fail to allocate memory for the copy, fill in the "errbuf"
49 + * member of the "pcap_t" with an error message, and return -1;
50 + * otherwise, return 0.
53 +install_bpf_program(pcap_t *p, struct bpf_program *fp)
58 + * Validate the program.
60 + if (!bpf_validate(fp->bf_insns, fp->bf_len)) {
61 + snprintf(p->errbuf, sizeof(p->errbuf),
62 + "BPF program is not valid");
67 + * Free up any already installed program.
69 + pcap_freecode(&p->fcode);
71 + prog_size = sizeof(*fp->bf_insns) * fp->bf_len;
72 + p->fcode.bf_len = fp->bf_len;
73 + p->fcode.bf_insns = (struct bpf_insn *)malloc(prog_size);
74 + if (p->fcode.bf_insns == NULL) {
75 + snprintf(p->errbuf, sizeof(p->errbuf),
76 + "malloc: %s", pcap_strerror(errno));
79 + memcpy(p->fcode.bf_insns, fp->bf_insns, prog_size);
84 pcap_strcasecmp(const char *s1, const char *s2)
88 @@ -2292,45 +2292,6 @@ icode_to_fcode(root, lenp)
93 - * Make a copy of a BPF program and put it in the "fcode" member of
96 - * If we fail to allocate memory for the copy, fill in the "errbuf"
97 - * member of the "pcap_t" with an error message, and return -1;
98 - * otherwise, return 0.
101 -install_bpf_program(pcap_t *p, struct bpf_program *fp)
106 - * Validate the program.
108 - if (!bpf_validate(fp->bf_insns, fp->bf_len)) {
109 - snprintf(p->errbuf, sizeof(p->errbuf),
110 - "BPF program is not valid");
115 - * Free up any already installed program.
117 - pcap_freecode(&p->fcode);
119 - prog_size = sizeof(*fp->bf_insns) * fp->bf_len;
120 - p->fcode.bf_len = fp->bf_len;
121 - p->fcode.bf_insns = (struct bpf_insn *)malloc(prog_size);
122 - if (p->fcode.bf_insns == NULL) {
123 - snprintf(p->errbuf, sizeof(p->errbuf),
124 - "malloc: %s", pcap_strerror(errno));
127 - memcpy(p->fcode.bf_insns, fp->bf_insns, prog_size);