From eb19780045e383f73ed3e666dcbee06638ab6451 Mon Sep 17 00:00:00 2001 From: Otto Moerbeek Date: Mon, 26 Sep 2005 19:30:49 +0000 Subject: If setting the filter fails, pass the error back; ok deraadt@ --- usr.sbin/tcpdump/privsep_pcap.c | 16 ++++++++++------ 1 file 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); -- cgit v1.2.3