- if (ioctl(p->fd, BIOCVERSION, (caddr_t)&bv) < 0) {
- snprintf(p->errbuf, sizeof(p->errbuf),
- "BIOCVERSION: %s", pcap_strerror(errno));
- return (-1);
- }
- else if (bv.bv_major != BPF_MAJOR_VERSION ||
- bv.bv_minor < BPF_MINOR_VERSION) {
- fprintf(stderr,
- "requires bpf language %d.%d or higher; kernel is %d.%d",
- BPF_MAJOR_VERSION, BPF_MINOR_VERSION,
- bv.bv_major, bv.bv_minor);
- /* don't give up, just be inefficient */
- p->md.use_bpf = 0;
+ /*
+ * OK, that succeeded. We're doing filtering in
+ * the kernel. (We assume we don't have a
+ * userland filter installed - that'd require
+ * a previous version check to have failed but
+ * this one to succeed.)
+ *
+ * XXX - this message should be supplied to the
+ * application as a warning of some sort,
+ * except that if it's a GUI application, it's
+ * not clear that it should be displayed in
+ * a window to annoy the user.
+ */
+ fprintf(stderr, "tcpdump: Using kernel BPF filter\n");
+ pf->filtering_in_kernel = 1;
+
+ /*
+ * Discard any previously-received packets,
+ * as they might have passed whatever filter
+ * was formerly in effect, but might not pass
+ * this filter (BIOCSETF discards packets buffered
+ * in the kernel, so you can lose packets in any
+ * case).
+ */
+ p->cc = 0;
+ return (0);