summaryrefslogtreecommitdiffstats
path: root/usr.sbin/dhcrelay
diff options
context:
space:
mode:
authornatano <natano@openbsd.org>2016-05-28 07:00:18 +0000
committernatano <natano@openbsd.org>2016-05-28 07:00:18 +0000
commit2abf9a0d86fa9b4fb1b6fb30d464b452304d1b90 (patch)
tree3c1599cc8846249363d55b245b3c954b2c92dc84 /usr.sbin/dhcrelay
parentDo the endpoint verification before opening the pipe on the selected (diff)
downloadwireguard-openbsd-2abf9a0d86fa9b4fb1b6fb30d464b452304d1b90.tar.xz
wireguard-openbsd-2abf9a0d86fa9b4fb1b6fb30d464b452304d1b90.zip
Replace the /dev/bpf* open loop with a plain open("/dev/bpf0", ...).
ok deraadt jca
Diffstat (limited to 'usr.sbin/dhcrelay')
-rw-r--r--usr.sbin/dhcrelay/bpf.c29
1 files changed, 8 insertions, 21 deletions
diff --git a/usr.sbin/dhcrelay/bpf.c b/usr.sbin/dhcrelay/bpf.c
index 85ac2c95e9e..9a498c98f23 100644
--- a/usr.sbin/dhcrelay/bpf.c
+++ b/usr.sbin/dhcrelay/bpf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bpf.c,v 1.10 2016/02/07 00:49:28 krw Exp $ */
+/* $OpenBSD: bpf.c,v 1.11 2016/05/28 07:00:18 natano Exp $ */
/* BPF socket interface code, originally contributed by Archie Cobbs. */
@@ -60,9 +60,6 @@
#include "dhcp.h"
#include "dhcpd.h"
-
-#define BPF_FORMAT "/dev/bpf%d"
-
/*
* Called by get_interface_list for each interface that's discovered.
* Opens a packet filter for each interface and adds it to the select
@@ -71,26 +68,16 @@
int
if_register_bpf(struct interface_info *info)
{
- char filename[50];
- int sock, b;
-
- /* Open a BPF device */
- for (b = 0; 1; b++) {
- snprintf(filename, sizeof(filename), BPF_FORMAT, b);
- sock = open(filename, O_RDWR, 0);
- if (sock == -1) {
- if (errno == EBUSY)
- continue;
- else
- error("Can't find free bpf: %m");
- } else
- break;
- }
+ int sock;
+
+ /* Open the BPF device */
+ if ((sock = open("/dev/bpf0", O_RDWR)) == -1)
+ error("Can't open bpf device: %m");
/* Set the BPF device to point at this interface. */
if (ioctl(sock, BIOCSETIF, info->ifp) == -1)
- error("Can't attach interface %s to bpf device %s: %m",
- info->name, filename);
+ error("Can't attach interface %s to bpf device: %m",
+ info->name);
return (sock);
}