+ errno, "Cannot set direction to %s", direction_name);
+ return (-1);
+ }
+ return (0);
+}
+#elif defined(BIOCSDIRFILT)
+static int
+pcap_setdirection_bpf(pcap_t *p, pcap_direction_t d)
+{
+ u_int dirfilt;
+ const char *direction_name;
+
+ /*
+ * OpenBSD; same functionality, different names, different
+ * semantics (the flags mean "*don't* capture packets in
+ * that direction", not "*capture only* packets in that
+ * direction").
+ */
+ switch (d) {
+
+ case PCAP_D_IN:
+ /*
+ * Incoming, but not outgoing, so filter out
+ * outgoing packets.
+ */
+ dirfilt = BPF_DIRECTION_OUT;
+ direction_name = "\"incoming only\"";
+ break;
+
+ case PCAP_D_OUT:
+ /*
+ * Outgoing, but not incoming, so filter out
+ * incoming packets.
+ */
+ dirfilt = BPF_DIRECTION_IN;
+ direction_name = "\"outgoing only\"";
+ break;
+
+ default:
+ /*
+ * Incoming and outgoing, so don't filter out
+ * any packets based on direction.
+ *
+ * It's guaranteed, at this point, that d is a valid
+ * direction value, so we know that this is PCAP_D_INOUT
+ * if it's not PCAP_D_IN or PCAP_D_OUT.
+ */
+ dirfilt = 0;
+ direction_name = "\"incoming and outgoing\"";
+ break;
+ }
+ if (ioctl(p->fd, BIOCSDIRFILT, &dirfilt) == -1) {
+ pcap_fmt_errmsg_for_errno(p->errbuf, sizeof(p->errbuf),
+ errno, "Cannot set direction to %s", direction_name);