summaryrefslogtreecommitdiff
path: root/lib/libpcap
diff options
context:
space:
mode:
authorMartin Natano <natano@cvs.openbsd.org>2016-05-03 07:38:39 +0000
committerMartin Natano <natano@cvs.openbsd.org>2016-05-03 07:38:39 +0000
commit8c8c7790a6d5ed23daf5d4ae042583784c4ed30c (patch)
tree7d1ce1c315bf133834343fc5b1740f7adc3fbf4c /lib/libpcap
parentb8a86b74f449b51ef0bee1c848cc6bdfdb40c521 (diff)
Move to /dev/bpf; ok lteo
Diffstat (limited to 'lib/libpcap')
-rw-r--r--lib/libpcap/pcap-bpf.c71
1 files changed, 11 insertions, 60 deletions
diff --git a/lib/libpcap/pcap-bpf.c b/lib/libpcap/pcap-bpf.c
index f6d658c386e..c28e136d8fe 100644
--- a/lib/libpcap/pcap-bpf.c
+++ b/lib/libpcap/pcap-bpf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pcap-bpf.c,v 1.32 2015/12/22 19:51:04 mmcc Exp $ */
+/* $OpenBSD: pcap-bpf.c,v 1.33 2016/05/03 07:38:38 natano Exp $ */
/*
* Copyright (c) 1993, 1994, 1995, 1996, 1998
@@ -215,69 +215,20 @@ static __inline int
bpf_open(pcap_t *p)
{
int fd;
- int n = 0;
- char device[sizeof "/dev/bpf0000000000"];
- /*
- * Go through all the minors and find one that isn't in use.
- */
- do {
- (void)snprintf(device, sizeof device, "/dev/bpf%d", n++);
- fd = open(device, O_RDWR);
- if (fd < 0 && errno == EACCES)
- fd = open(device, O_RDONLY);
- } while (fd < 0 && errno == EBUSY);
+ fd = open("/dev/bpf", O_RDWR);
+ if (fd == -1 && errno == EACCES)
+ fd = open("/dev/bpf", O_RDONLY);
- /*
- * XXX better message for all minors used
- */
- if (fd < 0) {
- switch (errno) {
-
- case ENOENT:
- fd = PCAP_ERROR;
- if (n == 1) {
- /*
- * /dev/bpf0 doesn't exist, which
- * means we probably have no BPF
- * devices.
- */
- snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
- "(there are no BPF devices)");
- } else {
- /*
- * We got EBUSY on at least one
- * BPF device, so we have BPF
- * devices, but all the ones
- * that exist are busy.
- */
- snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
- "(all BPF devices are busy)");
- }
- break;
-
- case EACCES:
- /*
- * Got EACCES on the last device we tried,
- * and EBUSY on all devices before that,
- * if any.
- */
+ if (fd == -1) {
+ if (errno == EACCES)
fd = PCAP_ERROR_PERM_DENIED;
- snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
- "(cannot open BPF device) %s: %s", device,
- pcap_strerror(errno));
- break;
-
- default:
- /*
- * Some other problem.
- */
+ else
fd = PCAP_ERROR;
- snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
- "(cannot open BPF device) %s: %s", device,
- pcap_strerror(errno));
- break;
- }
+
+ snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
+ "(cannot open BPF device): %s",
+ pcap_strerror(errno));
}
return (fd);