summaryrefslogtreecommitdiffstats
path: root/usr.sbin/dhcpd/bpf.c
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/dhcpd/bpf.c
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/dhcpd/bpf.c')
-rw-r--r--usr.sbin/dhcpd/bpf.c27
1 files changed, 7 insertions, 20 deletions
diff --git a/usr.sbin/dhcpd/bpf.c b/usr.sbin/dhcpd/bpf.c
index 6d54149c753..b84fb6d6c89 100644
--- a/usr.sbin/dhcpd/bpf.c
+++ b/usr.sbin/dhcpd/bpf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bpf.c,v 1.13 2016/02/06 23:50:10 krw Exp $ */
+/* $OpenBSD: bpf.c,v 1.14 2016/05/28 07:00:18 natano Exp $ */
/* BPF socket interface code, originally contributed by Archie Cobbs. */
@@ -63,8 +63,6 @@
#include "tree.h"
#include "dhcpd.h"
-#define BPF_FORMAT "/dev/bpf%d"
-
ssize_t send_packet (struct interface_info *, struct dhcp_packet *,
size_t, struct in_addr, struct sockaddr_in *, struct hardware *);
@@ -76,26 +74,15 @@ ssize_t send_packet (struct interface_info *, struct dhcp_packet *,
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;
+
+ 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);
info->send_packet = send_packet;
return (sock);