diff options
author | Otto Moerbeek <otto@cvs.openbsd.org> | 2005-09-26 19:30:49 +0000 |
---|---|---|
committer | Otto Moerbeek <otto@cvs.openbsd.org> | 2005-09-26 19:30:49 +0000 |
commit | eb19780045e383f73ed3e666dcbee06638ab6451 (patch) | |
tree | 6e09ed4549eec6dd80b4f70bab943c684265bfc7 | |
parent | 3ff4d64c9307cff91b76014296e262935d36c87e (diff) |
If setting the filter fails, pass the error back;
ok deraadt@
-rw-r--r-- | usr.sbin/tcpdump/privsep_pcap.c | 16 |
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); |