direction_name = "\"outgoing only\"";
break;
- case PCAP_D_INOUT:
+ default:
/*
* Incoming and outgoing, so accept both
* incoming and outgoing packets.
+ *
+ * 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.
*/
direction = BPF_D_INOUT;
direction_name = "\"incoming and outgoing\"";
break;
-
- default:
- snprintf(p->errbuf, sizeof(p->errbuf), "Invalid direction");
- return (-1);
}
if (ioctl(p->fd, BIOCSDIRECTION, &direction) == -1) {
direction_name = "\"outgoing only\"";
break;
- case PCAP_D_INOUT:
+ 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;
-
- default:
- snprintf(p->errbuf, sizeof(p->errbuf), "Invalid direction");
- return (-1);
}
if (ioctl(p->fd, BIOCSDIRFILT, &dirfilt) == -1) {
pcap_fmt_errmsg_for_errno(p->errbuf, sizeof(p->errbuf),
"Setting direction to \"outgoing only\" is not supported on this device");
return (-1);
- case PCAP_D_INOUT:
+ default:
/*
* Incoming and outgoing, so we want to see transmitted
* packets.
+ *
+ * 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.
*/
seesent = 1;
direction_name = "\"incoming and outgoing\"";
break;
-
- default:
- snprintf(p->errbuf, sizeof(p->errbuf), "Invalid direction");
- return (-1);
}
if (ioctl(p->fd, BIOCSSEESENT, &seesent) == -1) {
snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
"Setting direction is not supported on this device");
return (-1);
- } else
- return (p->setdirection_op(p, d));
+ } else {
+ switch (d) {
+
+ case PCAP_D_IN:
+ case PCAP_D_OUT:
+ case PCAP_D_INOUT:
+ /*
+ * Valid direction.
+ */
+ return (p->setdirection_op(p, d));
+
+ default:
+ /*
+ * Invalid direction.
+ */
+ snprintf(p->errbuf, sizeof(p->errbuf),
+ "Invalid direction");
+ return (-1);
+ }
+ }
}
int