/* If we fail to allocate memory for the copy, fill in the "errbuf" member of the "pcap_t" with an error message, and return -1; otherwise, return 0.  */
int install_bpf_program(pcap_t *p, struct bpf_program *fp)
/* If we fail to allocate memory for the copy, fill in the "errbuf" member of the "pcap_t" with an error message, and return -1; otherwise, return 0.  */
int install_bpf_program(pcap_t *p, struct bpf_program *fp)
{
	size_t prog_size;
	if (!bpf_validate(fp->bf_insns, fp->bf_len)) {
		pcap_snprintf(p->errbuf, sizeof(p->errbuf),
			"BPF program is not valid");
		return (-1);
	}
	pcap_freecode(&p->fcode);
	prog_size = sizeof(*fp->bf_insns) * fp->bf_len;
	p->fcode.bf_len = fp->bf_len;
	p->fcode.bf_insns = (struct bpf_insn *)malloc(prog_size);
	if (p->fcode.bf_insns == NULL) {
		pcap_fmt_errmsg_for_errno(p->errbuf, sizeof(p->errbuf),
		    errno, "malloc");
		return (-1);
	}
	memcpy(p->fcode.bf_insns, fp->bf_insns, prog_size);
	return (0);
}