PR/3343: Jonathan Stone: Errors and warnings to stderr if interactive

This commit is contained in:
christos 2003-04-20 00:17:22 +00:00
parent 1368d826d9
commit 10dd0ebe00
4 changed files with 49 additions and 69 deletions

View File

@ -1,11 +1,11 @@
# $NetBSD: Makefile,v 1.5 2002/09/18 13:31:54 lukem Exp $
# $NetBSD: Makefile,v 1.6 2003/04/20 00:17:22 christos Exp $
NOLINT= # defined
NOPIC= # defined
NOPROFILE= # defined
LIB= common
SRCS= cmp.c device.c dl.c file.c get.c loop-bsd.c mopdef.c nma.c pf.c \
SRCS= cmp.c device.c dl.c file.c get.c log.c loop-bsd.c mopdef.c nma.c pf.c \
print.c put.c rc.c version.c
CLEANFILES= version.c

View File

@ -1,4 +1,4 @@
/* $NetBSD: device.c,v 1.5 2002/08/22 07:18:42 itojun Exp $ */
/* $NetBSD: device.c,v 1.6 2003/04/20 00:17:22 christos Exp $ */
/*
* Copyright (c) 1993-95 Mats O Jansson. All rights reserved.
@ -31,7 +31,7 @@
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: device.c,v 1.5 2002/08/22 07:18:42 itojun Exp $");
__RCSID("$NetBSD: device.c,v 1.6 2003/04/20 00:17:22 christos Exp $");
#endif
#include "os.h"
@ -39,6 +39,7 @@ __RCSID("$NetBSD: device.c,v 1.5 2002/08/22 07:18:42 itojun Exp $");
#include "device.h"
#include "mopdef.h"
#include "pf.h"
#include "log.h"
struct if_info *iflist; /* Interface List */
@ -66,18 +67,14 @@ deviceEthAddr(ifname, eaddr)
and find the right one. */
/* Use datagram socket to get Ethernet address. */
if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
syslog(LOG_ERR, "deviceEthAddr: socket: %m");
exit(1);
}
if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
mopLogErr("deviceEthAddr: socket");
ifc.ifc_len = sizeof(inbuf);
ifc.ifc_buf = inbuf;
if (ioctl(fd, SIOCGIFCONF, (caddr_t)&ifc) < 0 ||
ifc.ifc_len < sizeof(struct ifreq)) {
syslog(LOG_ERR, "deviceEthAddr: SIOGIFCONF: %m");
exit(1);
}
ifc.ifc_len < sizeof(struct ifreq))
mopLogErr("deviceEthAddr: SIOGIFCONF");
ifr = ifc.ifc_req;
for (i = 0; i < ifc.ifc_len;
i += len, ifr = (struct ifreq *)((caddr_t)ifr + len)) {
@ -92,8 +89,7 @@ deviceEthAddr(ifname, eaddr)
}
}
syslog(LOG_ERR, "deviceEthAddr: Never saw interface `%s'!", ifname);
exit(1);
mopLogErrX("deviceEthAddr: Never saw interface `%s'!", ifname);
}
#endif /* DEV_NEW_CONF */
@ -124,10 +120,8 @@ deviceOpen(ifname, proto, trans)
if (tmp.fd != -1) {
p = (struct if_info *)malloc(sizeof(*p));
if (p == 0) {
syslog(LOG_ERR, "deviceOpen: malloc: %m");
exit(1);
}
if (p == 0)
mopLogErr("deviceOpen: malloc");
p->next = iflist;
iflist = p;
@ -196,7 +190,8 @@ deviceInitOne(ifname)
}
}
syslog(LOG_INFO, "Initialized %s", interface);
if (!mopInteractive)
syslog(LOG_INFO, "Initialized %s", interface);
/* Ok, get transport information */
@ -260,18 +255,14 @@ deviceInitAll()
int fd;
int i, len;
if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
syslog(LOG_ERR, "deviceInitAll: socket: %m");
exit(1);
}
if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
mopLogErr("deviceInitAll: socket");
ifc.ifc_len = sizeof(inbuf);
ifc.ifc_buf = inbuf;
if (ioctl(fd, SIOCGIFCONF, (caddr_t)&ifc) < 0 ||
ifc.ifc_len < sizeof(struct ifreq)) {
syslog(LOG_ERR, "deviceInitAll: SIOCGIFCONF: %m");
exit(1);
}
ifc.ifc_len < sizeof(struct ifreq))
mopLogErr("deviceInitAll: SIOCGIFCONF");
ifr = ifc.ifc_req;
for (i = 0; i < ifc.ifc_len;
i += len, ifr = (struct ifreq *)((caddr_t)ifr + len)) {
@ -281,7 +272,7 @@ deviceInitAll()
sdl->sdl_alen != 6)
continue;
if (ioctl(fd, SIOCGIFFLAGS, (caddr_t)ifr) < 0) {
syslog(LOG_ERR, "deviceInitAll: SIOCGIFFLAGS: %m");
mopLogWarn("deviceInitAll: SIOCGIFFLAGS");
continue;
}
if ((ifr->ifr_flags &
@ -296,17 +287,13 @@ deviceInitAll()
struct ifreq ibuf[8], *ifrp;
struct ifconf ifc;
if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
syslog(LOG_ERR, "deviceInitAll: old socket: %m");
exit(1);
}
if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
mopLogErr("deviceInitAll: old socket");
ifc.ifc_len = sizeof ibuf;
ifc.ifc_buf = (caddr_t)ibuf;
if (ioctl(fd, SIOCGIFCONF, (char *)&ifc) < 0 ||
ifc.ifc_len < sizeof(struct ifreq)) {
syslog(LOG_ERR, "deviceInitAll: old SIOCGIFCONF: %m");
exit(1);
}
ifc.ifc_len < sizeof(struct ifreq))
mopLogErr("deviceInitAll: old SIOCGIFCONF");
ifrp = ibuf;
n = ifc.ifc_len / sizeof(*ifrp);
for (; --n >= 0; ++ifrp) {

View File

@ -1,4 +1,4 @@
/* $NetBSD: loop-bsd.c,v 1.6 2002/09/20 14:16:03 mycroft Exp $ */
/* $NetBSD: loop-bsd.c,v 1.7 2003/04/20 00:17:22 christos Exp $ */
/*
* Copyright (c) 1993-95 Mats O Jansson. All rights reserved.
@ -31,7 +31,7 @@
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: loop-bsd.c,v 1.6 2002/09/20 14:16:03 mycroft Exp $");
__RCSID("$NetBSD: loop-bsd.c,v 1.7 2003/04/20 00:17:22 christos Exp $");
#endif
#include <errno.h>
@ -50,6 +50,7 @@ __RCSID("$NetBSD: loop-bsd.c,v 1.6 2002/09/20 14:16:03 mycroft Exp $");
#include "common.h"
#include "device.h"
#include "mopdef.h"
#include "log.h"
int
mopOpenRC(p, trans)
@ -112,21 +113,15 @@ Loop()
int bufsize;
struct if_info *ii;
if (iflist == 0) {
syslog(LOG_ERR, "no interfaces");
exit(0);
}
if (iflist == 0)
mopLogErrX("no interfaces");
if (iflist->fd != -1) {
if (ioctl(iflist->fd, BIOCGBLEN, (caddr_t) & bufsize) < 0) {
syslog(LOG_ERR, "BIOCGBLEN: %m");
exit(0);
}
if (ioctl(iflist->fd, BIOCGBLEN, (caddr_t) & bufsize) < 0)
mopLogErr("BIOCGBLEN");
}
buf = (u_char *) malloc((unsigned) bufsize);
if (buf == 0) {
syslog(LOG_ERR, "malloc: %m");
exit(0);
}
if (buf == 0)
mopLogErr("malloc");
/*
* Find the highest numbered file descriptor for select().
* Initialize the set of descriptors to listen to.
@ -140,10 +135,8 @@ Loop()
set[m].events = POLLIN;
}
for (;;) {
if (poll(set, n, INFTIM) < 0) {
syslog(LOG_ERR, "poll: %m");
exit(0);
}
if (poll(set, n, INFTIM) < 0)
mopLogErr("poll");
for (ii = iflist, m = 0; ii; ii = ii->next, m++) {
if (!(set[m].revents & POLLIN))
continue;
@ -161,8 +154,7 @@ Loop()
(void) lseek(ii->fd, 0, 0);
goto again;
}
syslog(LOG_ERR, "read: %m");
exit(0);
mopLogErr("read");
}
/* Loop through the packet(s) */
#define bhp ((struct bpf_hdr *)bp)

View File

@ -1,4 +1,4 @@
/* $NetBSD: pf.c,v 1.7 2002/08/22 07:18:42 itojun Exp $ */
/* $NetBSD: pf.c,v 1.8 2003/04/20 00:17:22 christos Exp $ */
/*
* Copyright (c) 1993-95 Mats O Jansson. All rights reserved.
@ -35,7 +35,7 @@
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: pf.c,v 1.7 2002/08/22 07:18:42 itojun Exp $");
__RCSID("$NetBSD: pf.c,v 1.8 2003/04/20 00:17:22 christos Exp $");
#endif
#include "os.h"
@ -45,6 +45,7 @@ __RCSID("$NetBSD: pf.c,v 1.7 2002/08/22 07:18:42 itojun Exp $");
#include "mopdef.h"
#include "pf.h"
#include "log.h"
/*
* Variables
@ -104,35 +105,35 @@ pfInit(interface, mode, protocol, typ)
} while (fd < 0 && errno == EBUSY);
if (fd < 0) {
syslog(LOG_ERR,"pfInit: open %s: %m", device);
mopLogWarn("pfInit: open %s", device);
return(-1);
}
/* Set immediate mode so packets are processed as they arrive. */
immediate = 1;
if (ioctl(fd, BIOCIMMEDIATE, &immediate) < 0) {
syslog(LOG_ERR,"pfInit: BIOCIMMEDIATE: %m");
mopLogWarn("pfInit: BIOCIMMEDIATE");
return(-1);
}
(void) strncpy(ifr.ifr_name, interface, sizeof ifr.ifr_name);
if (ioctl(fd, BIOCSETIF, (caddr_t) & ifr) < 0) {
syslog(LOG_ERR,"pfInit: BIOCSETIF: %m");
mopLogWarn("pfInit: BIOCSETIF");
return(-1);
}
/* Check that the data link layer is an Ethernet; this code won't work
* with anything else. */
if (ioctl(fd, BIOCGDLT, (caddr_t) & dlt) < 0) {
syslog(LOG_ERR,"pfInit: BIOCGDLT: %m");
mopLogWarn("pfInit: BIOCGDLT");
return(-1);
}
if (dlt != DLT_EN10MB) {
syslog(LOG_ERR,"pfInit: %s is not ethernet", device);
mopLogWarnX("pfInit: %s is not ethernet", device);
return(-1);
}
if (promisc) {
/* Set promiscuous mode. */
if (ioctl(fd, BIOCPROMISC, (caddr_t)0) < 0) {
syslog(LOG_ERR,"pfInit: BIOCPROMISC: %m");
mopLogWarn("pfInit: BIOCPROMISC");
return(-1);
}
}
@ -141,7 +142,7 @@ pfInit(interface, mode, protocol, typ)
insns[3].k = protocol;
if (ioctl(fd, BIOCSETF, (caddr_t) & filter) < 0) {
syslog(LOG_ERR,"pfInit: BIOCSETF: %m");
mopLogWarn("pfInit: BIOCSETF");
return(-1);
}
return(fd);
@ -169,11 +170,11 @@ pfAddMulti(s, interface, addr)
*
*/
if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
syslog(LOG_ERR, "pfAddMulti: socket: %m");
mopLogWarn("pfAddMulti: socket");
return(-1);
}
if (ioctl(fd, SIOCADDMULTI, (caddr_t)&ifr) < 0) {
syslog(LOG_ERR, "pfAddMulti: SIOCADDMULTI: %m");
mopLogWarn("pfAddMulti: SIOCADDMULTI");
close(fd);
return(-1);
}
@ -204,11 +205,11 @@ pfDelMulti(s, interface, addr)
*
*/
if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
syslog(LOG_ERR, "pfDelMulti: socket: %m");
mopLogWarn("pfDelMulti: socket");
return(-1);
}
if (ioctl(fd, SIOCDELMULTI, (caddr_t)&ifr) < 0) {
syslog(LOG_ERR, "pfAddMulti: SIOCDELMULTI: %m");
mopLogWarn("pfAddMulti: SIOCDELMULTI");
close(fd);
return(-1);
}