summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorOtto Moerbeek <otto@cvs.openbsd.org>2005-09-26 19:30:49 +0000
committerOtto Moerbeek <otto@cvs.openbsd.org>2005-09-26 19:30:49 +0000
commiteb19780045e383f73ed3e666dcbee06638ab6451 (patch)
tree6e09ed4549eec6dd80b4f70bab943c684265bfc7 /usr.sbin
parent3ff4d64c9307cff91b76014296e262935d36c87e (diff)
If setting the filter fails, pass the error back;
ok deraadt@
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/tcpdump/privsep_pcap.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/usr.sbin/tcpdump/privsep_pcap.c b/usr.sbin/tcpdump/privsep_pcap.c
index a6806471bda..4b4071c98b8 100644
--- a/usr.sbin/tcpdump/privsep_pcap.c
+++ b/usr.sbin/tcpdump/privsep_pcap.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: privsep_pcap.c,v 1.9 2005/05/22 19:53:33 moritz Exp $ */
+/* $OpenBSD: privsep_pcap.c,v 1.10 2005/09/26 19:30:48 otto Exp $ */
/*
* Copyright (c) 2004 Can Erkin Acar
@@ -78,19 +78,23 @@ setfilter(int bpfd, int sock, char *filter)
if (pcap_compile(&hpcap, &fcode, filter, oflag, netmask))
goto err;
+ /* if bpf descriptor is open, set the filter XXX check oflag? */
+ if (bpfd >= 0 && ioctl(bpfd, BIOCSETF, &fcode)) {
+ snprintf(hpcap.errbuf, PCAP_ERRBUF_SIZE,
+ "ioctl: BIOCSETF: %s", strerror(errno));
+ pcap_freecode(&fcode);
+ goto err;
+ }
/* write the filter */
must_write(sock, &fcode.bf_len, sizeof(fcode.bf_len));
if (fcode.bf_len > 0)
must_write(sock, fcode.bf_insns,
fcode.bf_len * sizeof(struct bpf_insn));
else {
- write_string(sock, "Invalid filter size");
- return (1);
+ snprintf(hpcap.errbuf, PCAP_ERRBUF_SIZE, "Invalid filter size");
+ goto err;
}
- /* if bpf descriptor is open, set the filter XXX check oflag? */
- if (bpfd >= 0 && ioctl(bpfd, BIOCSETF, &fcode))
- return 1;
pcap_freecode(&fcode);
return (0);