changed syslog -> notice/error/fatal etc.
*/
#ifndef lint
-static char rcsid[] = "$Id: sys-NeXT.c,v 1.12 1999/03/12 06:07:20 paulus Exp $";
+static char rcsid[] = "$Id: sys-NeXT.c,v 1.13 1999/03/16 02:57:05 paulus Exp $";
#endif
#include <stdio.h>
-#include <syslog.h>
#include <termios.h>
#include <utmp.h>
#include <unistd.h>
static int loop_master;
static char loop_name[20];
+static fd_set in_fds; /* set of fds that wait_input waits for */
+static int max_in_fd; /* highest fd set in in_fds */
+
extern int errno;
static int restore_term; /* 1 => we've munged the terminal */
setlogmask(LOG_UPTO(LOG_INFO));
/* Get an internet socket for doing socket ioctl's on. */
- if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
- syslog(LOG_ERR, "Couldn't create IP socket: %m");
- die(1);
- }
+ if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
+ fatal("Couldn't create IP socket: %m");
if((pppdev = open("/dev/ppp0", O_RDWR, O_NONBLOCK)) == NULL)
- {
- syslog(LOG_ERR, "Couldn't open /dev/ppp0: %m");
- die(1);
- }
+ fatal("Couldn't open /dev/ppp0: %m");
+ FD_ZERO(&in_fds);
+ max_in_fd = 0;
}
/*
note_debug_level()
{
if (debug) {
- syslog(LOG_INFO, "Debug turned ON, Level %d", debug);
+ info("Debug turned ON, Level %d", debug);
setlogmask(LOG_UPTO(LOG_DEBUG));
} else {
setlogmask(LOG_UPTO(LOG_WARNING));
int pppdisc = PPPDISC;
int x;
- if (ioctl(fd, TIOCGETD, &initdisc) < 0) {
- syslog(LOG_ERR, "ioctl(TIOCGETD): %m");
- die(1);
- }
- if (ioctl(fd, TIOCSETD, &pppdisc) < 0) {
- syslog(LOG_ERR, "ioctl(establish TIOCSETD): %m");
- die(1);
- }
+ if (ioctl(fd, TIOCGETD, &initdisc) < 0)
+ fatal("ioctl(TIOCGETD): %m");
+ if (ioctl(fd, TIOCSETD, &pppdisc) < 0)
+ fatal("ioctl(establish TIOCSETD): %m");
/*
* Find out which interface we were given.
*/
- if (ioctl(fd, PPPIOCGUNIT, &ifunit) < 0) {
- syslog(LOG_ERR, "ioctl(PPPIOCGUNIT): %m");
- die(1);
- }
+ if (ioctl(fd, PPPIOCGUNIT, &ifunit) < 0)
+ fatal("ioctl(PPPIOCGUNIT): %m");
/*
* Enable debug in the driver if requested.
*/
if (kdebugflag) {
if (ioctl(fd, PPPIOCGFLAGS, (caddr_t) &x) < 0) {
- syslog(LOG_WARNING, "ioctl(PPPIOCGFLAGS): %m");
+ warn("ioctl(PPPIOCGFLAGS): %m");
} else {
x |= (kdebugflag & 0xFF) * SC_DEBUG;
if (ioctl(fd, PPPIOCSFLAGS, (caddr_t) &x) < 0)
- syslog(LOG_WARNING, "ioctl(PPPIOCSFLAGS): %m");
+ warn("ioctl(PPPIOCSFLAGS): %m");
}
}
*/
if ((initfdflags = fcntl(fd, F_GETFL)) == -1
|| fcntl(fd, F_SETFL, initfdflags | O_NONBLOCK) == -1) {
- syslog(LOG_WARNING, "Couldn't set device to non-blocking mode: %m");
+ warn("Couldn't set device to non-blocking mode: %m");
}
}
{
/* Reset non-blocking mode on fd. */
if (initfdflags != -1 && fcntl(fd, F_SETFL, initfdflags) < 0)
- syslog(LOG_WARNING, "Couldn't restore device fd flags: %m");
+ warn("Couldn't restore device fd flags: %m");
initfdflags = -1;
/* Restore old line discipline. */
if (initdisc >= 0 && ioctl(fd, TIOCSETD, &initdisc) < 0)
- syslog(LOG_ERR, "ioctl(TIOCSETD): %m");
+ error("ioctl(TIOCSETD): %m");
initdisc = -1;
}
break;
}
if (s != NULL) {
- syslog(LOG_WARNING, "Serial link is not 8-bit clean:");
- syslog(LOG_WARNING, "All received characters had %s", s);
+ warn("Serial link is not 8-bit clean:");
+ warn("All received characters had %s", s);
}
}
}
for (speedp = speeds; speedp->speed_int; speedp++)
if (bps == speedp->speed_int)
return speedp->speed_val;
- syslog(LOG_WARNING, "speed %d not supported", bps);
+ warn("speed %d not supported", bps);
return 0;
}
int speed, x, modembits;
struct termios tios;
- if (tcgetattr(fd, &tios) < 0) {
- syslog(LOG_ERR, "tcgetattr: %m");
- die(1);
- }
+ if (tcgetattr(fd, &tios) < 0)
+ fatal("tcgetattr: %m");
if (!restore_term)
inittermios = tios;
* We can't proceed if the serial port speed is B0,
* since that implies that the serial port is disabled.
*/
- if (speed == B0) {
- syslog(LOG_ERR, "Baud rate for %s is 0; need explicit baud rate",
- devnam);
- die(1);
- }
+ if (speed == B0)
+ fatal("Baud rate for %s is 0; need explicit baud rate",
+ devnam);
}
if (modem) {
modembits = TIOCM_RTS | TIOCM_CTS;
if (ioctl(fd, (crtscts ? TIOCMBIS : TIOCMBIC), &modembits) < 0)
- syslog(LOG_ERR, "ioctl: TIOCMBIS/BIC: %m");
+ error("ioctl: TIOCMBIS/BIC: %m");
}
- if (tcsetattr(fd, TCSAFLUSH, &tios) < 0) {
- syslog(LOG_ERR, "tcsetattr: %m");
- die(1);
- }
+ if (tcsetattr(fd, TCSAFLUSH, &tios) < 0)
+ fatal("tcsetattr: %m");
baud_rate = inspeed = baud_rate_of(speed);
restore_term = 1;
if (restore_term) {
if (tcsetattr(fd, TCSAFLUSH, &inittermios) < 0)
if (errno != ENXIO)
- syslog(LOG_WARNING, "tcsetattr: %m");
+ warn("tcsetattr: %m");
restore_term = 0;
}
}
int len;
{
if (debug)
- log_packet(p, len, "sent ", LOG_DEBUG);
+ dbglog("sent %P", p, len);
if (write(ttyfd, p, len) < 0) {
if (errno == EWOULDBLOCK || errno == ENOBUFS
|| errno == ENXIO || errno == EIO) {
- syslog(LOG_WARNING, "write: warning: %m");
+ warn("write: warning: %m");
} else {
- syslog(LOG_ERR, "write: %m");
- die(1);
+ fatal("write: %m");
}
}
}
/*
- * wait_input - wait until there is data available on ttyfd,
+ * wait_input - wait until there is data available,
* for the length of time specified by *timo (indefinite
* if timo is NULL).
*/
fd_set ready;
int n;
- FD_ZERO(&ready);
- FD_SET(ttyfd, &ready);
- n = select(ttyfd+1, &ready, NULL, &ready, timo);
- if (n < 0 && errno != EINTR) {
- syslog(LOG_ERR, "select: %m");
- die(1);
- }
+ ready = in_fds;
+ n = select(max_in_fd + 1, &ready, NULL, &ready, timo);
+ if (n < 0 && errno != EINTR)
+ fatal("select: %m");
+}
+
+
+/*
+ * add_fd - add an fd to the set that wait_input waits for.
+ */
+void add_fd(int fd)
+{
+ FD_SET(fd, &in_fds);
+ if (fd > max_in_fd)
+ max_in_fd = fd;
}
+/*
+ * remove_fd - remove an fd from the set that wait_input waits for.
+ */
+void remove_fd(int fd)
+{
+ FD_CLR(fd, &in_fds);
+}
/*
* read_packet - get a PPP packet from the serial device.
if ((len = read(ttyfd, buf, PPP_MTU + PPP_HDRLEN)) < 0) {
if (errno == EWOULDBLOCK || errno == EINTR) {
- MAINDEBUG((LOG_DEBUG, "read: %m"));
+ SYSDEBUG(("read: %m"));
return -1;
}
- syslog(LOG_ERR, "read: %m");
- die(1);
+ fatal("read: %m");
}
return len;
}
strlcpy(ifr.ifr_name, sizeof (ifr.ifr_name), ifname);
ifr.ifr_mtu = mtu;
- if (ioctl(sockfd, SIOCSIFMTU, (caddr_t) &ifr) < 0) {
- syslog(LOG_ERR, "ioctl(SIOCSIFMTU): %m");
- quit();
- }
+ if (ioctl(sockfd, SIOCSIFMTU, (caddr_t) &ifr) < 0)
+ fatal("ioctl(SIOCSIFMTU): %m");
- if (ioctl(ttyfd, PPPIOCSASYNCMAP, (caddr_t) &asyncmap) < 0) {
- syslog(LOG_ERR, "ioctl(PPPIOCSASYNCMAP): %m");
- quit();
- }
+ if (ioctl(ttyfd, PPPIOCSASYNCMAP, (caddr_t) &asyncmap) < 0)
+ fatal("ioctl(PPPIOCSASYNCMAP): %m");
+
+ if (ioctl(ttyfd, PPPIOCGFLAGS, (caddr_t) &x) < 0)
+ fatal("ioctl(PPPIOCGFLAGS): %m");
- if (ioctl(ttyfd, PPPIOCGFLAGS, (caddr_t) &x) < 0) {
- syslog(LOG_ERR, "ioctl(PPPIOCGFLAGS): %m");
- quit();
- }
x = pcomp? x | SC_COMP_PROT: x &~ SC_COMP_PROT;
x = accomp? x | SC_COMP_AC: x &~ SC_COMP_AC;
- if (ioctl(ttyfd, PPPIOCSFLAGS, (caddr_t) &x) < 0) {
- syslog(LOG_ERR, "ioctl(PPPIOCSFLAGS): %m");
- quit();
- }
+ if (ioctl(ttyfd, PPPIOCSFLAGS, (caddr_t) &x) < 0)
+ fatal("ioctl(PPPIOCSFLAGS): %m");
}
ext_accm accm;
{
if (ioctl(ttyfd, PPPIOCSXASYNCMAP, accm) < 0 && errno != ENOTTY)
- syslog(LOG_WARNING, "ioctl(PPPIOCSXASYNCMAP): %m");
+ warn("ioctl(PPPIOCSXASYNCMAP): %m");
}
{
int x;
- if (ioctl(ttyfd, PPPIOCSMRU, (caddr_t) &mru) < 0) {
- syslog(LOG_ERR, "ioctl(PPPIOCSMRU): %m");
- quit();
- }
- if (ioctl(ttyfd, PPPIOCSRASYNCMAP, (caddr_t) &asyncmap) < 0) {
- syslog(LOG_ERR, "ioctl(PPPIOCSRASYNCMAP): %m");
- quit();
- }
- if (ioctl(ttyfd, PPPIOCGFLAGS, (caddr_t) &x) < 0) {
- syslog(LOG_ERR, "ioctl(PPPIOCGFLAGS): %m");
- quit();
- }
+ if (ioctl(ttyfd, PPPIOCSMRU, (caddr_t) &mru) < 0)
+ fatal("ioctl(PPPIOCSMRU): %m");
+ if (ioctl(ttyfd, PPPIOCSRASYNCMAP, (caddr_t) &asyncmap) < 0)
+ fatal("ioctl(PPPIOCSRASYNCMAP): %m");
+ if (ioctl(ttyfd, PPPIOCGFLAGS, (caddr_t) &x) < 0)
+ fatal("ioctl(PPPIOCGFLAGS): %m");
x = !accomp? x | SC_REJ_COMP_AC: x &~ SC_REJ_COMP_AC;
- if (ioctl(ttyfd, PPPIOCSFLAGS, (caddr_t) &x) < 0) {
- syslog(LOG_ERR, "ioctl(PPPIOCSFLAGS): %m");
- quit();
- }
+ if (ioctl(ttyfd, PPPIOCSFLAGS, (caddr_t) &x) < 0)
+ fatal("ioctl(PPPIOCSFLAGS): %m");
}
/*
int x;
if (ioctl(ttyfd, PPPIOCGFLAGS, (caddr_t) &x) < 0) {
- syslog(LOG_ERR, "ioctl(PPPIOCGFLAGS): %m");
+ error("ioctl(PPPIOCGFLAGS): %m");
return;
}
x = isopen? x | SC_CCP_OPEN: x &~ SC_CCP_OPEN;
x = isup? x | SC_CCP_UP: x &~ SC_CCP_UP;
if (ioctl(ttyfd, PPPIOCSFLAGS, (caddr_t) &x) < 0)
- syslog(LOG_ERR, "ioctl(PPPIOCSFLAGS): %m");
+ error("ioctl(PPPIOCSFLAGS): %m");
}
/*
int x;
if (ioctl(ttyfd, PPPIOCGFLAGS, (caddr_t) &x) < 0) {
- syslog(LOG_ERR, "ioctl(PPPIOCGFLAGS): %m");
+ error("ioctl(PPPIOCGFLAGS): %m");
return 0;
}
return x & SC_DC_FERROR;
u_int x;
if (ioctl(ttyfd, PPPIOCGFLAGS, (caddr_t) &x) < 0) {
- syslog(LOG_ERR, "ioctl(PPIOCGFLAGS): %m");
+ error("ioctl(PPIOCGFLAGS): %m");
return 0;
}
x = vjcomp ? x | SC_COMP_TCP: x &~ SC_COMP_TCP;
x = cidcomp? x & ~SC_NO_TCP_CCID: x | SC_NO_TCP_CCID;
if (ioctl(ttyfd, PPPIOCSFLAGS, (caddr_t) &x) < 0) {
- syslog(LOG_ERR, "ioctl(PPPIOCSFLAGS): %m");
+ error("ioctl(PPPIOCSFLAGS): %m");
return 0;
}
if (ioctl(ttyfd, PPPIOCSMAXCID, (caddr_t) &maxcid) < 0) {
- syslog(LOG_ERR, "ioctl(PPPIOCSFLAGS): %m");
+ error("ioctl(PPPIOCSFLAGS): %m");
return 0;
}
return 1;
strlcpy(ifr.ifr_name, sizeof (ifr.ifr_name), ifname);
if (ioctl(sockfd, SIOCGIFFLAGS, (caddr_t) &ifr) < 0) {
- syslog(LOG_ERR, "ioctl (SIOCGIFFLAGS): %m");
+ error("ioctl (SIOCGIFFLAGS): %m");
return 0;
}
ifr.ifr_flags |= IFF_UP;
if (ioctl(sockfd, SIOCSIFFLAGS, (caddr_t) &ifr) < 0) {
- syslog(LOG_ERR, "ioctl(SIOCSIFFLAGS): %m");
+ error("ioctl(SIOCSIFFLAGS): %m");
return 0;
}
if_is_up = 1;
npi.mode = NPMODE_PASS;
if (ioctl(ttyfd, PPPIOCSNPMODE, &npi) < 0) {
if (errno != ENOTTY) {
- syslog(LOG_ERR, "ioctl(PPPIOCSNPMODE): %m");
+ error("ioctl(PPPIOCSNPMODE): %m");
return 0;
}
/* for backwards compatibility */
if (ioctl(ttyfd, PPPIOCGFLAGS, (caddr_t) &x) < 0) {
- syslog(LOG_ERR, "ioctl (PPPIOCGFLAGS): %m");
+ error("ioctl (PPPIOCGFLAGS): %m");
return 0;
}
x |= SC_ENABLE_IP;
if (ioctl(ttyfd, PPPIOCSFLAGS, (caddr_t) &x) < 0) {
- syslog(LOG_ERR, "ioctl(PPPIOCSFLAGS): %m");
+ error("ioctl(PPPIOCSFLAGS): %m");
return 0;
}
}
strlcpy(ifr.ifr_name, sizeof (ifr.ifr_name), ifname);
if (ioctl(sockfd, SIOCGIFFLAGS, (caddr_t) &ifr) < 0) {
- syslog(LOG_ERR, "ioctl (SIOCGIFFLAGS): %m");
+ error("ioctl (SIOCGIFFLAGS): %m");
rv = 0;
} else {
ifr.ifr_flags &= ~IFF_UP;
if (ioctl(sockfd, SIOCSIFFLAGS, (caddr_t) &ifr) < 0) {
- syslog(LOG_ERR, "ioctl(SIOCSIFFLAGS): %m");
+ error("ioctl(SIOCSIFFLAGS): %m");
rv = 0;
} else
if_is_up = 0;
SET_SA_FAMILY(ifr.ifr_addr, AF_INET);
((struct sockaddr_in *) &ifr.ifr_addr)->sin_addr.s_addr = o;
if (ioctl(sockfd, SIOCSIFADDR, (caddr_t) &ifr) < 0) {
- syslog(LOG_ERR, "ioctl(SIOCAIFADDR): %m");
+ error("ioctl(SIOCAIFADDR): %m");
ret = 0;
}
((struct sockaddr_in *) &ifr.ifr_dstaddr)->sin_addr.s_addr = h;
if (ioctl(sockfd, SIOCSIFDSTADDR, (caddr_t) &ifr) < 0) {
- syslog(LOG_ERR, "ioctl(SIOCSIFDSTADDR): %m");
+ error("ioctl(SIOCSIFDSTADDR): %m");
ret = 0;
}
if (m != 0) {
((struct sockaddr_in *) &ifr.ifr_addr)->sin_addr.s_addr = m;
- syslog(LOG_INFO, "Setting interface mask to %s\n", ip_ntoa(m));
+ info("Setting interface mask to %s\n", ip_ntoa(m));
if (ioctl(sockfd, SIOCSIFNETMASK, (caddr_t) &ifr) < 0) {
- syslog(LOG_ERR, "ioctl(SIOCSIFNETMASK): %m");
+ error("ioctl(SIOCSIFNETMASK): %m");
ret = 0;
}
}
((struct sockaddr_in *) &rt.rt_gateway)->sin_addr.s_addr = o;
rt.rt_flags = RTF_HOST;
if (ioctl(sockfd, SIOCDELRT, (caddr_t) &rt) < 0) {
- syslog(LOG_ERR, "ioctl(SIOCDELRT): %m");
+ error("ioctl(SIOCDELRT): %m");
return 0;
}
return 1;
((struct sockaddr_in *) &rt.rt_gateway)->sin_addr.s_addr = g;
rt.rt_flags = RTF_GATEWAY;
if (ioctl(sockfd, (cmd == 's') ? SIOCADDRT : SIOCDELRT, &rt) < 0) {
- syslog(LOG_ERR, "%cifdefaultroute: ioctl(%s): %m", cmd,
+ error("%cifdefaultroute: ioctl(%s): %m", cmd,
(cmd == 's') ? "SIOCADDRT" : "SIOCDELRT");
return 0;
}
* as our local address.
*/
if (!get_ether_addr(hisaddr, &arpreq.arp_ha)) {
- syslog(LOG_ERR, "Cannot determine ethernet address for proxy ARP");
+ error("Cannot determine ethernet address for proxy ARP");
return 0;
}
((struct sockaddr_in *) &arpreq.arp_pa)->sin_addr.s_addr = hisaddr;
arpreq.arp_flags = ATF_PERM | ATF_PUBL;
if (ioctl(sockfd, SIOCSARP, (caddr_t)&arpreq) < 0) {
- syslog(LOG_ERR, "ioctl(SIOCSARP): %m");
+ error("ioctl(SIOCSARP): %m");
return 0;
}
SET_SA_FAMILY(arpreq.arp_pa, AF_INET);
((struct sockaddr_in *) &arpreq.arp_pa)->sin_addr.s_addr = hisaddr;
if (ioctl(sockfd, SIOCDARP, (caddr_t)&arpreq) < 0) {
- syslog(LOG_WARNING, "ioctl(SIOCDARP): %m");
+ warn("ioctl(SIOCDARP): %m");
return 0;
}
proxy_arp_addr = 0;
ifc.ifc_len = sizeof(ifs);
ifc.ifc_req = ifs;
if (ioctl(sockfd, SIOCGIFCONF, &ifc) < 0) {
- syslog(LOG_ERR, "ioctl(SIOCGIFCONF): %m");
+ error("ioctl(SIOCGIFCONF): %m");
return 0;
}
if (ifr >= ifend)
return 0;
- syslog(LOG_INFO, "found interface %s for proxy arp", ifr->ifr_name);
+ info("found interface %s for proxy arp", ifr->ifr_name);
/*
* Get the hostname and look for an entry using the ethers database.
return 0;
if (ether_by_host(hostent->h_name, &dla)) {
- syslog(LOG_INFO, "Add entry for %s in /etc/ethers", hostent->h_name);
+ info("Add entry for %s in /etc/ethers", hostent->h_name);
return 0; /* it's not there */
}
hwaddr->sa_family = AF_UNSPEC;
ifc.ifc_len = sizeof(ifs);
ifc.ifc_req = ifs;
if (ioctl(sockfd, SIOCGIFCONF, &ifc) < 0) {
- syslog(LOG_WARNING, "ioctl(SIOCGIFCONF): %m");
+ warn("ioctl(SIOCGIFCONF): %m");
return mask;
}
ifend = (struct ifreq *) (ifc.ifc_buf + ifc.ifc_len);
/* Read the lock file to find out who has the device locked */
n = read(fd, &pid, sizeof(pid));
if (n <= 0) {
- syslog(LOG_ERR, "Can't read pid from lock file %s", lock_file);
+ error("Can't read pid from lock file %s", lock_file);
close(fd);
} else {
if (kill(pid, 0) == -1 && errno == ESRCH) {
/* pid no longer exists - remove the lock file */
if (unlink(lock_file) == 0) {
close(fd);
- syslog(LOG_NOTICE, "Removed stale lock on %s (pid %d)",
+ notice("Removed stale lock on %s (pid %d)",
dev, pid);
continue;
} else
- syslog(LOG_WARNING, "Couldn't remove stale lock on %s",
- dev);
+ warn("Couldn't remove stale lock on %s", dev);
} else
- syslog(LOG_NOTICE, "Device %s is locked by pid %d",
+ notice("Device %s is locked by pid %d",
dev, pid);
}
close(fd);
} else
- syslog(LOG_ERR, "Can't create lock file %s: %m", lock_file);
+ error("Can't create lock file %s: %m", lock_file);
free(lock_file);
lock_file = NULL;
return -1;
code = cmd;
if (let == 't' && (75 <= code && code <= 90))
- syslog(LOG_INFO, "ioctl(%d, 0x%x ('%c', %d, %d), 0x%x)\n", fd, cmd,
+ info("ioctl(%d, 0x%x ('%c', %d, %d), 0x%x)\n", fd, cmd,
let, code, size, c);
#endif
#ifdef DEBUGIOCTL
serrno = errno;
if (ret == -1)
- syslog(LOG_INFO, "ioctl('%c', %d, %d) errno = %d (%m)\n",
+ info("ioctl('%c', %d, %d) errno = %d (%m)\n",
let, code, size, errno);
if (let == 't' && (75 <= code && code <= 90) && (cmd & IOC_OUT)) {
int i, len = ((cmd >> 16) & IOCPARM_MASK);
for (i = 0; i < len / 4; ++i)
- syslog(LOG_INFO, "word[%d] @ 0x%06x = 0x%x\n",
+ info("word[%d] @ 0x%06x = 0x%x\n",
i, &((int *) c)[i],((int *)c)[i]);
}
errno = serrno;
if (!in)
{
in = 1;
- syslog(LOG_WARNING, "PPPD: Inside modified HP and SPARC sigaction\n");
+ warn("PPPD: Inside modified HP and SPARC sigaction\n");
}
return sigvec(sig, &sv, NULL);
rv = 1;
}
- if (n == 0) {
- syslog(LOG_ERR, "eof on loopback");
- die(1);
- } else if (errno != EWOULDBLOCK){
- syslog(LOG_ERR, "read from loopback: %m");
- die(1);
- }
+ if (n == 0)
+ fatal("eof on loopback");
+ if (errno != EWOULDBLOCK)
+ fatal("read from loopback: %m");
return rv;
#endif
npi.protocol = proto;
npi.mode = mode;
if (ioctl(ttyfd, PPPIOCSNPMODE, &npi) < 0) {
- syslog(LOG_ERR, "ioctl(set NP %d mode to %d): %m", proto, mode);
+ error("ioctl(set NP %d mode to %d): %m", proto, mode);
return 0;
}
return 1;
struct termios tios;
int pppdisc = PPPDISC;
- syslog(LOG_ERR, "open_ppp_loopback called!");
- die(1);
+ fatal("open_ppp_loopback called!");
- if (openpty(&loop_master, &loop_slave, loop_name, NULL, NULL) < 0) {
- syslog(LOG_ERR, "No free pty for loopback");
- die(1);
- }
- SYSDEBUG((LOG_DEBUG, "using %s for loopback", loop_name));
+ if (openpty(&loop_master, &loop_slave, loop_name, NULL, NULL) < 0)
+ fatal("No free pty for loopback");
+ SYSDEBUG(("using %s for loopback", loop_name));
if (tcgetattr(loop_slave, &tios) == 0) {
tios.c_cflag &= ~(CSIZE | CSTOPB | PARENB);
tios.c_oflag = 0;
tios.c_lflag = 0;
if (tcsetattr(loop_slave, TCSAFLUSH, &tios) < 0)
- syslog(LOG_WARNING, "couldn't set attributes on loopback: %m");
+ warn("couldn't set attributes on loopback: %m");
}
if ((flags = fcntl(loop_master, F_GETFL)) != -1)
if (fcntl(loop_master, F_SETFL, flags | O_NONBLOCK) == -1)
- syslog(LOG_WARNING, "couldn't set loopback to nonblock: %m");
+ warn("couldn't set loopback to nonblock: %m");
ttyfd = loop_slave;
- if (ioctl(ttyfd, TIOCSETD, &pppdisc) < 0) {
- syslog(LOG_ERR, "ioctl(TIOCSETD): %m");
- die(1);
- }
+ if (ioctl(ttyfd, TIOCSETD, &pppdisc) < 0)
+ fatal("ioctl(TIOCSETD): %m");
/*
* Find out which interface we were given.
*/
- if (ioctl(ttyfd, PPPIOCGUNIT, &ifunit) < 0) {
- syslog(LOG_ERR, "ioctl(PPPIOCGUNIT): %m");
- die(1);
- }
+ if (ioctl(ttyfd, PPPIOCGUNIT, &ifunit) < 0)
+ fatal("ioctl(PPPIOCGUNIT): %m");
/*
* Enable debug in the driver if requested.
*/
if (kdebugflag) {
if (ioctl(ttyfd, PPPIOCGFLAGS, (caddr_t) &flags) < 0) {
- syslog(LOG_WARNING, "ioctl (PPPIOCGFLAGS): %m");
+ warn("ioctl (PPPIOCGFLAGS): %m");
} else {
flags |= (kdebugflag & 0xFF) * SC_DEBUG;
if (ioctl(ttyfd, PPPIOCSFLAGS, (caddr_t) &flags) < 0)
- syslog(LOG_WARNING, "ioctl(PPPIOCSFLAGS): %m");
+ warn("ioctl(PPPIOCSFLAGS): %m");
}
}
/*
* Transfer the ppp interface back to the loopback.
*/
- if (ioctl(ttyfd, PPPIOCXFERUNIT, 0) < 0) {
- syslog(LOG_ERR, "ioctl(transfer ppp unit): %m");
- die(1);
- }
+ if (ioctl(ttyfd, PPPIOCXFERUNIT, 0) < 0)
+ fatal("ioctl(transfer ppp unit): %m");
x = PPPDISC;
- if (ioctl(loop_slave, TIOCSETD, &x) < 0) {
- syslog(LOG_ERR, "ioctl(TIOCSETD): %m");
- die(1);
- }
+ if (ioctl(loop_slave, TIOCSETD, &x) < 0)
+ fatal("ioctl(TIOCSETD): %m");
/*
* Check that we got the same unit again.
*/
- if (ioctl(loop_slave, PPPIOCGUNIT, &x) < 0) {
- syslog(LOG_ERR, "ioctl(PPPIOCGUNIT): %m");
- die(1);
- }
- if (x != ifunit) {
- syslog(LOG_ERR, "transfer_ppp failed: wanted unit %d, got %d",
- ifunit, x);
- die(1);
- }
+ if (ioctl(loop_slave, PPPIOCGUNIT, &x) < 0)
+ fatal("ioctl(PPPIOCGUNIT): %m");
+ if (x != ifunit)
+ fatal("transfer_ppp failed: wanted unit %d, got %d",
+ ifunit, x);
ttyfd = loop_slave;
}
*/
if (demand)
{
- syslog(LOG_WARNING, "PPP-2.3 for NeXTSTEP does not yet support demand dialing\n");
+ option_error("PPP-2.3 for NeXTSTEP does not yet support demand dialing");
return 0;
}
return 1;
closelog();
}
-
+#if 0
/*
* wait_loop_output - wait until there is data available on the
* loopback, for the length of time specified by *timo (indefinite
FD_ZERO(&ready);
FD_SET(loop_master, &ready);
n = select(loop_master + 1, &ready, NULL, &ready, timo);
- if (n < 0 && errno != EINTR) {
- syslog(LOG_ERR, "select: %m");
- die(1);
- }
+ if (n < 0 && errno != EINTR)
+ fatal("select: %m");
}
-
/*
* wait_time - wait for a given length of time or until a
* signal is received.
int n;
n = select(0, NULL, NULL, NULL, timo);
- if (n < 0 && errno != EINTR) {
- syslog(LOG_ERR, "select: %m");
- die(1);
- }
+ if (n < 0 && errno != EINTR)
+ fatal("select: %m");
}
+#endif
*/
#ifndef lint
-static char rcsid[] = "$Id: sys-aix4.c,v 1.15 1999/03/12 06:07:21 paulus Exp $";
+static char rcsid[] = "$Id: sys-aix4.c,v 1.16 1999/03/16 02:57:05 paulus Exp $";
#endif
/*
#include <stdlib.h>
*/
#include <errno.h>
-#include <syslog.h>
#include <termios.h>
#include <sys/termiox.h>
#include <fcntl.h>
static u_int32_t default_route_gateway; /* Gateway for default route added */
static u_int32_t proxy_arp_addr; /* Addr for proxy arp entry added */
+#define MAX_POLLFDS 32
+static struct pollfd pollfds[MAX_POLLFDS];
+static int n_pollfds;
+
/* Prototypes for procedures local to this file. */
static int translate_speed __P((int));
static int baud_rate_of __P((int));
sys_init()
{
/* Get an internet socket for doing socket ioctl's on. */
- if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
- syslog(LOG_ERR, "Couldn't create IP socket: %m");
- die(1);
- }
+ if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
+ fatal("Couldn't create IP socket: %m");
+
+ n_pollfds = 0;
}
/*
if (ioctl(fd, I_LOOK, str_modules[str_module_count].modname) < 0 ||
ioctl(fd, I_POP, 0) < 0)
break;
- MAINDEBUG((LOG_DEBUG, "popped stream module : %s",
+ SYSDEBUG(("popped stream module : %s",
str_modules[str_module_count].modname));
str_module_count++;
}
/* now push the async/fcs module */
- if (ioctl(fd, I_PUSH, "pppasync") < 0) {
- syslog(LOG_ERR, "ioctl(I_PUSH, ppp_async): %m");
- die(1);
- }
+ if (ioctl(fd, I_PUSH, "pppasync") < 0)
+ fatal("ioctl(I_PUSH, ppp_async): %m");
/* push the compress module */
if (ioctl(fd, I_PUSH, "pppcomp") < 0) {
- syslog(LOG_WARNING, "ioctl(I_PUSH, ppp_comp): %m");
+ warn("ioctl(I_PUSH, ppp_comp): %m");
}
/* finally, push the ppp_if module that actually handles the */
/* network interface */
- if (ioctl(fd, I_PUSH, "pppif") < 0) {
- syslog(LOG_ERR, "ioctl(I_PUSH, ppp_if): %m");
- die(1);
- }
+ if (ioctl(fd, I_PUSH, "pppif") < 0)
+ fatal("ioctl(I_PUSH, ppp_if): %m");
pushed_ppp = 1;
/* read mode, message non-discard mode
- if (ioctl(fd, I_SRDOPT, RMSGN) < 0) {
- syslog(LOG_ERR, "ioctl(I_SRDOPT, RMSGN): %m");
- die(1);
- }
+ if (ioctl(fd, I_SRDOPT, RMSGN) < 0)
+ fatal("ioctl(I_SRDOPT, RMSGN): %m");
*/
/*
* Find out which interface we were given.
* (ppp_if handles this ioctl)
*/
- if (ioctl(fd, SIOCGETU, &ifunit) < 0) {
- syslog(LOG_ERR, "ioctl(SIOCGETU): %m");
- die(1);
- }
+ if (ioctl(fd, SIOCGETU, &ifunit) < 0)
+ fatal("ioctl(SIOCGETU): %m");
/* Set debug flags in driver */
if (ioctl(fd, SIOCSIFDEBUG, kdebugflag) < 0) {
- syslog(LOG_ERR, "ioctl(SIOCSIFDEBUG): %m");
+ error("ioctl(SIOCSIFDEBUG): %m");
}
/* close stdin, stdout, stderr if they might refer to the device */
*/
if ((initfdflags = fcntl(fd, F_GETFL)) == -1
|| fcntl(fd, F_SETFL, initfdflags | O_NONBLOCK) == -1) {
- syslog(LOG_WARNING, "Couldn't set device to non-blocking mode: %m");
+ warn("Couldn't set device to non-blocking mode: %m");
}
}
/* Reset non-blocking mode on the file descriptor. */
if (initfdflags != -1 && fcntl(fd, F_SETFL, initfdflags) < 0)
- syslog(LOG_WARNING, "Couldn't restore device fd flags: %m");
+ warn("Couldn't restore device fd flags: %m");
initfdflags = -1;
if (hungup) {
break;
}
if (s != NULL) {
- syslog(LOG_WARNING, "Serial link is not 8-bit clean:");
- syslog(LOG_WARNING, "All received characters had %s", s);
+ warn("Serial link is not 8-bit clean:");
+ warn("All received characters had %s", s);
}
}
}
for (; str_module_count > 0; str_module_count--) {
if (ioctl(fd, I_PUSH, str_modules[str_module_count-1].modname)) {
if (errno != ENXIO)
- syslog(LOG_WARNING, "str_restore: couldn't push module %s: %m",
- str_modules[str_module_count-1].modname);
+ warn("str_restore: couldn't push module %s: %m",
+ str_modules[str_module_count-1].modname);
} else {
- MAINDEBUG((LOG_INFO, "str_restore: pushed module %s",
- str_modules[str_module_count-1].modname));
+ SYSDEBUG(("str_restore: pushed module %s",
+ str_modules[str_module_count-1].modname));
}
}
}
for (speedp = speeds; speedp->speed_int; speedp++)
if (bps == speedp->speed_int)
return speedp->speed_val;
- syslog(LOG_WARNING, "speed %d not supported", bps);
+ warn("speed %d not supported", bps);
return 0;
}
struct termios tios;
struct termiox tiox;
- if (tcgetattr(fd, &tios) < 0) {
- syslog(LOG_ERR, "tcgetattr: %m");
- die(1);
- }
+ if (tcgetattr(fd, &tios) < 0)
+ fatal("tcgetattr: %m");
+
if (!restore_term)
inittermios = tios;
* We can't proceed if the serial port speed is B0,
* since that implies that the serial port is disabled.
*/
- if (speed == B0) {
- syslog(LOG_ERR, "Baud rate for %s is 0; need explicit baud rate",
- devnam);
- die(1);
- }
+ if (speed == B0)
+ fatal("Baud rate for %s is 0; need explicit baud rate", devnam);
}
- if (tcsetattr(fd, TCSAFLUSH, &tios) < 0) {
- syslog(LOG_ERR, "tcsetattr: %m");
- die(1);
- }
+ if (tcsetattr(fd, TCSAFLUSH, &tios) < 0)
+ fatal("tcsetattr: %m");
baud_rate = inspeed = baud_rate_of(speed);
restore_term = 1;
}
if (tcsetattr(fd, TCSAFLUSH, &inittermios) < 0)
if (errno != ENXIO)
- syslog(LOG_WARNING, "tcsetattr: %m");
+ warn("tcsetattr: %m");
restore_term = 0;
}
}
struct pollfd pfd;
if (debug)
- log_packet(p, len, "sent ", LOG_DEBUG);
+ dbglog("sent %P", p, len);
str.len = len;
str.buf = (caddr_t) p;
while (putmsg(ttyfd, NULL, &str, 0) < 0) {
if (--retries < 0 || (errno != EWOULDBLOCK && errno != EAGAIN)) {
if (errno != ENXIO)
- syslog(LOG_ERR, "Couldn't send packet: %m");
+ error("Couldn't send packet: %m");
break;
}
pfd.fd = ttyfd;
struct timeval *timo;
{
int t;
- struct pollfd pfd;
t = timo == NULL? -1: timo->tv_sec * 1000 + timo->tv_usec / 1000;
- pfd.fd = ttyfd;
- pfd.events = POLLIN | POLLPRI | POLLHUP;
- if (poll(&pfd, 1, t) < 0 && errno != EINTR) {
- syslog(LOG_ERR, "poll: %m");
- die(1);
+ if (poll(pollfds, n_pollfds, t) < 0 && errno != EINTR)
+ fatal("poll: %m");
+}
+
+/*
+ * add_fd - add an fd to the set that wait_input waits for.
+ */
+void add_fd(int fd)
+{
+ int n;
+
+ for (n = 0; n < n_pollfds; ++n)
+ if (pollfds[n].fd == fd)
+ return;
+ if (n_pollfds < MAX_POLLFDS) {
+ pollfds[n_pollfds].fd = fd;
+ pollfds[n_pollfds].events = POLLIN | POLLPRI | POLLHUP;
+ ++n_pollfds;
+ } else
+ error("Too many inputs!");
+}
+
+/*
+ * remove_fd - remove an fd from the set that wait_input waits for.
+ */
+void remove_fd(int fd)
+{
+ int n;
+
+ for (n = 0; n < n_pollfds; ++n) {
+ if (pollfds[n].fd == fd) {
+ while (++n < n_pollfds)
+ pollfds[n-1] = pollfds[n];
+ --n_pollfds;
+ break;
+ }
}
}
+
/*
* read_packet - get a PPP packet from the serial device.
*/
if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR) {
return -1;
}
- syslog(LOG_ERR, "getmsg %m");
- die(1);
+ fatal("getmsg %m");
}
if (len)
- MAINDEBUG((LOG_DEBUG, "getmsg returned 0x%x",len));
+ SYSDEBUG(("getmsg returned 0x%x", len));
if (ctl.len > 0)
- syslog(LOG_NOTICE, "got ctrl msg len %d %x %x\n", ctl.len,
- ctlbuf[0], ctlbuf[1]);
+ notice("got ctrl msg len %d %x %x\n", ctl.len, ctlbuf[0], ctlbuf[1]);
if (str.len < 0) {
- MAINDEBUG((LOG_DEBUG, "getmsg short return length %d", str.len));
+ SYSDEBUG(("getmsg short return length %d", str.len));
return -1;
}
strlcpy(ifr.ifr_name, sizeof (ifr.ifr_name), ifname);
ifr.ifr_mtu = mtu;
- if (ioctl(sockfd, SIOCSIFMTU, (caddr_t) &ifr) < 0) {
- syslog(LOG_ERR, "ioctl(SIOCSIFMTU): %m");
- quit();
- }
+ if (ioctl(sockfd, SIOCSIFMTU, (caddr_t) &ifr) < 0)
+ fatal("ioctl(SIOCSIFMTU): %m");
- if(ioctl(ttyfd, SIOCSIFASYNCMAP, asyncmap) < 0) {
- syslog(LOG_ERR, "ioctl(SIOCSIFASYNCMAP): %m");
- quit();
- }
+ if(ioctl(ttyfd, SIOCSIFASYNCMAP, asyncmap) < 0)
+ fatal("ioctl(SIOCSIFASYNCMAP): %m");
c = (pcomp? 1: 0);
- if(ioctl(ttyfd, SIOCSIFCOMPPROT, c) < 0) {
- syslog(LOG_ERR, "ioctl(SIOCSIFCOMPPROT): %m");
- quit();
- }
+ if(ioctl(ttyfd, SIOCSIFCOMPPROT, c) < 0)
+ fatal("ioctl(SIOCSIFCOMPPROT): %m");
c = (accomp? 1: 0);
- if(ioctl(ttyfd, SIOCSIFCOMPAC, c) < 0) {
- syslog(LOG_ERR, "ioctl(SIOCSIFCOMPAC): %m");
- quit();
- }
+ if(ioctl(ttyfd, SIOCSIFCOMPAC, c) < 0)
+ fatal("ioctl(SIOCSIFCOMPAC): %m");
}
ext_accm accm;
{
if (ioctl(ttyfd, SIOCSIFXASYNCMAP, accm) < 0 && errno != ENOTTY)
- syslog(LOG_WARNING, "ioctl(set extended ACCM): %m");
+ warn("ioctl(set extended ACCM): %m");
}
char c;
if (ioctl(ttyfd, SIOCSIFMRU, mru) < 0) {
- syslog(LOG_ERR, "ioctl(SIOCSIFMRU): %m");
+ error("ioctl(SIOCSIFMRU): %m");
}
if (ioctl(ttyfd, SIOCSIFRASYNCMAP, (caddr_t) asyncmap) < 0) {
- syslog(LOG_ERR, "ioctl(SIOCSIFRASYNCMAP): %m");
+ error("ioctl(SIOCSIFRASYNCMAP): %m");
}
c = 2 + (pcomp? 1: 0);
if(ioctl(ttyfd, SIOCSIFCOMPPROT, c) < 0) {
- syslog(LOG_ERR, "ioctl(SIOCSIFCOMPPROT): %m");
+ error("ioctl(SIOCSIFCOMPPROT): %m");
}
c = 2 + (accomp? 1: 0);
if (ioctl(ttyfd, SIOCSIFCOMPAC, c) < 0) {
- syslog(LOG_ERR, "ioctl(SIOCSIFCOMPAC): %m");
+ error("ioctl(SIOCSIFCOMPAC): %m");
}
}
x = (isopen? 1: 0) + (isup? 2: 0);
if (ioctl(ttyfd, SIOCSIFCOMP, x) < 0 && errno != ENOTTY)
- syslog(LOG_ERR, "ioctl (SIOCSIFCOMP): %m");
+ error("ioctl (SIOCSIFCOMP): %m");
}
/*
int x;
if (ioctl(ttyfd, SIOCGIFCOMP, &x) < 0) {
- syslog(LOG_ERR, "ioctl(SIOCGIFCOMP): %m");
+ error("ioctl(SIOCGIFCOMP): %m");
return 0;
}
return x & CCP_FATALERROR;
x = (vjcomp? 1: 0) + (cidcomp? 0: 2) + (maxcid << 4);
if (ioctl(ttyfd, SIOCSIFVJCOMP, x) < 0) {
- syslog(LOG_ERR, "ioctl(SIOCSIFVJCOMP): %m");
+ error("ioctl(SIOCSIFVJCOMP): %m");
return 0;
}
return 1;
strlcpy(ifr.ifr_name, sizeof (ifr.ifr_name), ifname);
if (ioctl(sockfd, SIOCGIFFLAGS, (caddr_t) &ifr) < 0) {
- syslog(LOG_ERR, "ioctl (SIOCGIFFLAGS): %m");
+ error("ioctl (SIOCGIFFLAGS): %m");
return 0;
}
ifr.ifr_flags |= IFF_UP;
if (ioctl(sockfd, SIOCSIFFLAGS, (caddr_t) &ifr) < 0) {
- syslog(LOG_ERR, "ioctl(SIOCSIFFLAGS): %m");
+ error("ioctl(SIOCSIFFLAGS): %m");
return 0;
}
npi.protocol = proto;
npi.mode = mode;
if (ioctl(ppp_fd, PPPIOCSNPMODE, &npi) < 0) {
- syslog(LOG_ERR, "ioctl(set NP %d mode to %d): %m", proto, mode);
+ error("ioctl(set NP %d mode to %d): %m", proto, mode);
return 0;
}
return 1;
strlcpy(ifr.ifr_name, sizeof (ifr.ifr_name), ifname);
if (ioctl(sockfd, SIOCGIFFLAGS, (caddr_t) &ifr) < 0) {
- syslog(LOG_ERR, "ioctl (SIOCGIFFLAGS): %m");
+ error("ioctl (SIOCGIFFLAGS): %m");
rv = 0;
} else {
ifr.ifr_flags &= ~IFF_UP;
if (ioctl(sockfd, SIOCSIFFLAGS, (caddr_t) &ifr) < 0) {
- syslog(LOG_ERR, "ioctl(SIOCSIFFLAGS): %m");
+ error("ioctl(SIOCSIFFLAGS): %m");
rv = 0;
} else
if_is_up = 0;
strlcpy(ifr.ifr_name, sizeof (ifr.ifr_name), ifname);
SET_SA_FAMILY(ifr.ifr_addr, AF_INET);
if (m != 0) {
- syslog(LOG_INFO, "Setting interface mask to %s\n", ip_ntoa(m));
+ info("Setting interface mask to %s\n", ip_ntoa(m));
((struct sockaddr_in *) &ifr.ifr_addr)->sin_addr.s_addr = m;
if (ioctl(sockfd, SIOCSIFNETMASK, (caddr_t) &ifr) < 0) {
- syslog(LOG_ERR, "ioctl(SIOCSIFNETMASK): %m");
+ error("ioctl(SIOCSIFNETMASK): %m");
ret = 0;
}
}
((struct sockaddr_in *) &ifr.ifr_addr)->sin_addr.s_addr = o;
if (ioctl(sockfd, SIOCSIFADDR, (caddr_t) &ifr) < 0) {
- syslog(LOG_ERR, "ioctl(SIOCSIFADDR): %m");
+ error("ioctl(SIOCSIFADDR): %m");
ret = 0;
}
SET_SA_FAMILY(ifr.ifr_dstaddr, AF_INET);
((struct sockaddr_in *) &ifr.ifr_dstaddr)->sin_addr.s_addr = h;
if (ioctl(sockfd, SIOCSIFDSTADDR, (caddr_t) &ifr) < 0) {
- syslog(LOG_ERR, "ioctl(SIOCSIFDSTADDR): %m");
+ error("ioctl(SIOCSIFDSTADDR): %m");
ret = 0;
}
/* XXX is this necessary? */
((struct sockaddr_in *) &ifr.ifr_addr)->sin_addr.s_addr = o;
if (ioctl(sockfd, SIOCSIFADDR, (caddr_t) &ifr) < 0) {
- syslog(LOG_ERR, "ioctl(SIOCSIFADDR): %m");
+ error("ioctl(SIOCSIFADDR): %m");
ret = 0;
}
((struct sockaddr_in *) &rt.rt_gateway)->sin_addr.s_addr = o;
rt.rt_flags = RTF_HOST;
if (ioctl(sockfd, SIOCDELRT, (caddr_t) &rt) < 0) {
- syslog(LOG_ERR, "ioctl(SIOCDELRT): %m");
+ error("ioctl(SIOCDELRT): %m");
return 0;
}
return 1;
((struct sockaddr_in *) &rt.rt_gateway)->sin_addr.s_addr = g;
rt.rt_flags = RTF_GATEWAY;
if (ioctl(sockfd, SIOCADDRT, &rt) < 0) {
- syslog(LOG_ERR, "default route ioctl(SIOCADDRT): %m");
+ error("default route ioctl(SIOCADDRT): %m");
return 0;
}
default_route_gateway = g;
((struct sockaddr_in *) &rt.rt_gateway)->sin_addr.s_addr = g;
rt.rt_flags = RTF_GATEWAY;
if (ioctl(sockfd, SIOCDELRT, &rt) < 0) {
- syslog(LOG_ERR, "default route ioctl(SIOCDELRT): %m");
+ error("default route ioctl(SIOCDELRT): %m");
return 0;
}
default_route_gateway = 0;
* as our local address.
*/
if (!get_ether_addr(hisaddr, &arpreq.arp_ha)) {
- syslog(LOG_WARNING, "Cannot determine ethernet address for proxy ARP");
+ warn("Cannot determine ethernet address for proxy ARP");
return 0;
}
((struct sockaddr_in *) &arpreq.arp_pa)->sin_addr.s_addr = hisaddr;
arpreq.arp_flags = ATF_PERM | ATF_PUBL;
if (ioctl(sockfd, SIOCSARP, (caddr_t)&arpreq) < 0) {
- syslog(LOG_ERR, "ioctl(SIOCSARP): %m");
+ error("ioctl(SIOCSARP): %m");
return 0;
}
SET_SA_FAMILY(arpreq.arp_pa, AF_INET);
((struct sockaddr_in *) &arpreq.arp_pa)->sin_addr.s_addr = hisaddr;
if (ioctl(sockfd, SIOCDARP, (caddr_t)&arpreq) < 0) {
- syslog(LOG_ERR, "ioctl(SIOCDARP): %m");
+ error("ioctl(SIOCDARP): %m");
return 0;
}
proxy_arp_addr = 0;
int kvm_read(int fd, off_t offset, void *buf, int nbytes)
{
if (lseek(fd, offset, SEEK_SET) != offset) {
- syslog(LOG_ERR,"lseek in kmem: %m");
+ error("lseek in kmem: %m");
return(0);
}
return(read(fd, buf, nbytes));
/* Open kernel memory for reading */
if ((kd = open("/dev/kmem", O_RDONLY)) < 0) {
- syslog(LOG_ERR, "/dev/kmem: %m");
+ error("/dev/kmem: %m");
return 0;
}
/* Fetch namelist */
if (nlist("/unix", nl) != 0) {
- syslog(LOG_ERR, "nlist(): %m");
+ error("nlist(): %m");
return 0;
}
if (kvm_read(kd, nl[N_IFNET].n_value, (char *)&addr, sizeof(addr))
!= sizeof(addr)) {
- syslog(LOG_ERR, "error reading ifnet addr");
+ error("error reading ifnet addr");
return 0;
}
for ( ; addr && !found; addr = (u_long)ifp->if_next) {
if (kvm_read(kd, addr, (char *)ac, sizeof(*ac)) != sizeof(*ac)) {
- syslog(LOG_ERR, "error reading ifnet");
+ error("error reading ifnet");
return 0;
}
for (ifap = ifp->if_addrlist; ifap; ifap=ifaddr.ifa.ifa_next) {
if (kvm_read(kd, (u_long)ifap, (char *)&ifaddr,
sizeof(ifaddr)) != sizeof(ifaddr)) {
- syslog(LOG_ERR, "error reading ifaddr");
+ error("error reading ifaddr");
return 0;
}
if (kvm_read(kd, (u_long)ifaddr.ifa.ifa_addr, &ifaddrsaddr,
sizeof(struct sockaddr_in)) != sizeof(struct sockaddr_in)) {
- syslog(LOG_ERR, "error reading ifaddrsaddr");
+ error("error reading ifaddrsaddr");
return(0);
}
if (kvm_read(kd, (u_long)ifaddr.ifa.ifa_netmask, &ifmasksaddr,
sizeof(struct sockaddr_in)) != sizeof(struct sockaddr_in)) {
- syslog(LOG_ERR, "error reading ifmasksaddr");
+ error("error reading ifmasksaddr");
return(0);
}
/* Check if this interface on the right subnet */
ifip = ifinetptr->sin_addr.s_addr;
if (kvm_read(kd, (u_long)ifaddr.ifa.ifa_netmask, &ifmasksaddr,
sizeof(struct sockaddr_in)) != sizeof(struct sockaddr_in)) {
- syslog(LOG_ERR, "error reading ifmasksaddr");
+ error("error reading ifmasksaddr");
return(0);
}
mask = ifmasksaddr.sin_addr.s_addr;
ifc.ifc_len = sizeof(ifs);
ifc.ifc_req = ifs;
if (ioctl(sockfd, SIOCGIFCONF, &ifc) < 0) {
- syslog(LOG_WARNING, "ioctl(SIOCGIFCONF): %m");
+ warn("ioctl(SIOCGIFCONF): %m");
return mask;
}
ifend = (struct ifreq *) (ifc.ifc_buf + ifc.ifc_len);
devname = device;
if ((rc = ttylock(devname)) == 0) {
- devlocked = (char *) malloc(strlen(devname) + 1);
- sprintf(devlocked,"%s",devname);
+ devlocked = strdup(devname);
} else
devlocked = (char *) 0;
*/
#ifndef lint
-static char rcsid[] = "$Id: sys-bsd.c,v 1.36 1999/03/12 06:07:21 paulus Exp $";
+static char rcsid[] = "$Id: sys-bsd.c,v 1.37 1999/03/16 02:57:06 paulus Exp $";
/* $NetBSD: sys-bsd.c,v 1.1.1.3 1997/09/26 18:53:04 christos Exp $ */
#endif
*/
#include <stdio.h>
-#include <syslog.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
static int sockfd; /* socket for doing interface ioctls */
+static fd_set in_fds; /* set of fds that wait_input waits for */
+static int max_in_fd; /* highest fd set in in_fds */
+
static int if_is_up; /* the interface is currently up */
static u_int32_t ifaddrs[2]; /* local and remote addresses we set */
static u_int32_t default_route_gateway; /* gateway addr for default route */
sys_init()
{
/* Get an internet socket for doing socket ioctl's on. */
- if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
- syslog(LOG_ERR, "Couldn't create IP socket: %m");
- die(1);
- }
+ if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
+ fatal("Couldn't create IP socket: %m");
+
+ FD_ZERO(&in_fds);
+ max_in_fd = 0;
}
/*
{
#ifndef CDTRCTS
if (crtscts == 2) {
- syslog(LOG_WARNING, "DTR/CTS flow control is not supported on this system");
+ warn("DTR/CTS flow control is not supported on this system");
return 0;
}
#endif
/*
* Demand mode - prime the old ppp device to relinquish the unit.
*/
- if (ioctl(ppp_fd, PPPIOCXFERUNIT, 0) < 0) {
- syslog(LOG_ERR, "ioctl(transfer ppp unit): %m");
- die(1);
- }
+ if (ioctl(ppp_fd, PPPIOCXFERUNIT, 0) < 0)
+ fatal("ioctl(transfer ppp unit): %m");
}
/*
* Save the old line discipline of fd, and set it to PPP.
*/
- if (ioctl(fd, TIOCGETD, &initdisc) < 0) {
- syslog(LOG_ERR, "ioctl(TIOCGETD): %m");
- die(1);
- }
- if (ioctl(fd, TIOCSETD, &pppdisc) < 0) {
- syslog(LOG_ERR, "ioctl(TIOCSETD): %m");
- die(1);
- }
+ if (ioctl(fd, TIOCGETD, &initdisc) < 0)
+ fatal("ioctl(TIOCGETD): %m");
+ if (ioctl(fd, TIOCSETD, &pppdisc) < 0)
+ fatal("ioctl(TIOCSETD): %m");
if (!demand) {
/*
* Find out which interface we were given.
*/
- if (ioctl(fd, PPPIOCGUNIT, &ifunit) < 0) {
- syslog(LOG_ERR, "ioctl(PPPIOCGUNIT): %m");
- die(1);
- }
+ if (ioctl(fd, PPPIOCGUNIT, &ifunit) < 0) {
+ fatal("ioctl(PPPIOCGUNIT): %m");
} else {
/*
* Check that we got the same unit again.
*/
- if (ioctl(fd, PPPIOCGUNIT, &x) < 0) {
- syslog(LOG_ERR, "ioctl(PPPIOCGUNIT): %m");
- die(1);
- }
- if (x != ifunit) {
- syslog(LOG_ERR, "transfer_ppp failed: wanted unit %d, got %d",
- ifunit, x);
- die(1);
- }
+ if (ioctl(fd, PPPIOCGUNIT, &x) < 0) {
+ fatal("ioctl(PPPIOCGUNIT): %m");
+ if (x != ifunit)
+ fatal("transfer_ppp failed: wanted unit %d, got %d", ifunit, x);
x = TTYDISC;
ioctl(loop_slave, TIOCSETD, &x);
}
*/
if (kdebugflag) {
if (ioctl(fd, PPPIOCGFLAGS, (caddr_t) &x) < 0) {
- syslog(LOG_WARNING, "ioctl (PPPIOCGFLAGS): %m");
+ warn("ioctl (PPPIOCGFLAGS): %m");
} else {
x |= (kdebugflag & 0xFF) * SC_DEBUG;
if (ioctl(fd, PPPIOCSFLAGS, (caddr_t) &x) < 0)
- syslog(LOG_WARNING, "ioctl(PPPIOCSFLAGS): %m");
+ warn("ioctl(PPPIOCSFLAGS): %m");
}
}
*/
if ((initfdflags = fcntl(fd, F_GETFL)) == -1
|| fcntl(fd, F_SETFL, initfdflags | O_NONBLOCK) == -1) {
- syslog(LOG_WARNING, "Couldn't set device to non-blocking mode: %m");
+ warn("Couldn't set device to non-blocking mode: %m");
}
}
/*
* Transfer the ppp interface back to the loopback.
*/
- if (ioctl(ppp_fd, PPPIOCXFERUNIT, 0) < 0) {
- syslog(LOG_ERR, "ioctl(transfer ppp unit): %m");
- die(1);
- }
+ if (ioctl(ppp_fd, PPPIOCXFERUNIT, 0) < 0)
+ fatal("ioctl(transfer ppp unit): %m");
x = PPPDISC;
- if (ioctl(loop_slave, TIOCSETD, &x) < 0) {
- syslog(LOG_ERR, "ioctl(TIOCSETD): %m");
- die(1);
- }
+ if (ioctl(loop_slave, TIOCSETD, &x) < 0)
+ fatal("ioctl(TIOCSETD): %m");
/*
* Check that we got the same unit again.
*/
- if (ioctl(loop_slave, PPPIOCGUNIT, &x) < 0) {
- syslog(LOG_ERR, "ioctl(PPPIOCGUNIT): %m");
- die(1);
- }
- if (x != ifunit) {
- syslog(LOG_ERR, "transfer_ppp failed: wanted unit %d, got %d",
- ifunit, x);
- die(1);
- }
+ if (ioctl(loop_slave, PPPIOCGUNIT, &x) < 0)
+ fatal("ioctl(PPPIOCGUNIT): %m");
+ if (x != ifunit)
+ fatal("transfer_ppp failed: wanted unit %d, got %d", ifunit, x);
ppp_fd = loop_slave;
}
{
/* Reset non-blocking mode on fd. */
if (initfdflags != -1 && fcntl(fd, F_SETFL, initfdflags) < 0)
- syslog(LOG_WARNING, "Couldn't restore device fd flags: %m");
+ warn("Couldn't restore device fd flags: %m");
initfdflags = -1;
/* Restore old line discipline. */
if (initdisc >= 0 && ioctl(fd, TIOCSETD, &initdisc) < 0)
- syslog(LOG_ERR, "ioctl(TIOCSETD): %m");
+ error("ioctl(TIOCSETD): %m");
initdisc = -1;
if (fd == ppp_fd)
break;
}
if (s != NULL) {
- syslog(LOG_WARNING, "Serial link is not 8-bit clean:");
- syslog(LOG_WARNING, "All received characters had %s", s);
+ warn("Serial link is not 8-bit clean:");
+ warn("All received characters had %s", s);
}
}
}
{
struct termios tios;
- if (tcgetattr(fd, &tios) < 0) {
- syslog(LOG_ERR, "tcgetattr: %m");
- die(1);
- }
+ if (tcgetattr(fd, &tios) < 0)
+ fatal("tcgetattr: %m");
if (!restore_term) {
inittermios = tios;
* We can't proceed if the serial port speed is 0,
* since that implies that the serial port is disabled.
*/
- if (inspeed == 0) {
- syslog(LOG_ERR, "Baud rate for %s is 0; need explicit baud rate",
- devnam);
- die(1);
- }
+ if (inspeed == 0)
+ fatal("Baud rate for %s is 0; need explicit baud rate", devnam);
}
baud_rate = inspeed;
- if (tcsetattr(fd, TCSAFLUSH, &tios) < 0) {
- syslog(LOG_ERR, "tcsetattr: %m");
- die(1);
- }
+ if (tcsetattr(fd, TCSAFLUSH, &tios) < 0)
+ fatal("tcsetattr: %m");
restore_term = 1;
}
}
if (tcsetattr(fd, TCSAFLUSH, &inittermios) < 0)
if (errno != ENXIO)
- syslog(LOG_WARNING, "tcsetattr: %m");
+ warn("tcsetattr: %m");
ioctl(fd, TIOCSWINSZ, &wsinfo);
restore_term = 0;
}
struct termios tios;
int pppdisc = PPPDISC;
- if (openpty(&loop_master, &loop_slave, loop_name, NULL, NULL) < 0) {
- syslog(LOG_ERR, "No free pty for loopback");
- die(1);
- }
- SYSDEBUG((LOG_DEBUG, "using %s for loopback", loop_name));
+ if (openpty(&loop_master, &loop_slave, loop_name, NULL, NULL) < 0)
+ fatal("No free pty for loopback");
+ SYSDEBUG(("using %s for loopback", loop_name));
if (tcgetattr(loop_slave, &tios) == 0) {
tios.c_cflag &= ~(CSIZE | CSTOPB | PARENB);
tios.c_oflag = 0;
tios.c_lflag = 0;
if (tcsetattr(loop_slave, TCSAFLUSH, &tios) < 0)
- syslog(LOG_WARNING, "couldn't set attributes on loopback: %m");
+ warn("couldn't set attributes on loopback: %m");
}
if ((flags = fcntl(loop_master, F_GETFL)) != -1)
if (fcntl(loop_master, F_SETFL, flags | O_NONBLOCK) == -1)
- syslog(LOG_WARNING, "couldn't set loopback to nonblock: %m");
+ warn("couldn't set loopback to nonblock: %m");
ppp_fd = loop_slave;
- if (ioctl(ppp_fd, TIOCSETD, &pppdisc) < 0) {
- syslog(LOG_ERR, "ioctl(TIOCSETD): %m");
- die(1);
- }
+ if (ioctl(ppp_fd, TIOCSETD, &pppdisc) < 0)
+ fatal("ioctl(TIOCSETD): %m");
/*
* Find out which interface we were given.
*/
- if (ioctl(ppp_fd, PPPIOCGUNIT, &ifunit) < 0) {
- syslog(LOG_ERR, "ioctl(PPPIOCGUNIT): %m");
- die(1);
- }
+ if (ioctl(ppp_fd, PPPIOCGUNIT, &ifunit) < 0)
+ fatal("ioctl(PPPIOCGUNIT): %m");
/*
* Enable debug in the driver if requested.
*/
if (kdebugflag) {
if (ioctl(ppp_fd, PPPIOCGFLAGS, (caddr_t) &flags) < 0) {
- syslog(LOG_WARNING, "ioctl (PPPIOCGFLAGS): %m");
+ warn("ioctl (PPPIOCGFLAGS): %m");
} else {
flags |= (kdebugflag & 0xFF) * SC_DEBUG;
if (ioctl(ppp_fd, PPPIOCSFLAGS, (caddr_t) &flags) < 0)
- syslog(LOG_WARNING, "ioctl(PPPIOCSFLAGS): %m");
+ warn("ioctl(PPPIOCSFLAGS): %m");
}
}
int len;
{
if (debug)
- log_packet(p, len, "sent ", LOG_DEBUG);
+ dbglog("sent %P", p, len);
if (write(ttyfd, p, len) < 0) {
if (errno != EIO)
- syslog(LOG_ERR, "write: %m");
+ error("write: %m");
}
}
/*
- * wait_input - wait until there is data available on ttyfd,
+ * wait_input - wait until there is data available,
* for the length of time specified by *timo (indefinite
* if timo is NULL).
*/
fd_set ready;
int n;
- FD_ZERO(&ready);
- FD_SET(ttyfd, &ready);
- n = select(ttyfd+1, &ready, NULL, &ready, timo);
- if (n < 0 && errno != EINTR) {
- syslog(LOG_ERR, "select: %m");
- die(1);
- }
+ ready = in_fds;
+ n = select(max_in_fd + 1, &ready, NULL, &ready, timo);
+ if (n < 0 && errno != EINTR)
+ fatal("select: %m");
}
+/*
+ * add_fd - add an fd to the set that wait_input waits for.
+ */
+void add_fd(int fd)
+{
+ FD_SET(fd, &in_fds);
+ if (fd > max_in_fd)
+ max_in_fd = fd;
+}
+
+/*
+ * remove_fd - remove an fd from the set that wait_input waits for.
+ */
+void remove_fd(int fd)
+{
+ FD_CLR(fd, &in_fds);
+}
+
+#if 0
/*
* wait_loop_output - wait until there is data available on the
* loopback, for the length of time specified by *timo (indefinite
FD_ZERO(&ready);
FD_SET(loop_master, &ready);
n = select(loop_master + 1, &ready, NULL, &ready, timo);
- if (n < 0 && errno != EINTR) {
- syslog(LOG_ERR, "select: %m");
- die(1);
- }
+ if (n < 0 && errno != EINTR)
+ fatal("select: %m");
}
int n;
n = select(0, NULL, NULL, NULL, timo);
- if (n < 0 && errno != EINTR) {
- syslog(LOG_ERR, "select: %m");
- die(1);
- }
+ if (n < 0 && errno != EINTR)
+ fatal("select: %m");
}
+#endif
/*
if ((len = read(ttyfd, buf, PPP_MTU + PPP_HDRLEN)) < 0) {
if (errno == EWOULDBLOCK || errno == EINTR)
return -1;
- syslog(LOG_ERR, "read: %m");
- die(1);
+ fatal("read: %m");
}
return len;
}
rv = 1;
}
- if (n == 0) {
- syslog(LOG_ERR, "eof on loopback");
- die(1);
- } else if (errno != EWOULDBLOCK){
- syslog(LOG_ERR, "read from loopback: %m");
- die(1);
- }
+ if (n == 0)
+ fatal("eof on loopback");
+ if (errno != EWOULDBLOCK)
+ fatal("read from loopback: %m");
return rv;
}
strlcpy(ifr.ifr_name, sizeof (ifr.ifr_name), ifname);
ifr.ifr_mtu = mtu;
- if (ioctl(sockfd, SIOCSIFMTU, (caddr_t) &ifr) < 0) {
- syslog(LOG_ERR, "ioctl(SIOCSIFMTU): %m");
- quit();
- }
+ if (ioctl(sockfd, SIOCSIFMTU, (caddr_t) &ifr) < 0)
+ fatal("ioctl(SIOCSIFMTU): %m");
- if (ioctl(ppp_fd, PPPIOCSASYNCMAP, (caddr_t) &asyncmap) < 0) {
- syslog(LOG_ERR, "ioctl(PPPIOCSASYNCMAP): %m");
- quit();
- }
+ if (ioctl(ppp_fd, PPPIOCSASYNCMAP, (caddr_t) &asyncmap) < 0)
+ fatal("ioctl(PPPIOCSASYNCMAP): %m");
- if (ioctl(ppp_fd, PPPIOCGFLAGS, (caddr_t) &x) < 0) {
- syslog(LOG_ERR, "ioctl (PPPIOCGFLAGS): %m");
- quit();
- }
+ if (ioctl(ppp_fd, PPPIOCGFLAGS, (caddr_t) &x) < 0)
+ fatal("ioctl (PPPIOCGFLAGS): %m");
x = pcomp? x | SC_COMP_PROT: x &~ SC_COMP_PROT;
x = accomp? x | SC_COMP_AC: x &~ SC_COMP_AC;
- if (ioctl(ppp_fd, PPPIOCSFLAGS, (caddr_t) &x) < 0) {
- syslog(LOG_ERR, "ioctl(PPPIOCSFLAGS): %m");
- quit();
- }
+ if (ioctl(ppp_fd, PPPIOCSFLAGS, (caddr_t) &x) < 0)
+ fatal("ioctl(PPPIOCSFLAGS): %m");
}
ext_accm accm;
{
if (ioctl(ppp_fd, PPPIOCSXASYNCMAP, accm) < 0 && errno != ENOTTY)
- syslog(LOG_WARNING, "ioctl(set extended ACCM): %m");
+ warn("ioctl(set extended ACCM): %m");
}
{
int x;
- if (ioctl(ppp_fd, PPPIOCSMRU, (caddr_t) &mru) < 0) {
- syslog(LOG_ERR, "ioctl(PPPIOCSMRU): %m");
- quit();
- }
- if (ioctl(ppp_fd, PPPIOCSRASYNCMAP, (caddr_t) &asyncmap) < 0) {
- syslog(LOG_ERR, "ioctl(PPPIOCSRASYNCMAP): %m");
- quit();
- }
- if (ioctl(ppp_fd, PPPIOCGFLAGS, (caddr_t) &x) < 0) {
- syslog(LOG_ERR, "ioctl (PPPIOCGFLAGS): %m");
- quit();
- }
+ if (ioctl(ppp_fd, PPPIOCSMRU, (caddr_t) &mru) < 0)
+ fatal("ioctl(PPPIOCSMRU): %m");
+ if (ioctl(ppp_fd, PPPIOCSRASYNCMAP, (caddr_t) &asyncmap) < 0)
+ fatal("ioctl(PPPIOCSRASYNCMAP): %m");
+ if (ioctl(ppp_fd, PPPIOCGFLAGS, (caddr_t) &x) < 0)
+ fatal("ioctl (PPPIOCGFLAGS): %m");
x = !accomp? x | SC_REJ_COMP_AC: x &~ SC_REJ_COMP_AC;
- if (ioctl(ppp_fd, PPPIOCSFLAGS, (caddr_t) &x) < 0) {
- syslog(LOG_ERR, "ioctl(PPPIOCSFLAGS): %m");
- quit();
- }
+ if (ioctl(ppp_fd, PPPIOCSFLAGS, (caddr_t) &x) < 0)
+ fatal("ioctl(PPPIOCSFLAGS): %m");
}
/*
int x;
if (ioctl(ppp_fd, PPPIOCGFLAGS, (caddr_t) &x) < 0) {
- syslog(LOG_ERR, "ioctl (PPPIOCGFLAGS): %m");
+ error("ioctl (PPPIOCGFLAGS): %m");
return;
}
x = isopen? x | SC_CCP_OPEN: x &~ SC_CCP_OPEN;
x = isup? x | SC_CCP_UP: x &~ SC_CCP_UP;
if (ioctl(ppp_fd, PPPIOCSFLAGS, (caddr_t) &x) < 0)
- syslog(LOG_ERR, "ioctl(PPPIOCSFLAGS): %m");
+ error("ioctl(PPPIOCSFLAGS): %m");
}
/*
int x;
if (ioctl(ppp_fd, PPPIOCGFLAGS, (caddr_t) &x) < 0) {
- syslog(LOG_ERR, "ioctl(PPPIOCGFLAGS): %m");
+ error("ioctl(PPPIOCGFLAGS): %m");
return 0;
}
return x & SC_DC_FERROR;
if (pass->bf_len > 0) {
if (ioctl(ppp_fd, PPPIOCSPASS, pass) < 0) {
- syslog(LOG_ERR, "Couldn't set pass-filter in kernel: %m");
+ error("Couldn't set pass-filter in kernel: %m");
ret = 0;
}
}
if (active->bf_len > 0) {
if (ioctl(ppp_fd, PPPIOCSACTIVE, active) < 0) {
- syslog(LOG_ERR, "Couldn't set active-filter in kernel: %m");
+ error("Couldn't set active-filter in kernel: %m");
ret = 0;
}
}
u_int x;
if (ioctl(ppp_fd, PPPIOCGFLAGS, (caddr_t) &x) < 0) {
- syslog(LOG_ERR, "ioctl (PPPIOCGFLAGS): %m");
+ error("ioctl (PPPIOCGFLAGS): %m");
return 0;
}
x = vjcomp ? x | SC_COMP_TCP: x &~ SC_COMP_TCP;
x = cidcomp? x & ~SC_NO_TCP_CCID: x | SC_NO_TCP_CCID;
if (ioctl(ppp_fd, PPPIOCSFLAGS, (caddr_t) &x) < 0) {
- syslog(LOG_ERR, "ioctl(PPPIOCSFLAGS): %m");
+ error("ioctl(PPPIOCSFLAGS): %m");
return 0;
}
if (vjcomp && ioctl(ppp_fd, PPPIOCSMAXCID, (caddr_t) &maxcid) < 0) {
- syslog(LOG_ERR, "ioctl(PPPIOCSFLAGS): %m");
+ error("ioctl(PPPIOCSFLAGS): %m");
return 0;
}
return 1;
strlcpy(ifr.ifr_name, sizeof (ifr.ifr_name), ifname);
if (ioctl(sockfd, SIOCGIFFLAGS, (caddr_t) &ifr) < 0) {
- syslog(LOG_ERR, "ioctl (SIOCGIFFLAGS): %m");
+ error("ioctl (SIOCGIFFLAGS): %m");
return 0;
}
ifr.ifr_flags |= IFF_UP;
if (ioctl(sockfd, SIOCSIFFLAGS, (caddr_t) &ifr) < 0) {
- syslog(LOG_ERR, "ioctl(SIOCSIFFLAGS): %m");
+ error("ioctl(SIOCSIFFLAGS): %m");
return 0;
}
if_is_up = 1;
npi.protocol = proto;
npi.mode = mode;
if (ioctl(ppp_fd, PPPIOCSNPMODE, &npi) < 0) {
- syslog(LOG_ERR, "ioctl(set NP %d mode to %d): %m", proto, mode);
+ error("ioctl(set NP %d mode to %d): %m", proto, mode);
return 0;
}
return 1;
strlcpy(ifr.ifr_name, sizeof (ifr.ifr_name), ifname);
if (ioctl(sockfd, SIOCGIFFLAGS, (caddr_t) &ifr) < 0) {
- syslog(LOG_ERR, "ioctl (SIOCGIFFLAGS): %m");
+ error("ioctl (SIOCGIFFLAGS): %m");
rv = 0;
} else {
ifr.ifr_flags &= ~IFF_UP;
if (ioctl(sockfd, SIOCSIFFLAGS, (caddr_t) &ifr) < 0) {
- syslog(LOG_ERR, "ioctl(SIOCSIFFLAGS): %m");
+ error("ioctl(SIOCSIFFLAGS): %m");
rv = 0;
} else
if_is_up = 0;
strlcpy(ifr.ifr_name, sizeof(ifr.ifr_name), ifname);
if (ioctl(sockfd, SIOCDIFADDR, (caddr_t) &ifr) < 0) {
if (errno != EADDRNOTAVAIL)
- syslog(LOG_WARNING, "Couldn't remove interface address: %m");
+ warn("Couldn't remove interface address: %m");
}
if (ioctl(sockfd, SIOCAIFADDR, (caddr_t) &ifra) < 0) {
if (errno != EEXIST) {
- syslog(LOG_ERR, "Couldn't set interface address: %m");
+ error("Couldn't set interface address: %m");
return 0;
}
- syslog(LOG_WARNING,
- "Couldn't set interface address: Address %s already exists",
- ip_ntoa(o));
+ warn("Couldn't set interface address: Address %I already exists", o);
}
ifaddrs[0] = o;
ifaddrs[1] = h;
BZERO(&ifra.ifra_mask, sizeof(ifra.ifra_mask));
if (ioctl(sockfd, SIOCDIFADDR, (caddr_t) &ifra) < 0) {
if (errno != EADDRNOTAVAIL)
- syslog(LOG_WARNING, "Couldn't delete interface address: %m");
+ warn("Couldn't delete interface address: %m");
return 0;
}
return 1;
} rtmsg;
if ((routes = socket(PF_ROUTE, SOCK_RAW, AF_INET)) < 0) {
- syslog(LOG_ERR, "Couldn't %s default route: socket: %m",
+ error("Couldn't %s default route: socket: %m",
cmd=='s'? "add": "delete");
return 0;
}
rtmsg.hdr.rtm_msglen = sizeof(rtmsg);
if (write(routes, &rtmsg, sizeof(rtmsg)) < 0) {
- syslog(LOG_ERR, "Couldn't %s default route: %m",
+ error("Couldn't %s default route: %m",
cmd=='s'? "add": "delete");
close(routes);
return 0;
*/
memset(&arpmsg, 0, sizeof(arpmsg));
if (!get_ether_addr(hisaddr, &arpmsg.hwa)) {
- syslog(LOG_ERR, "Cannot determine ethernet address for proxy ARP");
+ error("Cannot determine ethernet address for proxy ARP");
return 0;
}
if ((routes = socket(PF_ROUTE, SOCK_RAW, AF_INET)) < 0) {
- syslog(LOG_ERR, "Couldn't add proxy arp entry: socket: %m");
+ error("Couldn't add proxy arp entry: socket: %m");
return 0;
}
arpmsg.hdr.rtm_msglen = (char *) &arpmsg.hwa - (char *) &arpmsg
+ arpmsg.hwa.sdl_len;
if (write(routes, &arpmsg, arpmsg.hdr.rtm_msglen) < 0) {
- syslog(LOG_ERR, "Couldn't add proxy arp entry: %m");
+ error("Couldn't add proxy arp entry: %m");
close(routes);
return 0;
}
arpmsg.hdr.rtm_seq = ++rtm_seq;
if ((routes = socket(PF_ROUTE, SOCK_RAW, AF_INET)) < 0) {
- syslog(LOG_ERR, "Couldn't delete proxy arp entry: socket: %m");
+ error("Couldn't delete proxy arp entry: socket: %m");
return 0;
}
if (write(routes, &arpmsg, arpmsg.hdr.rtm_msglen) < 0) {
- syslog(LOG_ERR, "Couldn't delete proxy arp entry: %m");
+ error("Couldn't delete proxy arp entry: %m");
close(routes);
return 0;
}
* as our local address.
*/
if (!get_ether_addr(hisaddr, &dls.sdl)) {
- syslog(LOG_ERR, "Cannot determine ethernet address for proxy ARP");
+ error("Cannot determine ethernet address for proxy ARP");
return 0;
}
((struct sockaddr_in *) &arpreq.arp_pa)->sin_addr.s_addr = hisaddr;
arpreq.arp_flags = ATF_PERM | ATF_PUBL;
if (ioctl(sockfd, SIOCSARP, (caddr_t)&arpreq) < 0) {
- syslog(LOG_ERR, "Couldn't add proxy arp entry: %m");
+ error("Couldn't add proxy arp entry: %m");
return 0;
}
SET_SA_FAMILY(arpreq.arp_pa, AF_INET);
((struct sockaddr_in *) &arpreq.arp_pa)->sin_addr.s_addr = hisaddr;
if (ioctl(sockfd, SIOCDARP, (caddr_t)&arpreq) < 0) {
- syslog(LOG_WARNING, "Couldn't delete proxy arp entry: %m");
+ warn("Couldn't delete proxy arp entry: %m");
return 0;
}
proxy_arp_addr = 0;
ifc.ifc_len = sizeof(ifs);
ifc.ifc_req = ifs;
if (ioctl(sockfd, SIOCGIFCONF, &ifc) < 0) {
- syslog(LOG_ERR, "ioctl(SIOCGIFCONF): %m");
+ error("ioctl(SIOCGIFCONF): %m");
return 0;
}
if (ifr >= ifend)
return 0;
- syslog(LOG_INFO, "found interface %s for proxy arp", ifr->ifr_name);
+ info("found interface %s for proxy arp", ifr->ifr_name);
/*
* Now scan through again looking for a link-level address
ifc.ifc_len = sizeof(ifs);
ifc.ifc_req = ifs;
if (ioctl(sockfd, SIOCGIFCONF, &ifc) < 0) {
- syslog(LOG_WARNING, "ioctl(SIOCGIFCONF): %m");
+ warn("ioctl(SIOCGIFCONF): %m");
return mask;
}
ifend = (struct ifreq *) (ifc.ifc_buf + ifc.ifc_len);
/* Read the lock file to find out who has the device locked */
n = read(fd, hdb_lock_buffer, 11);
if (n <= 0) {
- syslog(LOG_ERR, "Can't read pid from lock file %s", lock_file);
+ error("Can't read pid from lock file %s", lock_file);
close(fd);
} else {
hdb_lock_buffer[n] = 0;
/* pid no longer exists - remove the lock file */
if (unlink(lock_file) == 0) {
close(fd);
- syslog(LOG_NOTICE, "Removed stale lock on %s (pid %d)",
+ notice("Removed stale lock on %s (pid %d)",
dev, pid);
continue;
} else
- syslog(LOG_WARNING, "Couldn't remove stale lock on %s",
+ warn("Couldn't remove stale lock on %s",
dev);
} else
- syslog(LOG_NOTICE, "Device %s is locked by pid %d",
+ notice("Device %s is locked by pid %d",
dev, pid);
}
close(fd);
} else
- syslog(LOG_ERR, "Can't create lock file %s: %m", lock_file);
+ error("Can't create lock file %s: %m", lock_file);
free(lock_file);
lock_file = NULL;
return -1;
}
- sprintf(hdb_lock_buffer, "%10d\n", getpid());
+ slprintf(hdb_lock_buffer, sizeof(hdb_lock_buffer), "%10d\n", getpid());
write(fd, hdb_lock_buffer, 11);
close(fd);
*/
#ifndef lint
-static char rcsid[] = "$Id: sys-osf.c,v 1.18 1999/03/12 06:07:22 paulus Exp $";
+static char rcsid[] = "$Id: sys-osf.c,v 1.19 1999/03/16 02:57:06 paulus Exp $";
#endif
#include <stdio.h>
#include <sys/socket.h>
#include <sys/stream.h>
#include <sys/stropts.h>
-#include <sys/syslog.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/poll.h>
static u_int32_t default_route_gateway; /* Gateway for default route added */
static u_int32_t proxy_arp_addr; /* Addr for proxy arp entry added */
+#define MAX_POLLFDS 32
+static struct pollfd pollfds[MAX_POLLFDS];
+static int n_pollfds;
+
/* Prototypes for procedures local to this file. */
static int translate_speed __P((int));
static int baud_rate_of __P((int));
setlogmask(LOG_UPTO(LOG_DEBUG));
/* Get an internet socket for doing socket ioctl's on. */
- if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
- syslog(LOG_ERR, "Couldn't create IP socket: %m");
- die(1);
- }
+ if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
+ fatal("Couldn't create IP socket: %m");
if (default_device)
tty_sid = getsid((pid_t)0);
* Open the ppp device.
*/
pppfd = open("/dev/streams/ppp", O_RDWR | O_NONBLOCK, 0);
- if (pppfd < 0) {
- syslog(LOG_ERR, "Can't open /dev/streams/ppp: %m");
- die(1);
- }
+ if (pppfd < 0)
+ fatal("Can't open /dev/streams/ppp: %m");
if (kdebugflag) {
x = PPPDBG_LOG + PPPDBG_DRIVER;
strioctl(pppfd, PPPIO_DEBUG, &x, sizeof(int), 0);
}
/* Assign a new PPA and get its unit number. */
- if (strioctl(pppfd, PPPIO_NEWPPA, &ifunit, 0, sizeof(int)) < 0) {
- syslog(LOG_ERR, "Can't create new PPP interface: %m");
- die(1);
- }
+ if (strioctl(pppfd, PPPIO_NEWPPA, &ifunit, 0, sizeof(int)) < 0)
+ fatal("Can't create new PPP interface: %m");
/*
* Open the ppp device again and push the if_ppp module on it.
*/
iffd = open("/dev/streams/ppp", O_RDWR, 0);
- if (iffd < 0) {
- syslog(LOG_ERR, "Can't open /dev/streams/ppp (2): %m");
- die(1);
- }
+ if (iffd < 0)
+ fatal("Can't open /dev/streams/ppp (2): %m");
if (kdebugflag) {
x = PPPDBG_LOG + PPPDBG_DRIVER;
strioctl(iffd, PPPIO_DEBUG, &x, sizeof(int), 0);
}
- if (strioctl(iffd, PPPIO_ATTACH, &ifunit, sizeof(int), 0) < 0) {
- syslog(LOG_ERR, "Couldn't attach ppp interface to device: %m");
- die(1);
- }
- if (ioctl(iffd, I_PUSH, "if_ppp") < 0) {
- syslog(LOG_ERR, "Can't push ppp interface module: %m");
- die(1);
- }
+ if (strioctl(iffd, PPPIO_ATTACH, &ifunit, sizeof(int), 0) < 0)
+ fatal("Couldn't attach ppp interface to device: %m");
+ if (ioctl(iffd, I_PUSH, "if_ppp") < 0)
+ fatal("Can't push ppp interface module: %m");
if (kdebugflag) {
x = PPPDBG_LOG + PPPDBG_IF;
strioctl(iffd, PPPIO_DEBUG, &x, sizeof(int), 0);
}
- if (strioctl(iffd, PPPIO_NEWPPA, &ifunit, sizeof(int), 0) < 0) {
- syslog(LOG_ERR, "Couldn't create ppp interface unit: %m");
- die(1);
- }
+ if (strioctl(iffd, PPPIO_NEWPPA, &ifunit, sizeof(int), 0) < 0)
+ fatal("Couldn't create ppp interface unit: %m");
x = PPP_IP;
- if (strioctl(iffd, PPPIO_BIND, &x, sizeof(int), 0) < 0) {
- syslog(LOG_ERR, "Couldn't bind ppp interface to IP SAP: %m");
- die(1);
- }
+ if (strioctl(iffd, PPPIO_BIND, &x, sizeof(int), 0) < 0)
+ fatal("Couldn't bind ppp interface to IP SAP: %m");
+
+ n_pollfds = 0;
}
/*
struct sigaction sa;
if (streampipe(fdes) != 0)
- syslog(LOG_ERR, "streampipe(): %m\n");
+ error("streampipe(): %m\n");
else if (isastream(fdes[0]) == 1) {
if ((fret=fork()) < 0) {
- syslog(LOG_ERR, "fork(): %m\n");
+ error("fork(): %m\n");
} else if (fret == 0) {
/* Process to forward things from pipe to tty */
sigemptyset(&(sa.sa_mask));
if (FD_ISSET(fd, &readfds)) {
rret = read(fd, buffer, BUFFSIZE);
if (rret == 0) {
- MAINDEBUG((LOG_DEBUG, "slave died: EOF on tty."));
+ SYSDEBUG(("slave died: EOF on tty."));
exit(0);
} else {
write(fdes[1], buffer, rret);
if (FD_ISSET(fdes[1], &readfds)) {
rret = read(fdes[1], buffer, BUFFSIZE);
if (rret == 0) {
- MAINDEBUG((LOG_DEBUG, "slave died: EOF on pipe."));
+ SYSDEBUG(("slave died: EOF on pipe."));
exit(0);
} else {
write(fd, buffer, rret);
int i;
if (isastream(fd) != 1) {
- if ((ttyfd = fd = streamify(fd)) < 0) {
- syslog(LOG_ERR, "Couldn't get a STREAMS module!\n");
- die(1);
- }
+ if ((ttyfd = fd = streamify(fd)) < 0)
+ fatal("Couldn't get a STREAMS module!\n");
}
/* Pop any existing modules off the tty stream. */
if (ioctl(fd, I_LOOK, tty_modules[i]) < 0
|| ioctl(fd, I_POP, 0) < 0)
break;
- syslog(LOG_ERR, "popping module %s\n", tty_modules[i]);
+ error("popping module %s\n", tty_modules[i]);
}
tty_nmodules = i;
/* Push the async hdlc module and the compressor module. */
- if (ioctl(fd, I_PUSH, "ppp_ahdl") < 0) {
- syslog(LOG_ERR, "Couldn't push PPP Async HDLC module: %m");
- die(1);
- }
- if (ioctl(fd, I_PUSH, "ppp_comp") < 0) {
- syslog(LOG_ERR, "Couldn't push PPP compression module: %m");
-/* die(1); */
- }
+ if (ioctl(fd, I_PUSH, "ppp_ahdl") < 0)
+ fatal("Couldn't push PPP Async HDLC module: %m");
+ if (ioctl(fd, I_PUSH, "ppp_comp") < 0)
+ error("Couldn't push PPP compression module: %m");
/* read mode, message non-discard mode */
- if (ioctl(fd, I_SRDOPT, RMSGN|RPROTNORM) < 0) {
- syslog(LOG_ERR, "ioctl(I_SRDOPT, RMSGN): %m");
- die(1);
- }
+ if (ioctl(fd, I_SRDOPT, RMSGN|RPROTNORM) < 0)
+ fatal("ioctl(I_SRDOPT, RMSGN): %m");
/* Link the serial port under the PPP multiplexor. */
- if ((fdmuxid = ioctl(pppfd, I_LINK, fd)) < 0) {
- syslog(LOG_ERR, "Can't link tty to PPP mux: %m");
- die(1);
- }
+ if ((fdmuxid = ioctl(pppfd, I_LINK, fd)) < 0)
+ fatal("Can't link tty to PPP mux: %m");
/* close stdin, stdout, stderr if they might refer to the device */
if (default_device && !closed_stdio) {
*/
if ((initfdflags = fcntl(fd, F_GETFL)) == -1
|| fcntl(fd, F_SETFL, initfdflags | O_NONBLOCK) == -1) {
- syslog(LOG_WARNING, "Couldn't set device to non-blocking mode: %m");
+ warn("Couldn't set device to non-blocking mode: %m");
}
}
if (fdmuxid >= 0) {
if (ioctl(pppfd, I_UNLINK, fdmuxid) < 0) {
if (!hungup)
- syslog(LOG_ERR, "Can't unlink tty from PPP mux: %m");
+ error("Can't unlink tty from PPP mux: %m");
}
fdmuxid = -1;
/* Reset non-blocking mode on the file descriptor. */
if (initfdflags != -1 && fcntl(fd, F_SETFL, initfdflags) < 0)
- syslog(LOG_WARNING, "Couldn't restore device fd flags: %m");
+ warn("Couldn't restore device fd flags: %m");
initfdflags = -1;
if (!hungup) {
;
for (i = tty_nmodules - 1; i >= 0; --i)
if (ioctl(fd, I_PUSH, tty_modules[i]) < 0)
- syslog(LOG_ERR, "Couldn't restore tty module %s: %m",
+ error("Couldn't restore tty module %s: %m",
tty_modules[i]);
}
* seen the M_HANGUP message (it went up through the ppp
* driver to the stream head for our fd to /dev/ppp).
*/
- syslog(LOG_DEBUG, "sending hangup to %d", tty_sid);
+ dbglog("sending hangup to %d", tty_sid);
if (kill(tty_sid, SIGHUP) < 0)
- syslog(LOG_ERR, "couldn't kill pgrp: %m");
+ error("couldn't kill pgrp: %m");
}
if (orig_ttyfd >= 0) {
close(fd);
break;
}
if (s != NULL) {
- syslog(LOG_WARNING, "Serial link is not 8-bit clean:");
- syslog(LOG_WARNING, "All received characters had %s", s);
+ warn("Serial link is not 8-bit clean:");
+ warn("All received characters had %s", s);
}
}
for (speedp = speeds; speedp->speed_int; speedp++)
if (bps == speedp->speed_int)
return speedp->speed_val;
- syslog(LOG_WARNING, "speed %d not supported", bps);
+ warn("speed %d not supported", bps);
return 0;
}
int speed;
struct termios tios;
- if (tcgetattr(fd, &tios) < 0) {
- syslog(LOG_ERR, "tcgetattr: %m");
- die(1);
- }
+ if (tcgetattr(fd, &tios) < 0)
+ fatal("tcgetattr: %m");
if (!restore_term) {
inittermios = tios;
* We can't proceed if the serial port speed is 0,
* since that implies that the serial port is disabled.
*/
- if (speed == B0) {
- syslog(LOG_ERR, "Baud rate for %s is 0; need explicit baud rate",
- devnam);
- die(1);
- }
+ if (speed == B0)
+ fatal("Baud rate for %s is 0; need explicit baud rate", devnam);
}
- if (tcsetattr(fd, TCSAFLUSH, &tios) < 0) {
- syslog(LOG_ERR, "tcsetattr: %m");
- die(1);
- }
+ if (tcsetattr(fd, TCSAFLUSH, &tios) < 0)
+ fatal("tcsetattr: %m");
baud_rate = inspeed = baud_rate_of(speed);
restore_term = 1;
}
if (tcsetattr(fd, TCSAFLUSH, &inittermios) < 0)
if (!hungup && errno != ENXIO)
- syslog(LOG_WARNING, "tcsetattr: %m");
+ warn("tcsetattr: %m");
ioctl(fd, TIOCSWINSZ, &wsinfo);
restore_term = 0;
}
struct pollfd pfd;
if (debug)
- log_packet(p, len, "sent ", LOG_DEBUG);
+ dbglog("sent %P", p, len);
data.len = len;
data.buf = (caddr_t) p;
while (putmsg(pppfd, NULL, &data, 0) < 0) {
if (--retries < 0 || (errno != EWOULDBLOCK && errno != EAGAIN)) {
if (errno != ENXIO)
- syslog(LOG_ERR, "Couldn't send packet: %m");
+ error("Couldn't send packet: %m");
break;
}
pfd.fd = pppfd;
struct timeval *timo;
{
int t;
- struct pollfd pfd;
t = timo == NULL? -1: timo->tv_sec * 1000 + timo->tv_usec / 1000;
- pfd.fd = pppfd;
- pfd.events = POLLIN | POLLPRI | POLLHUP;
- if (poll(&pfd, 1, t) < 0 && errno != EINTR) {
- syslog(LOG_ERR, "poll: %m");
- die(1);
+ if (poll(pollfds, n_pollfds, t) < 0 && errno != EINTR)
+ fatal("poll: %m");
+}
+
+/*
+ * add_fd - add an fd to the set that wait_input waits for.
+ */
+void add_fd(int fd)
+{
+ int n;
+
+ for (n = 0; n < n_pollfds; ++n)
+ if (pollfds[n].fd == fd)
+ return;
+ if (n_pollfds < MAX_POLLFDS) {
+ pollfds[n_pollfds].fd = fd;
+ pollfds[n_pollfds].events = POLLIN | POLLPRI | POLLHUP;
+ ++n_pollfds;
+ } else
+ error("Too many inputs!");
+}
+
+/*
+ * remove_fd - remove an fd from the set that wait_input waits for.
+ */
+void remove_fd(int fd)
+{
+ int n;
+
+ for (n = 0; n < n_pollfds; ++n) {
+ if (pollfds[n].fd == fd) {
+ while (++n < n_pollfds)
+ pollfds[n-1] = pollfds[n];
+ --n_pollfds;
+ break;
+ }
}
}
+#if 0
/*
* wait_loop_output - wait until there is data available on the
* loopback, for the length of time specified by *timo (indefinite
int n;
n = select(0, NULL, NULL, NULL, timo);
- if (n < 0 && errno != EINTR) {
- syslog(LOG_ERR, "select: %m");
- die(1);
- }
+ if (n < 0 && errno != EINTR)
+ fatal("select: %m");
}
-
+#endif
/*
* read_packet - get a PPP packet from the serial device.
if (len < 0) {
if (errno = EAGAIN || errno == EWOULDBLOCK || errno == EINTR)
return -1;
- syslog(LOG_ERR, "Error reading packet: %m");
- die(1);
+ fatal("Error reading packet: %m");
}
if (ctrl.len <= 0)
* Got a M_PROTO or M_PCPROTO message. Huh?
*/
if (debug)
- syslog(LOG_DEBUG, "got ctrl msg len=%d", ctrl.len);
+ dbglog("got ctrl msg len=%d", ctrl.len);
}
}
if (strioctl(pppfd, PPPIO_MTU, &mtu, sizeof(mtu), 0) < 0) {
if (hungup && errno == ENXIO)
return;
- syslog(LOG_ERR, "Couldn't set MTU: %m");
+ error("Couldn't set MTU: %m");
}
if (strioctl(pppfd, PPPIO_XACCM, &asyncmap, sizeof(asyncmap), 0) < 0) {
- syslog(LOG_ERR, "Couldn't set transmit ACCM: %m");
+ error("Couldn't set transmit ACCM: %m");
}
cf[0] = (pcomp? COMP_PROT: 0) + (accomp? COMP_AC: 0);
cf[1] = COMP_PROT | COMP_AC;
if (strioctl(pppfd, PPPIO_CFLAGS, cf, sizeof(cf), sizeof(int)) < 0) {
- syslog(LOG_ERR, "Couldn't set prot/AC compression: %m");
+ error("Couldn't set prot/AC compression: %m");
}
}
{
if (strioctl(pppfd, PPPIO_XACCM, accm, sizeof(ext_accm), 0) < 0) {
if (!hungup || errno != ENXIO)
- syslog(LOG_WARNING, "Couldn't set extended ACCM: %m");
+ warn("Couldn't set extended ACCM: %m");
}
}
if (strioctl(pppfd, PPPIO_MRU, &mru, sizeof(mru), 0) < 0) {
if (hungup && errno == ENXIO)
return;
- syslog(LOG_ERR, "Couldn't set MRU: %m");
+ error("Couldn't set MRU: %m");
}
if (strioctl(pppfd, PPPIO_RACCM, &asyncmap, sizeof(asyncmap), 0) < 0) {
- syslog(LOG_ERR, "Couldn't set receive ACCM: %m");
+ error("Couldn't set receive ACCM: %m");
}
cf[0] = (pcomp? DECOMP_PROT: 0) + (accomp? DECOMP_AC: 0);
cf[1] = DECOMP_PROT | DECOMP_AC;
if (strioctl(pppfd, PPPIO_CFLAGS, cf, sizeof(cf), sizeof(int)) < 0) {
- syslog(LOG_ERR, "Couldn't set prot/AC decompression: %m");
+ error("Couldn't set prot/AC decompression: %m");
}
}
wait_time(&tval);
}
if (errno != 0)
- syslog(LOG_ERR, "hard failure trying to get memory for a compressor: %m");
+ error("hard failure trying to get memory for a compressor: %m");
return (errno == ENOSR)? 0: -1;
}
cf[1] = CCP_ISOPEN | CCP_ISUP | CCP_ERROR | CCP_FATALERROR;
if (strioctl(pppfd, PPPIO_CFLAGS, cf, sizeof(cf), sizeof(int)) < 0) {
if (!hungup || errno != ENXIO)
- syslog(LOG_ERR, "Couldn't set kernel CCP state: %m");
+ error("Couldn't set kernel CCP state: %m");
}
}
cf[0] = cf[1] = 0;
if (strioctl(pppfd, PPPIO_CFLAGS, cf, sizeof(cf), sizeof(int)) < 0) {
if (errno != ENXIO && errno != EINVAL)
- syslog(LOG_ERR, "Couldn't get compression flags: %m");
+ error("Couldn't get compression flags: %m");
return 0;
}
return cf[0] & CCP_FATALERROR;
maxcid[0] = xcidcomp;
maxcid[1] = 15; /* XXX should be rmaxcid */
if (strioctl(pppfd, PPPIO_VJINIT, maxcid, sizeof(maxcid), 0) < 0) {
- syslog(LOG_ERR, "Couldn't initialize VJ compression: %m");
+ error("Couldn't initialize VJ compression: %m");
}
}
cf[1] = COMP_VJC + DECOMP_VJC + COMP_VJCCID + DECOMP_VJCCID;
if (strioctl(pppfd, PPPIO_CFLAGS, cf, sizeof(cf), sizeof(int)) < 0) {
if (vjcomp)
- syslog(LOG_ERR, "Couldn't enable VJ compression: %m");
+ error("Couldn't enable VJ compression: %m");
}
return 1;
strlcpy(ifr.ifr_name, sizeof(ifr.ifr_name), ifname);
if (ioctl(sockfd, SIOCGIFFLAGS, &ifr) < 0) {
- syslog(LOG_ERR, "Couldn't mark interface up (get): %m");
+ error("Couldn't mark interface up (get): %m");
return 0;
}
ifr.ifr_flags |= IFF_UP;
if (ioctl(sockfd, SIOCSIFFLAGS, &ifr) < 0) {
- syslog(LOG_ERR, "Couldn't mark interface up (set): %m");
+ error("Couldn't mark interface up (set): %m");
return 0;
}
if_is_up = 1;
strlcpy(ifr.ifr_name, sizeof(ifr.ifr_name), ifname);
if (ioctl(sockfd, SIOCGIFFLAGS, &ifr) < 0) {
- syslog(LOG_ERR, "Couldn't mark interface down (get): %m");
+ error("Couldn't mark interface down (get): %m");
return 0;
}
if ((ifr.ifr_flags & IFF_UP) != 0) {
ifr.ifr_flags &= ~IFF_UP;
if (ioctl(sockfd, SIOCSIFFLAGS, &ifr) < 0) {
- syslog(LOG_ERR, "Couldn't mark interface down (set): %m");
+ error("Couldn't mark interface down (set): %m");
return 0;
}
}
npi[0] = proto;
npi[1] = (int) mode;
if (strioctl(pppfd, PPPIO_NPMODE, npi, 2 * sizeof(int), 0) < 0) {
- syslog(LOG_ERR, "ioctl(set NP %d mode to %d): %m", proto, mode);
+ error("ioctl(set NP %d mode to %d): %m", proto, mode);
return 0;
}
return 1;
((struct sockaddr_in *) &ifr.ifr_addr)->sin_addr.s_addr = o;
if ((ioctl(sockfd, (int)SIOCDIFADDR, (caddr_t) &ifr) < 0)
&& errno != EADDRNOTAVAIL) {
- syslog(LOG_ERR, "ioctl(SIOCDIFADDR): %m");
+ error("ioctl(SIOCDIFADDR): %m");
ret = 0;
}
if (m != 0) {
((struct sockaddr_in *)&addreq.ifra_mask)->sin_addr.s_addr = m;
addreq.ifra_mask.sa_len = sizeof (struct sockaddr);
- syslog(LOG_INFO, "Setting interface mask to %s\n", ip_ntoa(m));
+ info("Setting interface mask to %s\n", ip_ntoa(m));
}
/* install new src/dst and (possibly) netmask
*/
if (ioctl(sockfd, SIOCPIFADDR, &addreq) < 0) {
- syslog(LOG_ERR, "ioctl(SIOCPIFADDR): %m");
+ error("ioctl(SIOCPIFADDR): %m");
ret = 0;
}
ifr.ifr_metric = link_mtu;
if (ioctl(sockfd, SIOCSIPMTU, &ifr) < 0) {
- syslog(LOG_ERR, "Couldn't set IP MTU: %m");
+ error("Couldn't set IP MTU: %m");
ret = 0;
}
SET_SA_FAMILY(ifr.ifr_addr, AF_INET);
((struct sockaddr_in *) &ifr.ifr_addr)->sin_addr.s_addr = o;
if (ioctl(sockfd, (int)SIOCDIFADDR, (caddr_t) &ifr) < 0) {
- syslog(LOG_ERR, "ioctl(SIOCDIFADDR): %m");
+ error("ioctl(SIOCDIFADDR): %m");
return 0;
}
return 1;
((struct sockaddr_in *) &rt.rt_gateway)->sin_addr.s_addr = g;
rt.rt_flags = RTF_GATEWAY;
if (ioctl(sockfd, (int)SIOCADDRT, &rt) < 0) {
- syslog(LOG_ERR, "default route ioctl(SIOCADDRT): %m");
+ error("default route ioctl(SIOCADDRT): %m");
return 0;
}
default_route_gateway = g;
((struct sockaddr_in *) &rt.rt_gateway)->sin_addr.s_addr = g;
rt.rt_flags = RTF_GATEWAY;
if (ioctl(sockfd, (int)SIOCDELRT, &rt) < 0) {
- syslog(LOG_ERR, "default route ioctl(SIOCDELRT): %m");
+ error("default route ioctl(SIOCDELRT): %m");
return 0;
}
default_route_gateway = 0;
* as our local address.
*/
if (!get_ether_addr(hisaddr, &arpreq.arp_ha)) {
- syslog(LOG_WARNING, "Cannot determine ethernet address for proxy ARP");
+ warn("Cannot determine ethernet address for proxy ARP");
return 0;
}
((struct sockaddr_in *) &arpreq.arp_pa)->sin_addr.s_addr = hisaddr;
arpreq.arp_flags = ATF_PERM | ATF_PUBL;
if (ioctl(sockfd, (int)SIOCSARP, (caddr_t)&arpreq) < 0) {
- syslog(LOG_ERR, "ioctl(SIOCSARP): %m");
+ error("ioctl(SIOCSARP): %m");
return 0;
}
SET_SA_FAMILY(arpreq.arp_pa, AF_INET);
((struct sockaddr_in *) &arpreq.arp_pa)->sin_addr.s_addr = hisaddr;
if (ioctl(sockfd, (int)SIOCDARP, (caddr_t)&arpreq) < 0) {
- syslog(LOG_ERR, "ioctl(SIOCDARP): %m");
+ error("ioctl(SIOCDARP): %m");
return 0;
}
proxy_arp_addr = 0;
ifc.ifc_len = sizeof(ifs);
ifc.ifc_req = ifs;
if (ioctl(sockfd, SIOCGIFCONF, &ifc) < 0) {
- syslog(LOG_ERR, "ioctl(SIOCGIFCONF): %m");
+ error("ioctl(SIOCGIFCONF): %m");
return 0;
}
if (ifr >= ifend)
return 0;
- syslog(LOG_INFO, "found interface %s for proxy arp", ifr->ifr_name);
+ info("found interface %s for proxy arp", ifr->ifr_name);
strlcpy(ifdevreq.ifr_name, sizeof(ifdevreq.ifr_name), ifr->ifr_name);
if (ifc.ifc_req == 0)
return mask;
if (ioctl(sockfd, SIOCGIFCONF, &ifc) < 0) {
- syslog(LOG_WARNING, "Couldn't get system interface list: %m");
+ warn("Couldn't get system interface list: %m");
return mask;
}
ifend = (struct ifreq *) (ifc.ifc_buf + ifc.ifc_len);
if (ioctl(fd, I_STR, &str) == -1)
return -1;
if (str.ic_len != olen)
- syslog(LOG_DEBUG, "strioctl: expected %d bytes, got %d for cmd %x\n",
+ dbglog("strioctl: expected %d bytes, got %d for cmd %x\n",
olen, str.ic_len, cmd);
return 0;
}
n = read(fd, &pid, sizeof(pid));
#endif
if (n <= 0) {
- syslog(LOG_ERR, "Can't read pid from lock file %s", lock_file);
+ error("Can't read pid from lock file %s", lock_file);
close(fd);
} else {
if (kill(pid, 0) == -1 && errno == ESRCH) {
/* pid no longer exists - remove the lock file */
if (unlink(lock_file) == 0) {
close(fd);
- syslog(LOG_NOTICE, "Removed stale lock on %s (pid %d)",
+ notice("Removed stale lock on %s (pid %d)",
dev, pid);
continue;
} else
- syslog(LOG_WARNING, "Couldn't remove stale lock on %s",
+ warn("Couldn't remove stale lock on %s",
dev);
} else
- syslog(LOG_NOTICE, "Device %s is locked by pid %d",
+ notice("Device %s is locked by pid %d",
dev, pid);
}
close(fd);
} else
- syslog(LOG_ERR, "Can't create lock file %s: %m", lock_file);
+ error("Can't create lock file %s: %m", lock_file);
free(lock_file);
lock_file = NULL;
return -1;
}
#ifdef PIDSTRING
- sprintf(hdb_lock_buffer, "%10d\n", getpid());
+ slprintf(hdb_lock_buffer, sizeof(hdb_lock_buffer), "%10d\n", getpid());
write(fd, hdb_lock_buffer, 11);
#else
pid = getpid();
*/
#ifndef lint
-static char rcsid[] = "$Id: sys-sunos4.c,v 1.13 1999/03/12 06:07:23 paulus Exp $";
+static char rcsid[] = "$Id: sys-sunos4.c,v 1.14 1999/03/16 02:57:07 paulus Exp $";
#endif
#include <stdio.h>
#include <sys/sockio.h>
#include <sys/stream.h>
#include <sys/stropts.h>
-#include <sys/syslog.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/poll.h>
extern u_char inpacket_buf[]; /* borrowed from main.c */
+#define MAX_POLLFDS 32
+static struct pollfd pollfds[MAX_POLLFDS];
+static int n_pollfds;
+
static int link_mtu, link_mru;
#define NMODULES 32
int x;
/* Get an internet socket for doing socket ioctl's on. */
- if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
- syslog(LOG_ERR, "Couldn't create IP socket: %m");
- die(1);
- }
+ if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
+ fatal("Couldn't create IP socket: %m");
/*
* We may want to send a SIGHUP to the session leader associated
* Open the ppp device.
*/
pppfd = open("/dev/ppp", O_RDWR | O_NONBLOCK, 0);
- if (pppfd < 0) {
- syslog(LOG_ERR, "Can't open /dev/ppp: %m");
- die(1);
- }
+ if (pppfd < 0)
+ fatal("Can't open /dev/ppp: %m");
if (kdebugflag) {
x = PPPDBG_LOG + PPPDBG_DRIVER;
strioctl(pppfd, PPPIO_DEBUG, &x, sizeof(int), 0);
}
/* Assign a new PPA and get its unit number. */
- if (strioctl(pppfd, PPPIO_NEWPPA, &ifunit, 0, sizeof(int)) < 0) {
- syslog(LOG_ERR, "Can't create new PPP interface: %m");
- die(1);
- }
+ if (strioctl(pppfd, PPPIO_NEWPPA, &ifunit, 0, sizeof(int)) < 0)
+ fatal("Can't create new PPP interface: %m");
/*
* Open the ppp device again and push the if_ppp module on it.
*/
iffd = open("/dev/ppp", O_RDWR, 0);
- if (iffd < 0) {
- syslog(LOG_ERR, "Can't open /dev/ppp (2): %m");
- die(1);
- }
+ if (iffd < 0)
+ fatal("Can't open /dev/ppp (2): %m");
if (kdebugflag) {
x = PPPDBG_LOG + PPPDBG_DRIVER;
strioctl(iffd, PPPIO_DEBUG, &x, sizeof(int), 0);
}
- if (strioctl(iffd, PPPIO_ATTACH, &ifunit, sizeof(int), 0) < 0) {
- syslog(LOG_ERR, "Couldn't attach ppp interface to device: %m");
- die(1);
- }
- if (ioctl(iffd, I_PUSH, "if_ppp") < 0) {
- syslog(LOG_ERR, "Can't push ppp interface module: %m");
- die(1);
- }
+ if (strioctl(iffd, PPPIO_ATTACH, &ifunit, sizeof(int), 0) < 0)
+ fatal("Couldn't attach ppp interface to device: %m");
+ if (ioctl(iffd, I_PUSH, "if_ppp") < 0)
+ fatal("Can't push ppp interface module: %m");
if (kdebugflag) {
x = PPPDBG_LOG + PPPDBG_IF;
strioctl(iffd, PPPIO_DEBUG, &x, sizeof(int), 0);
}
- if (strioctl(iffd, PPPIO_NEWPPA, &ifunit, sizeof(int), 0) < 0) {
- syslog(LOG_ERR, "Couldn't create ppp interface unit: %m");
- die(1);
- }
+ if (strioctl(iffd, PPPIO_NEWPPA, &ifunit, sizeof(int), 0) < 0)
+ fatal("Couldn't create ppp interface unit: %m");
x = PPP_IP;
- if (strioctl(iffd, PPPIO_BIND, &x, sizeof(int), 0) < 0) {
- syslog(LOG_ERR, "Couldn't bind ppp interface to IP SAP: %m");
- die(1);
- }
+ if (strioctl(iffd, PPPIO_BIND, &x, sizeof(int), 0) < 0)
+ fatal("Couldn't bind ppp interface to IP SAP: %m");
+
+ n_pollfds = 0;
}
/*
tty_nmodules = i;
/* Push the async hdlc module and the compressor module. */
- if (ioctl(fd, I_PUSH, "ppp_ahdl") < 0) {
- syslog(LOG_ERR, "Couldn't push PPP Async HDLC module: %m");
- die(1);
- }
- if (ioctl(fd, I_PUSH, "ppp_comp") < 0) {
- syslog(LOG_ERR, "Couldn't push PPP compression module: %m");
-/* die(1); */
- }
+ if (ioctl(fd, I_PUSH, "ppp_ahdl") < 0)
+ fatal("Couldn't push PPP Async HDLC module: %m");
+ if (ioctl(fd, I_PUSH, "ppp_comp") < 0)
+ error("Couldn't push PPP compression module: %m");
/* Link the serial port under the PPP multiplexor. */
- if ((fdmuxid = ioctl(pppfd, I_LINK, fd)) < 0) {
- syslog(LOG_ERR, "Can't link tty to PPP mux: %m");
- die(1);
- }
+ if ((fdmuxid = ioctl(pppfd, I_LINK, fd)) < 0)
+ fatal("Can't link tty to PPP mux: %m");
}
/*
if (fdmuxid >= 0) {
if (ioctl(pppfd, I_UNLINK, fdmuxid) < 0) {
if (!hungup)
- syslog(LOG_ERR, "Can't unlink tty from PPP mux: %m");
+ error("Can't unlink tty from PPP mux: %m");
}
fdmuxid = -1;
;
for (i = tty_nmodules - 1; i >= 0; --i)
if (ioctl(fd, I_PUSH, tty_modules[i]) < 0)
- syslog(LOG_ERR, "Couldn't restore tty module %s: %m",
+ error("Couldn't restore tty module %s: %m",
tty_modules[i]);
}
if (hungup && default_device && parent_pid > 0) {
break;
}
if (s != NULL) {
- syslog(LOG_WARNING, "Serial link is not 8-bit clean:");
- syslog(LOG_WARNING, "All received characters had %s", s);
+ warn("Serial link is not 8-bit clean:");
+ warn("All received characters had %s", s);
}
}
for (speedp = speeds; speedp->speed_int; speedp++)
if (bps == speedp->speed_int)
return speedp->speed_val;
- syslog(LOG_WARNING, "speed %d not supported", bps);
+ warn("speed %d not supported", bps);
return 0;
}
int speed;
struct termios tios;
- if (tcgetattr(fd, &tios) < 0) {
- syslog(LOG_ERR, "tcgetattr: %m");
- die(1);
- }
+ if (tcgetattr(fd, &tios) < 0)
+ fatal("tcgetattr: %m");
if (!restore_term) {
inittermios = tios;
* We can't proceed if the serial port speed is 0,
* since that implies that the serial port is disabled.
*/
- if (speed == B0) {
- syslog(LOG_ERR, "Baud rate for %s is 0; need explicit baud rate",
- devnam);
- die(1);
- }
+ if (speed == B0)
+ fatal("Baud rate for %s is 0; need explicit baud rate", devnam);
}
- if (tcsetattr(fd, TCSAFLUSH, &tios) < 0) {
- syslog(LOG_ERR, "tcsetattr: %m");
- die(1);
- }
+ if (tcsetattr(fd, TCSAFLUSH, &tios) < 0)
+ fatal("tcsetattr: %m");
baud_rate = inspeed = baud_rate_of(speed);
restore_term = 1;
}
if (tcsetattr(fd, TCSAFLUSH, &inittermios) < 0)
if (!hungup && errno != ENXIO)
- syslog(LOG_WARNING, "tcsetattr: %m");
+ warn("tcsetattr: %m");
ioctl(fd, TIOCSWINSZ, &wsinfo);
restore_term = 0;
}
struct pollfd pfd;
if (debug)
- log_packet(p, len, "sent ", LOG_DEBUG);
+ dbglog("sent %P", p, len);
data.len = len;
data.buf = (caddr_t) p;
while (putmsg(pppfd, NULL, &data, 0) < 0) {
if (--retries < 0 || (errno != EWOULDBLOCK && errno != EAGAIN)) {
if (errno != ENXIO)
- syslog(LOG_ERR, "Couldn't send packet: %m");
+ error("Couldn't send packet: %m");
break;
}
pfd.fd = pppfd;
/*
- * wait_input - wait until there is data available on fd,
+ * wait_input - wait until there is data available,
* for the length of time specified by *timo (indefinite
* if timo is NULL).
*/
struct timeval *timo;
{
int t;
- struct pollfd pfd;
t = timo == NULL? -1: timo->tv_sec * 1000 + timo->tv_usec / 1000;
- pfd.fd = pppfd;
- pfd.events = POLLIN | POLLPRI | POLLHUP;
- if (poll(&pfd, 1, t) < 0 && errno != EINTR) {
- syslog(LOG_ERR, "poll: %m");
- die(1);
- }
+ if (poll(pollfds, n_pollfds, t) < 0 && errno != EINTR)
+ fatal("poll: %m");
}
/*
int n;
n = select(0, NULL, NULL, NULL, timo);
- if (n < 0 && errno != EINTR) {
- syslog(LOG_ERR, "select: %m");
- die(1);
- }
+ if (n < 0 && errno != EINTR)
+ fatal("select: %m");
}
if (len < 0) {
if (errno = EAGAIN || errno == EINTR)
return -1;
- syslog(LOG_ERR, "Error reading packet: %m");
- die(1);
+ fatal("Error reading packet: %m");
}
if (ctrl.len <= 0)
* Got a M_PROTO or M_PCPROTO message. Huh?
*/
if (debug)
- syslog(LOG_DEBUG, "got ctrl msg len=%d", ctrl.len);
+ dbglog("got ctrl msg len=%d", ctrl.len);
}
}
if (strioctl(pppfd, PPPIO_MTU, &mtu, sizeof(mtu), 0) < 0) {
if (hungup && errno == ENXIO)
return;
- syslog(LOG_ERR, "Couldn't set MTU: %m");
+ error("Couldn't set MTU: %m");
}
if (strioctl(pppfd, PPPIO_XACCM, &asyncmap, sizeof(asyncmap), 0) < 0) {
- syslog(LOG_ERR, "Couldn't set transmit ACCM: %m");
+ error("Couldn't set transmit ACCM: %m");
}
cf[0] = (pcomp? COMP_PROT: 0) + (accomp? COMP_AC: 0);
cf[1] = COMP_PROT | COMP_AC;
if (strioctl(pppfd, PPPIO_CFLAGS, cf, sizeof(cf), sizeof(int)) < 0) {
- syslog(LOG_ERR, "Couldn't set prot/AC compression: %m");
+ error("Couldn't set prot/AC compression: %m");
}
/* set mtu for ip as well */
strlcpy(ifr.ifr_name, sizeof(ifr.ifr_name), ifname);
ifr.ifr_metric = link_mtu;
if (ioctl(sockfd, SIOCSIFMTU, &ifr) < 0) {
- syslog(LOG_ERR, "Couldn't set IP MTU: %m");
+ error("Couldn't set IP MTU: %m");
}
}
{
if (strioctl(pppfd, PPPIO_XACCM, accm, sizeof(ext_accm), 0) < 0) {
if (!hungup || errno != ENXIO)
- syslog(LOG_WARNING, "Couldn't set extended ACCM: %m");
+ warn("Couldn't set extended ACCM: %m");
}
}
if (strioctl(pppfd, PPPIO_MRU, &mru, sizeof(mru), 0) < 0) {
if (hungup && errno == ENXIO)
return;
- syslog(LOG_ERR, "Couldn't set MRU: %m");
+ error("Couldn't set MRU: %m");
}
if (strioctl(pppfd, PPPIO_RACCM, &asyncmap, sizeof(asyncmap), 0) < 0) {
- syslog(LOG_ERR, "Couldn't set receive ACCM: %m");
+ error("Couldn't set receive ACCM: %m");
}
cf[0] = (pcomp? DECOMP_PROT: 0) + (accomp? DECOMP_AC: 0);
cf[1] = DECOMP_PROT | DECOMP_AC;
if (strioctl(pppfd, PPPIO_CFLAGS, cf, sizeof(cf), sizeof(int)) < 0) {
- syslog(LOG_ERR, "Couldn't set prot/AC decompression: %m");
+ error("Couldn't set prot/AC decompression: %m");
}
}
cf[1] = CCP_ISOPEN | CCP_ISUP | CCP_ERROR | CCP_FATALERROR;
if (strioctl(pppfd, PPPIO_CFLAGS, cf, sizeof(cf), sizeof(int)) < 0) {
if (!hungup || errno != ENXIO)
- syslog(LOG_ERR, "Couldn't set kernel CCP state: %m");
+ error("Couldn't set kernel CCP state: %m");
}
}
cf[0] = cf[1] = 0;
if (strioctl(pppfd, PPPIO_CFLAGS, cf, sizeof(cf), sizeof(int)) < 0) {
if (errno != ENXIO && errno != EINVAL)
- syslog(LOG_ERR, "Couldn't get compression flags: %m");
+ error("Couldn't get compression flags: %m");
return 0;
}
return cf[0] & CCP_FATALERROR;
maxcid[0] = xcidcomp;
maxcid[1] = 15; /* XXX should be rmaxcid */
if (strioctl(pppfd, PPPIO_VJINIT, maxcid, sizeof(maxcid), 0) < 0) {
- syslog(LOG_ERR, "Couldn't initialize VJ compression: %m");
+ error("Couldn't initialize VJ compression: %m");
}
}
cf[1] = COMP_VJC + DECOMP_VJC + COMP_VJCCID + DECOMP_VJCCID;
if (strioctl(pppfd, PPPIO_CFLAGS, cf, sizeof(cf), sizeof(int)) < 0) {
if (vjcomp)
- syslog(LOG_ERR, "Couldn't enable VJ compression: %m");
+ error("Couldn't enable VJ compression: %m");
}
return 1;
strlcpy(ifr.ifr_name, sizeof(ifr.ifr_name), ifname);
if (ioctl(sockfd, SIOCGIFFLAGS, &ifr) < 0) {
- syslog(LOG_ERR, "Couldn't mark interface up (get): %m");
+ error("Couldn't mark interface up (get): %m");
return 0;
}
ifr.ifr_flags |= IFF_UP;
if (ioctl(sockfd, SIOCSIFFLAGS, &ifr) < 0) {
- syslog(LOG_ERR, "Couldn't mark interface up (set): %m");
+ error("Couldn't mark interface up (set): %m");
return 0;
}
if_is_up = 1;
strlcpy(ifr.ifr_name, sizeof(ifr.ifr_name), ifname);
if (ioctl(sockfd, SIOCGIFFLAGS, &ifr) < 0) {
- syslog(LOG_ERR, "Couldn't mark interface down (get): %m");
+ error("Couldn't mark interface down (get): %m");
return 0;
}
if ((ifr.ifr_flags & IFF_UP) != 0) {
ifr.ifr_flags &= ~IFF_UP;
if (ioctl(sockfd, SIOCSIFFLAGS, &ifr) < 0) {
- syslog(LOG_ERR, "Couldn't mark interface down (set): %m");
+ error("Couldn't mark interface down (set): %m");
return 0;
}
}
npi[0] = proto;
npi[1] = (int) mode;
if (strioctl(pppfd, PPPIO_NPMODE, npi, 2 * sizeof(int), 0) < 0) {
- syslog(LOG_ERR, "ioctl(set NP %d mode to %d): %m", proto, mode);
+ error("ioctl(set NP %d mode to %d): %m", proto, mode);
return 0;
}
return 1;
ifr.ifr_addr.sa_family = AF_INET;
INET_ADDR(ifr.ifr_addr) = m;
if (ioctl(sockfd, SIOCSIFNETMASK, &ifr) < 0) {
- syslog(LOG_ERR, "Couldn't set IP netmask: %m");
+ error("Couldn't set IP netmask: %m");
}
ifr.ifr_addr.sa_family = AF_INET;
INET_ADDR(ifr.ifr_addr) = o;
if (ioctl(sockfd, SIOCSIFADDR, &ifr) < 0) {
- syslog(LOG_ERR, "Couldn't set local IP address: %m");
+ error("Couldn't set local IP address: %m");
}
ifr.ifr_dstaddr.sa_family = AF_INET;
INET_ADDR(ifr.ifr_dstaddr) = h;
if (ioctl(sockfd, SIOCSIFDSTADDR, &ifr) < 0) {
- syslog(LOG_ERR, "Couldn't set remote IP address: %m");
+ error("Couldn't set remote IP address: %m");
}
#if 0 /* now done in ppp_send_config */
ifr.ifr_metric = link_mtu;
if (ioctl(sockfd, SIOCSIFMTU, &ifr) < 0) {
- syslog(LOG_ERR, "Couldn't set IP MTU: %m");
+ error("Couldn't set IP MTU: %m");
}
#endif
ifaddrs[0] = o;
INET_ADDR(rt.rt_gateway) = o;
rt.rt_flags = RTF_HOST;
if (ioctl(sockfd, SIOCDELRT, &rt) < 0)
- syslog(LOG_ERR, "Couldn't delete route through interface: %m");
+ error("Couldn't delete route through interface: %m");
ifaddrs[0] = 0;
return 1;
}
rt.rt_flags = RTF_GATEWAY;
if (ioctl(sockfd, SIOCADDRT, &rt) < 0) {
- syslog(LOG_ERR, "Can't add default route: %m");
+ error("Can't add default route: %m");
return 0;
}
rt.rt_flags = RTF_GATEWAY;
if (ioctl(sockfd, SIOCDELRT, &rt) < 0) {
- syslog(LOG_ERR, "Can't delete default route: %m");
+ error("Can't delete default route: %m");
return 0;
}
INET_ADDR(arpreq.arp_pa) = hisaddr;
arpreq.arp_flags = ATF_PERM | ATF_PUBL;
if (ioctl(sockfd, SIOCSARP, (caddr_t) &arpreq) < 0) {
- syslog(LOG_ERR, "Couldn't set proxy ARP entry: %m");
+ error("Couldn't set proxy ARP entry: %m");
return 0;
}
arpreq.arp_pa.sa_family = AF_INET;
INET_ADDR(arpreq.arp_pa) = hisaddr;
if (ioctl(sockfd, SIOCDARP, (caddr_t)&arpreq) < 0) {
- syslog(LOG_ERR, "Couldn't delete proxy ARP entry: %m");
+ error("Couldn't delete proxy ARP entry: %m");
return 0;
}
ifc.ifc_len = sizeof(ifs);
ifc.ifc_req = ifs;
if (ioctl(sockfd, SIOCGIFCONF, &ifc) < 0) {
- syslog(LOG_ERR, "ioctl(SIOCGIFCONF): %m");
+ error("ioctl(SIOCGIFCONF): %m");
return 0;
}
if (ifr >= ifend)
return 0;
- syslog(LOG_INFO, "found interface %s for proxy arp", ifr->ifr_name);
+ info("found interface %s for proxy arp", ifr->ifr_name);
/*
* Grab the physical address for this interface.
*/
if ((nit_fd = open("/dev/nit", O_RDONLY)) < 0) {
- syslog(LOG_ERR, "Couldn't open /dev/nit: %m");
+ error("Couldn't open /dev/nit: %m");
return 0;
}
strlcpy(ifreq.ifr_name, sizeof(ifreq.ifr_name), ifr->ifr_name);
if (ioctl(nit_fd, NIOCBIND, &ifreq) < 0
|| ioctl(nit_fd, SIOCGIFADDR, &ifreq) < 0) {
- syslog(LOG_ERR, "Couldn't get hardware address for %s: %m",
+ error("Couldn't get hardware address for %s: %m",
ifreq.ifr_name);
close(nit_fd);
return 0;
if (ifc.ifc_req == 0)
return mask;
if (ioctl(sockfd, SIOCGIFCONF, &ifc) < 0) {
- syslog(LOG_WARNING, "Couldn't get system interface list: %m");
+ warn("Couldn't get system interface list: %m");
return mask;
}
ifend = (struct ifreq *) (ifc.ifc_buf + ifc.ifc_len);
if (ioctl(fd, I_STR, &str) == -1)
return -1;
if (str.ic_len != olen)
- syslog(LOG_DEBUG, "strioctl: expected %d bytes, got %d for cmd %x\n",
+ dbglog("strioctl: expected %d bytes, got %d for cmd %x\n",
olen, str.ic_len, cmd);
return 0;
}
n = read(fd, &pid, sizeof(pid));
#endif
if (n <= 0) {
- syslog(LOG_ERR, "Can't read pid from lock file %s", lock_file);
+ error("Can't read pid from lock file %s", lock_file);
close(fd);
} else {
if (kill(pid, 0) == -1 && errno == ESRCH) {
/* pid no longer exists - remove the lock file */
if (unlink(lock_file) == 0) {
close(fd);
- syslog(LOG_NOTICE, "Removed stale lock on %s (pid %d)",
+ notice("Removed stale lock on %s (pid %d)",
dev, pid);
continue;
} else
- syslog(LOG_WARNING, "Couldn't remove stale lock on %s",
+ warn("Couldn't remove stale lock on %s",
dev);
} else
- syslog(LOG_NOTICE, "Device %s is locked by pid %d",
+ notice("Device %s is locked by pid %d",
dev, pid);
}
close(fd);
} else
- syslog(LOG_ERR, "Can't create lock file %s: %m", lock_file);
+ error("Can't create lock file %s: %m", lock_file);
free(lock_file);
lock_file = NULL;
return -1;
}
#ifdef PIDSTRING
- sprintf(hdb_lock_buffer, "%10d\n", getpid());
+ slprintf(hdb_lock_buffer, sizeof(hdb_lock_buffer), "%10d\n", getpid());
write(fd, hdb_lock_buffer, 11);
#else
pid = getpid();
if (n > 0 && n < sys_nerr)
return sys_errlist[n];
- sprintf(unknown, "Error %d", n);
+ slprintf(unknown, sizeof(unknown), "Error %d", n);
return unknown;
}
*/
#ifndef lint
-static char rcsid[] = "$Id: sys-svr4.c,v 1.24 1999/03/12 06:07:23 paulus Exp $";
+static char rcsid[] = "$Id: sys-svr4.c,v 1.25 1999/03/16 02:57:07 paulus Exp $";
#endif
#include <limits.h>
#include <sys/stropts.h>
#include <sys/socket.h>
#include <sys/sockio.h>
-#include <sys/syslog.h>
#include <sys/sysmacros.h>
#include <sys/systeminfo.h>
#include <sys/dlpi.h>
extern u_char inpacket_buf[]; /* borrowed from main.c */
+#define MAX_POLLFDS 32
+static struct pollfd pollfds[MAX_POLLFDS];
+static int n_pollfds;
+
static int link_mtu, link_mru;
#define NMODULES 32
#endif
ipfd = open("/dev/ip", O_RDWR, 0);
- if (ipfd < 0) {
- syslog(LOG_ERR, "Couldn't open IP device: %m");
- die(1);
- }
+ if (ipfd < 0)
+ fatal("Couldn't open IP device: %m");
if (default_device)
tty_sid = getsid((pid_t)0);
pppfd = open("/dev/ppp", O_RDWR | O_NONBLOCK, 0);
- if (pppfd < 0) {
- syslog(LOG_ERR, "Can't open /dev/ppp: %m");
- die(1);
- }
+ if (pppfd < 0)
+ fatal("Can't open /dev/ppp: %m");
if (kdebugflag & 1) {
x = PPPDBG_LOG + PPPDBG_DRIVER;
strioctl(pppfd, PPPIO_DEBUG, &x, sizeof(int), 0);
}
/* Assign a new PPA and get its unit number. */
- if (strioctl(pppfd, PPPIO_NEWPPA, &ifunit, 0, sizeof(int)) < 0) {
- syslog(LOG_ERR, "Can't create new PPP interface: %m");
- die(1);
- }
+ if (strioctl(pppfd, PPPIO_NEWPPA, &ifunit, 0, sizeof(int)) < 0)
+ fatal("Can't create new PPP interface: %m");
/*
* Open the ppp device again and link it under the ip multiplexor.
* I don't know any way to be certain they will be the same. :-(
*/
ifd = open("/dev/ppp", O_RDWR, 0);
- if (ifd < 0) {
- syslog(LOG_ERR, "Can't open /dev/ppp (2): %m");
- die(1);
- }
+ if (ifd < 0)
+ fatal("Can't open /dev/ppp (2): %m");
if (kdebugflag & 1) {
x = PPPDBG_LOG + PPPDBG_DRIVER;
strioctl(ifd, PPPIO_DEBUG, &x, sizeof(int), 0);
}
#ifdef sun
if (ioctl(ifd, I_PUSH, "ip") < 0) {
- syslog(LOG_ERR, "Can't push IP module: %m");
close(ifd);
- die(1);
+ fatal("Can't push IP module: %m");
}
#else
if (dlpi_attach(ifd, ifunit) < 0 ||
dlpi_get_reply(ifd, &reply.prim, DL_OK_ACK, sizeof(reply)) < 0) {
- syslog(LOG_ERR, "Can't attach to ppp%d: %m", ifunit);
close(ifd);
- die(1);
+ fatal("Can't attach to ppp%d: %m", ifunit);
}
#endif
ipmuxid = ioctl(ipfd, I_LINK, ifd);
close(ifd);
- if (ipmuxid < 0) {
- syslog(LOG_ERR, "Can't link PPP device to IP: %m");
- die(1);
- }
+ if (ipmuxid < 0)
+ fatal("Can't link PPP device to IP: %m");
#ifndef sun
/* Set the interface name for the link. */
- (void) sprintf (ifr.ifr_name, "ppp%d", ifunit);
+ slprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "ppp%d", ifunit);
ifr.ifr_metric = ipmuxid;
- if (strioctl(ipfd, SIOCSIFNAME, (char *)&ifr, sizeof ifr, 0) < 0) {
- syslog(LOG_ERR, "Can't set interface name %s: %m", ifr.ifr_name);
- die(1);
- }
+ if (strioctl(ipfd, SIOCSIFNAME, (char *)&ifr, sizeof ifr, 0) < 0)
+ fatal("Can't set interface name %s: %m", ifr.ifr_name);
#endif
+
+ n_pollfds = 0;
}
/*
tty_nmodules = i;
/* Push the async hdlc module and the compressor module. */
- if (ioctl(fd, I_PUSH, "ppp_ahdl") < 0) {
- syslog(LOG_ERR, "Couldn't push PPP Async HDLC module: %m");
- die(1);
- }
+ if (ioctl(fd, I_PUSH, "ppp_ahdl") < 0)
+ fatal("Couldn't push PPP Async HDLC module: %m");
if (kdebugflag & 4) {
i = PPPDBG_LOG + PPPDBG_AHDLC;
strioctl(pppfd, PPPIO_DEBUG, &i, sizeof(int), 0);
}
- if (ioctl(fd, I_PUSH, "ppp_comp") < 0) {
- syslog(LOG_ERR, "Couldn't push PPP compression module: %m");
-/* die(1); */
- }
+ if (ioctl(fd, I_PUSH, "ppp_comp") < 0)
+ error("Couldn't push PPP compression module: %m");
if (kdebugflag & 2) {
i = PPPDBG_LOG + PPPDBG_COMP;
strioctl(pppfd, PPPIO_DEBUG, &i, sizeof(int), 0);
}
/* Link the serial port under the PPP multiplexor. */
- if ((fdmuxid = ioctl(pppfd, I_LINK, fd)) < 0) {
- syslog(LOG_ERR, "Can't link tty to PPP mux: %m");
- die(1);
- }
+ if ((fdmuxid = ioctl(pppfd, I_LINK, fd)) < 0)
+ fatal("Can't link tty to PPP mux: %m");
}
/*
if (fdmuxid >= 0) {
if (ioctl(pppfd, I_UNLINK, fdmuxid) < 0) {
if (!hungup)
- syslog(LOG_ERR, "Can't unlink tty from PPP mux: %m");
+ error("Can't unlink tty from PPP mux: %m");
}
fdmuxid = -1;
;
for (i = tty_nmodules - 1; i >= 0; --i)
if (ioctl(fd, I_PUSH, tty_modules[i]) < 0)
- syslog(LOG_ERR, "Couldn't restore tty module %s: %m",
+ error("Couldn't restore tty module %s: %m",
tty_modules[i]);
}
if (hungup && default_device && tty_sid > 0) {
break;
}
if (s != NULL) {
- syslog(LOG_WARNING, "Serial link is not 8-bit clean:");
- syslog(LOG_WARNING, "All received characters had %s", s);
+ warn("Serial link is not 8-bit clean:");
+ warn("All received characters had %s", s);
}
}
for (speedp = speeds; speedp->speed_int; speedp++)
if (bps == speedp->speed_int)
return speedp->speed_val;
- syslog(LOG_WARNING, "speed %d not supported", bps);
+ warn("speed %d not supported", bps);
return 0;
}
struct termiox tiox;
#endif
- if (tcgetattr(fd, &tios) < 0) {
- syslog(LOG_ERR, "tcgetattr: %m");
- die(1);
- }
+ if (tcgetattr(fd, &tios) < 0)
+ fatal("tcgetattr: %m");
#ifndef CRTSCTS
termiox_ok = 1;
if (ioctl (fd, TCGETX, &tiox) < 0) {
termiox_ok = 0;
if (errno != ENOTTY)
- syslog (LOG_ERR, "TCGETX: %m");
+ error("TCGETX: %m");
}
#endif
tios.c_cflag &= ~CRTSCTS;
#else
if (crtscts != 0 && !termiox_ok) {
- syslog(LOG_ERR, "Can't set RTS/CTS flow control");
+ error("Can't set RTS/CTS flow control");
} else if (crtscts > 0) {
tiox.x_hflag |= RTSXOFF|CTSXON;
} else if (crtscts < 0) {
* We can't proceed if the serial port speed is 0,
* since that implies that the serial port is disabled.
*/
- if (speed == B0) {
- syslog(LOG_ERR, "Baud rate for %s is 0; need explicit baud rate",
- devnam);
- die(1);
- }
+ if (speed == B0)
+ fatal("Baud rate for %s is 0; need explicit baud rate", devnam);
}
- if (tcsetattr(fd, TCSAFLUSH, &tios) < 0) {
- syslog(LOG_ERR, "tcsetattr: %m");
- die(1);
- }
+ if (tcsetattr(fd, TCSAFLUSH, &tios) < 0)
+ fatal("tcsetattr: %m");
#ifndef CRTSCTS
if (termiox_ok && ioctl (fd, TCSETXF, &tiox) < 0){
- syslog (LOG_ERR, "TCSETXF: %m");
+ error("TCSETXF: %m");
}
#endif
}
if (tcsetattr(fd, TCSAFLUSH, &inittermios) < 0)
if (!hungup && errno != ENXIO)
- syslog(LOG_WARNING, "tcsetattr: %m");
+ warn("tcsetattr: %m");
#ifndef CRTSCTS
if (ioctl (fd, TCSETXF, &inittermiox) < 0){
if (!hungup && errno != ENXIO)
- syslog (LOG_ERR, "TCSETXF: %m");
+ error("TCSETXF: %m");
}
#endif
ioctl(fd, TIOCSWINSZ, &wsinfo);
struct pollfd pfd;
if (debug)
- log_packet(p, len, "sent ", LOG_DEBUG);
+ dbglog("sent %P", p, len);
data.len = len;
data.buf = (caddr_t) p;
while (putmsg(pppfd, NULL, &data, 0) < 0) {
if (--retries < 0 || (errno != EWOULDBLOCK && errno != EAGAIN)) {
if (errno != ENXIO)
- syslog(LOG_ERR, "Couldn't send packet: %m");
+ error("Couldn't send packet: %m");
break;
}
pfd.fd = pppfd;
/*
- * wait_input - wait until there is data available on fd,
+ * wait_input - wait until there is data available,
* for the length of time specified by *timo (indefinite
* if timo is NULL).
*/
struct timeval *timo;
{
int t;
- struct pollfd pfd;
t = timo == NULL? -1: timo->tv_sec * 1000 + timo->tv_usec / 1000;
- pfd.fd = pppfd;
- pfd.events = POLLIN | POLLPRI | POLLHUP;
- if (poll(&pfd, 1, t) < 0 && errno != EINTR) {
- syslog(LOG_ERR, "poll: %m");
- die(1);
+ if (poll(pollfds, n_pollfds, t) < 0 && errno != EINTR)
+ fatal("poll: %m");
+}
+
+/*
+ * add_fd - add an fd to the set that wait_input waits for.
+ */
+void add_fd(int fd)
+{
+ int n;
+
+ for (n = 0; n < n_pollfds; ++n)
+ if (pollfds[n].fd == fd)
+ return;
+ if (n_pollfds < MAX_POLLFDS) {
+ pollfds[n_pollfds].fd = fd;
+ pollfds[n_pollfds].events = POLLIN | POLLPRI | POLLHUP;
+ ++n_pollfds;
+ } else
+ error("Too many inputs!");
+}
+
+/*
+ * remove_fd - remove an fd from the set that wait_input waits for.
+ */
+void remove_fd(int fd)
+{
+ int n;
+
+ for (n = 0; n < n_pollfds; ++n) {
+ if (pollfds[n].fd == fd) {
+ while (++n < n_pollfds)
+ pollfds[n-1] = pollfds[n];
+ --n_pollfds;
+ break;
+ }
}
}
+#if 0
/*
* wait_loop_output - wait until there is data available on the
* loopback, for the length of time specified by *timo (indefinite
int n;
n = select(0, NULL, NULL, NULL, timo);
- if (n < 0 && errno != EINTR) {
- syslog(LOG_ERR, "select: %m");
- die(1);
- }
+ if (n < 0 && errno != EINTR)
+ fatal("select: %m");
}
+#endif
/*
if (len < 0) {
if (errno == EAGAIN || errno == EINTR)
return -1;
- syslog(LOG_ERR, "Error reading packet: %m");
- die(1);
+ fatal("Error reading packet: %m");
}
if (ctrl.len <= 0)
* as a DLPI primitive??
*/
if (debug)
- syslog(LOG_DEBUG, "got dlpi prim 0x%x, len=%d",
+ dbglog("got dlpi prim 0x%x, len=%d",
((union DL_primitives *)ctrlbuf)->dl_primitive, ctrl.len);
}
if (strioctl(pppfd, PPPIO_MTU, &mtu, sizeof(mtu), 0) < 0) {
if (hungup && errno == ENXIO)
return;
- syslog(LOG_ERR, "Couldn't set MTU: %m");
+ error("Couldn't set MTU: %m");
}
if (fdmuxid >= 0) {
/* can't set these if we don't have a stream attached below /dev/ppp */
if (strioctl(pppfd, PPPIO_XACCM, &asyncmap, sizeof(asyncmap), 0) < 0) {
- syslog(LOG_ERR, "Couldn't set transmit ACCM: %m");
+ error("Couldn't set transmit ACCM: %m");
}
cf[0] = (pcomp? COMP_PROT: 0) + (accomp? COMP_AC: 0);
cf[1] = COMP_PROT | COMP_AC;
if (strioctl(pppfd, PPPIO_CFLAGS, cf, sizeof(cf), sizeof(int)) < 0) {
- syslog(LOG_ERR, "Couldn't set prot/AC compression: %m");
+ error("Couldn't set prot/AC compression: %m");
}
}
strlcpy(ifr.ifr_name, sizeof(ifr.ifr_name), ifname);
ifr.ifr_metric = link_mtu;
if (ioctl(ipfd, SIOCSIFMTU, &ifr) < 0) {
- syslog(LOG_ERR, "Couldn't set IP MTU: %m");
+ error("Couldn't set IP MTU: %m");
}
}
if (fdmuxid >= 0
&& strioctl(pppfd, PPPIO_XACCM, accm, sizeof(ext_accm), 0) < 0) {
if (!hungup || errno != ENXIO)
- syslog(LOG_WARNING, "Couldn't set extended ACCM: %m");
+ warn("Couldn't set extended ACCM: %m");
}
}
if (strioctl(pppfd, PPPIO_MRU, &mru, sizeof(mru), 0) < 0) {
if (hungup && errno == ENXIO)
return;
- syslog(LOG_ERR, "Couldn't set MRU: %m");
+ error("Couldn't set MRU: %m");
}
if (fdmuxid >= 0) {
/* can't set these if we don't have a stream attached below /dev/ppp */
if (strioctl(pppfd, PPPIO_RACCM, &asyncmap, sizeof(asyncmap), 0) < 0) {
- syslog(LOG_ERR, "Couldn't set receive ACCM: %m");
+ error("Couldn't set receive ACCM: %m");
}
cf[0] = (pcomp? DECOMP_PROT: 0) + (accomp? DECOMP_AC: 0);
cf[1] = DECOMP_PROT | DECOMP_AC;
if (strioctl(pppfd, PPPIO_CFLAGS, cf, sizeof(cf), sizeof(int)) < 0) {
- syslog(LOG_ERR, "Couldn't set prot/AC decompression: %m");
+ error("Couldn't set prot/AC decompression: %m");
}
}
}
cf[1] = CCP_ISOPEN | CCP_ISUP | CCP_ERROR | CCP_FATALERROR;
if (strioctl(pppfd, PPPIO_CFLAGS, cf, sizeof(cf), sizeof(int)) < 0) {
if (!hungup || errno != ENXIO)
- syslog(LOG_ERR, "Couldn't set kernel CCP state: %m");
+ error("Couldn't set kernel CCP state: %m");
}
}
if (pass->bf_len > 0) {
if (strioctl(pppfd, PPPIO_PASSFILT, pass,
sizeof(struct bpf_program), 0) < 0) {
- syslog(LOG_ERR, "Couldn't set pass-filter in kernel: %m");
+ error("Couldn't set pass-filter in kernel: %m");
ret = 0;
}
}
if (active->bf_len > 0) {
if (strioctl(pppfd, PPPIO_ACTIVEFILT, active,
sizeof(struct bpf_program), 0) < 0) {
- syslog(LOG_ERR, "Couldn't set active-filter in kernel: %m");
+ error("Couldn't set active-filter in kernel: %m");
ret = 0;
}
}
cf[0] = cf[1] = 0;
if (strioctl(pppfd, PPPIO_CFLAGS, cf, sizeof(cf), sizeof(int)) < 0) {
if (errno != ENXIO && errno != EINVAL)
- syslog(LOG_ERR, "Couldn't get compression flags: %m");
+ error("Couldn't get compression flags: %m");
return 0;
}
return cf[0] & CCP_FATALERROR;
maxcid[0] = xcidcomp;
maxcid[1] = 15; /* XXX should be rmaxcid */
if (strioctl(pppfd, PPPIO_VJINIT, maxcid, sizeof(maxcid), 0) < 0) {
- syslog(LOG_ERR, "Couldn't initialize VJ compression: %m");
+ error("Couldn't initialize VJ compression: %m");
}
}
cf[1] = COMP_VJC + DECOMP_VJC + COMP_VJCCID + DECOMP_VJCCID;
if (strioctl(pppfd, PPPIO_CFLAGS, cf, sizeof(cf), sizeof(int)) < 0) {
if (vjcomp)
- syslog(LOG_ERR, "Couldn't enable VJ compression: %m");
+ error("Couldn't enable VJ compression: %m");
}
return 1;
strlcpy(ifr.ifr_name, sizeof(ifr.ifr_name), ifname);
if (ioctl(ipfd, SIOCGIFFLAGS, &ifr) < 0) {
- syslog(LOG_ERR, "Couldn't mark interface up (get): %m");
+ error("Couldn't mark interface up (get): %m");
return 0;
}
ifr.ifr_flags |= IFF_UP;
if (ioctl(ipfd, SIOCSIFFLAGS, &ifr) < 0) {
- syslog(LOG_ERR, "Couldn't mark interface up (set): %m");
+ error("Couldn't mark interface up (set): %m");
return 0;
}
if_is_up = 1;
return 1;
strlcpy(ifr.ifr_name, sizeof(ifr.ifr_name), ifname);
if (ioctl(ipfd, SIOCGIFFLAGS, &ifr) < 0) {
- syslog(LOG_ERR, "Couldn't mark interface down (get): %m");
+ error("Couldn't mark interface down (get): %m");
return 0;
}
ifr.ifr_flags &= ~IFF_UP;
if (ioctl(ipfd, SIOCSIFFLAGS, &ifr) < 0) {
- syslog(LOG_ERR, "Couldn't mark interface down (set): %m");
+ error("Couldn't mark interface down (set): %m");
return 0;
}
if_is_up = 0;
npi[0] = proto;
npi[1] = (int) mode;
if (strioctl(pppfd, PPPIO_NPMODE, &npi, 2 * sizeof(int), 0) < 0) {
- syslog(LOG_ERR, "ioctl(set NP %d mode to %d): %m", proto, mode);
+ error("ioctl(set NP %d mode to %d): %m", proto, mode);
return 0;
}
return 1;
ifr.ifr_addr.sa_family = AF_INET;
INET_ADDR(ifr.ifr_addr) = m;
if (ioctl(ipfd, SIOCSIFNETMASK, &ifr) < 0) {
- syslog(LOG_ERR, "Couldn't set IP netmask: %m");
+ error("Couldn't set IP netmask: %m");
ret = 0;
}
ifr.ifr_addr.sa_family = AF_INET;
INET_ADDR(ifr.ifr_addr) = o;
if (ioctl(ipfd, SIOCSIFADDR, &ifr) < 0) {
- syslog(LOG_ERR, "Couldn't set local IP address: %m");
+ error("Couldn't set local IP address: %m");
ret = 0;
}
&& (ifr.ifr_flags & IFF_POINTOPOINT) == 0) {
ifr.ifr_flags |= IFF_POINTOPOINT;
if (ioctl(ipfd, SIOCSIFFLAGS, &ifr) < 0) {
- syslog(LOG_ERR, "Couldn't mark interface pt-to-pt: %m");
+ error("Couldn't mark interface pt-to-pt: %m");
ret = 0;
}
}
ifr.ifr_dstaddr.sa_family = AF_INET;
INET_ADDR(ifr.ifr_dstaddr) = h;
if (ioctl(ipfd, SIOCSIFDSTADDR, &ifr) < 0) {
- syslog(LOG_ERR, "Couldn't set remote IP address: %m");
+ error("Couldn't set remote IP address: %m");
ret = 0;
}
#if 0 /* now done in ppp_send_config */
ifr.ifr_metric = link_mtu;
if (ioctl(ipfd, SIOCSIFMTU, &ifr) < 0) {
- syslog(LOG_ERR, "Couldn't set IP MTU: %m");
+ error("Couldn't set IP MTU: %m");
}
#endif
#if defined(__USLC__) /* was: #if 0 */
cifroute(unit, ouraddr, hisaddr);
if (ipmuxid >= 0) {
- syslog(LOG_NOTICE, "Removing ppp interface unit");
+ notice("Removing ppp interface unit");
if (ioctl(ipfd, I_UNLINK, ipmuxid) < 0) {
- syslog(LOG_ERR, "Can't remove ppp interface unit: %m");
+ error("Can't remove ppp interface unit: %m");
return 0;
}
ipmuxid = -1;
rt.rt_flags = RTF_GATEWAY;
if (ioctl(ipfd, SIOCADDRT, &rt) < 0) {
- syslog(LOG_ERR, "Can't add default route: %m");
+ error("Can't add default route: %m");
return 0;
}
rt.rt_flags = RTF_GATEWAY;
if (ioctl(ipfd, SIOCDELRT, &rt) < 0) {
- syslog(LOG_ERR, "Can't delete default route: %m");
+ error("Can't delete default route: %m");
return 0;
}
INET_ADDR(arpreq.arp_pa) = hisaddr;
arpreq.arp_flags = ATF_PERM | ATF_PUBL;
if (ioctl(ipfd, SIOCSARP, (caddr_t) &arpreq) < 0) {
- syslog(LOG_ERR, "Couldn't set proxy ARP entry: %m");
+ error("Couldn't set proxy ARP entry: %m");
return 0;
}
arpreq.arp_pa.sa_family = AF_INET;
INET_ADDR(arpreq.arp_pa) = hisaddr;
if (ioctl(ipfd, SIOCDARP, (caddr_t)&arpreq) < 0) {
- syslog(LOG_ERR, "Couldn't delete proxy ARP entry: %m");
+ error("Couldn't delete proxy ARP entry: %m");
return 0;
}
if (ifc.ifc_buf == 0)
return 0;
if (ioctl(ipfd, SIOCGIFCONF, &ifc) < 0) {
- syslog(LOG_WARNING, "Couldn't get system interface list: %m");
+ warn("Couldn't get system interface list: %m");
free(ifc.ifc_buf);
return 0;
}
}
if (ifr >= ifend) {
- syslog(LOG_WARNING, "No suitable interface found for proxy ARP");
+ warn("No suitable interface found for proxy ARP");
free(ifc.ifc_buf);
return 0;
}
- syslog(LOG_INFO, "found interface %s for proxy ARP", ifr->ifr_name);
+ info("found interface %s for proxy ARP", ifr->ifr_name);
if (!get_hw_addr(ifr->ifr_name, ina, hwaddr)) {
- syslog(LOG_ERR, "Couldn't get hardware address for %s", ifr->ifr_name);
+ error("Couldn't get hardware address for %s", ifr->ifr_name);
free(ifc.ifc_buf);
return 0;
}
req.arp_pa.sa_family = AF_INET;
INET_ADDR(req.arp_pa) = ina;
if (ioctl(s, SIOCGARP, &req) < 0) {
- syslog(LOG_ERR, "Couldn't get ARP entry for %s: %m", ip_ntoa(ina));
+ error("Couldn't get ARP entry for %s: %m", ip_ntoa(ina));
return 0;
}
*hwaddr = req.arp_ha;
*/
iffd = open(ifdev, O_RDWR);
if (iffd < 0) {
- syslog(LOG_ERR, "Can't open %s: %m", ifdev);
+ error("Can't open %s: %m", ifdev);
return 0;
}
if (dlpi_attach(iffd, unit) < 0
if (buf.len < sizeof(ulong)) {
if (debug)
- syslog(LOG_DEBUG, "dlpi response short (len=%d)\n", buf.len);
+ dbglog("dlpi response short (len=%d)\n", buf.len);
return -1;
}
if (debug) {
if (reply->dl_primitive == DL_ERROR_ACK) {
- syslog(LOG_DEBUG, "dlpi error %d (unix errno %d) for prim %x\n",
+ dbglog("dlpi error %d (unix errno %d) for prim %x\n",
reply->error_ack.dl_errno, reply->error_ack.dl_unix_errno,
reply->error_ack.dl_error_primitive);
} else {
- syslog(LOG_DEBUG, "dlpi unexpected response prim %x\n",
+ dbglog("dlpi unexpected response prim %x\n",
reply->dl_primitive);
}
}
if (ifc.ifc_buf == 0)
return mask;
if (ioctl(ipfd, SIOCGIFCONF, &ifc) < 0) {
- syslog(LOG_WARNING, "Couldn't get system interface list: %m");
+ warn("Couldn't get system interface list: %m");
free(ifc.ifc_buf);
return mask;
}
char buf[32];
if (sysinfo(SI_HW_SERIAL, buf, sizeof(buf)) < 0) {
- syslog(LOG_ERR, "sysinfo: %m");
+ error("sysinfo: %m");
return 0;
}
return (int) strtoul(buf, NULL, 16);
if (ioctl(fd, I_STR, &str) == -1)
return -1;
if (str.ic_len != olen)
- syslog(LOG_DEBUG, "strioctl: expected %d bytes, got %d for cmd %x\n",
+ dbglog("strioctl: expected %d bytes, got %d for cmd %x\n",
olen, str.ic_len, cmd);
return 0;
}
char ascii_pid[12];
if (stat(dev, &sbuf) < 0) {
- syslog(LOG_ERR, "Can't get device number for %s: %m", dev);
+ error("Can't get device number for %s: %m", dev);
return -1;
}
if ((sbuf.st_mode & S_IFMT) != S_IFCHR) {
- syslog(LOG_ERR, "Can't lock %s: not a character device", dev);
+ error("Can't lock %s: not a character device", dev);
return -1;
}
- sprintf(lock_file, "%s%03d.%03d.%03d", LOCK_PREFIX, major(sbuf.st_dev),
- major(sbuf.st_rdev), minor(sbuf.st_rdev));
+ slprintf(lock_file, sizeof(lock_file), "%s%03d.%03d.%03d",
+ LOCK_PREFIX, major(sbuf.st_dev),
+ major(sbuf.st_rdev), minor(sbuf.st_rdev));
while ((fd = open(lock_file, O_EXCL | O_CREAT | O_RDWR, 0644)) < 0) {
if (errno == EEXIST
/* Read the lock file to find out who has the device locked */
n = read(fd, ascii_pid, 11);
if (n <= 0) {
- syslog(LOG_ERR, "Can't read pid from lock file %s", lock_file);
+ error("Can't read pid from lock file %s", lock_file);
close(fd);
} else {
ascii_pid[n] = 0;
/* pid no longer exists - remove the lock file */
if (unlink(lock_file) == 0) {
close(fd);
- syslog(LOG_NOTICE, "Removed stale lock on %s (pid %d)",
+ notice("Removed stale lock on %s (pid %d)",
dev, pid);
continue;
} else
- syslog(LOG_WARNING, "Couldn't remove stale lock on %s",
+ warn("Couldn't remove stale lock on %s",
dev);
} else
- syslog(LOG_NOTICE, "Device %s is locked by pid %d",
+ notice("Device %s is locked by pid %d",
dev, pid);
}
close(fd);
} else
- syslog(LOG_ERR, "Can't create lock file %s: %m", lock_file);
+ error("Can't create lock file %s: %m", lock_file);
lock_file[0] = 0;
return -1;
}
- sprintf(ascii_pid, "%10d\n", getpid());
+ slprintf(ascii_pid, sizeof(ascii_pid), "%10d\n", getpid());
write(fd, ascii_pid, 11);
close(fd);
rt.rt_flags = RTF_HOST;
if (ioctl(ipfd, SIOCDELRT, &rt) < 0) {
- syslog(LOG_ERR, "Can't delete route: %m");
+ error("Can't delete route: %m");
return 0;
}
fd = open("/dev/ip", O_RDWR);
if (fd < 0) {
- syslog(LOG_WARNING, "have_route_to: couldn't open /dev/ip: %m");
+ warn("have_route_to: couldn't open /dev/ip: %m");
return -1;
}
cbuf.len = sizeof(req);
if (putmsg(fd, &cbuf, NULL, 0) == -1) {
- syslog(LOG_WARNING, "have_route_to: putmsg: %m");
+ warn("have_route_to: putmsg: %m");
close(fd);
return -1;
}
flags = 0;
r = getmsg(fd, &cbuf, &dbuf, &flags);
if (r == -1) {
- syslog(LOG_WARNING, "have_route_to: getmsg: %m");
+ warn("have_route_to: getmsg: %m");
close(fd);
return -1;
}
|| ack.ack.PRIM_type != T_OPTMGMT_ACK
|| ack.ack.MGMT_flags != T_SUCCESS
|| ack.ack.OPT_length < sizeof(struct opthdr)) {
- syslog(LOG_DEBUG, "have_route_to: bad message len=%d prim=%d",
+ dbglog("have_route_to: bad message len=%d prim=%d",
cbuf.len, ack.ack.PRIM_type);
close(fd);
return -1;
nroutes = dbuf.len / sizeof(mib2_ipRouteEntry_t);
for (rp = routes, i = 0; i < nroutes; ++i, ++rp) {
if (rp->ipRouteMask != ~0) {
- syslog(LOG_DEBUG, "have_route_to: dest=%x gw=%x mask=%x\n",
+ dbglog("have_route_to: dest=%x gw=%x mask=%x\n",
rp->ipRouteDest, rp->ipRouteNextHop,
rp->ipRouteMask);
if (((addr ^ rp->ipRouteDest) & rp->ipRouteMask) == 0
*/
#ifndef lint
-static char rcsid[] = "$Id: sys-ultrix.c,v 1.25 1999/03/12 06:07:24 paulus Exp $";
+static char rcsid[] = "$Id: sys-ultrix.c,v 1.26 1999/03/16 02:57:08 paulus Exp $";
#endif
/*
#include <stdio.h>
#include <stdlib.h>
-#include <syslog.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
static int sockfd; /* socket for doing interface ioctls */
+static fd_set in_fds; /* set of fds that wait_input waits for */
+static int max_in_fd; /* highest fd set in in_fds */
+
static int if_is_up; /* the interface is currently up */
static u_int32_t ifaddrs[2]; /* local and remote addresses */
static u_int32_t default_route_gateway; /* gateway addr for default route */
{
/* Get an internet socket for doing socket ioctl's on. */
if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
- syslog(LOG_ERR, "Couldn't create IP socket: %m");
+ error("Couldn't create IP socket: %m");
die(1);
}
+
+ FD_ZERO(&in_fds);
+ max_in_fd = 0;
}
/*
* Save the old line discipline of fd, and set it to PPP.
*/
if (ioctl(fd, TIOCGETD, &initdisc) < 0) {
- syslog(LOG_ERR, "ioctl(TIOCGETD): %m");
+ error("ioctl(TIOCGETD): %m");
die(1);
}
if (ioctl(fd, TIOCSETD, &pppdisc) < 0) {
- syslog(LOG_ERR, "ioctl(TIOCSETD): %m");
+ error("ioctl(TIOCSETD): %m");
die(1);
}
* Find out which interface we were given.
*/
if (ioctl(fd, PPPIOCGUNIT, &ifunit) < 0) {
- syslog(LOG_ERR, "ioctl(PPPIOCGUNIT): %m");
+ error("ioctl(PPPIOCGUNIT): %m");
die(1);
}
*/
if (kdebugflag) {
if (ioctl(fd, PPPIOCGFLAGS, (caddr_t) &x) < 0) {
- syslog(LOG_WARNING, "ioctl (PPPIOCGFLAGS): %m");
+ warn("ioctl (PPPIOCGFLAGS): %m");
} else {
x |= (kdebugflag & 0xFF) * SC_DEBUG;
if (ioctl(fd, PPPIOCSFLAGS, (caddr_t) &x) < 0)
- syslog(LOG_WARNING, "ioctl(PPPIOCSFLAGS): %m");
+ warn("ioctl(PPPIOCSFLAGS): %m");
}
}
*/
if ((initfdflags = fcntl(fd, F_GETFL)) == -1
|| fcntl(fd, F_SETFL, initfdflags | O_NONBLOCK) == -1) {
- syslog(LOG_WARNING, "Couldn't set device to non-blocking mode: %m");
+ warn("Couldn't set device to non-blocking mode: %m");
}
}
{
/* Reset non-blocking mode on fd. */
if (initfdflags != -1 && fcntl(fd, F_SETFL, initfdflags) < 0)
- syslog(LOG_WARNING, "Couldn't restore device fd flags: %m");
+ warn("Couldn't restore device fd flags: %m");
initfdflags = -1;
/* Restore old line discipline. */
if (initdisc >= 0 && ioctl(fd, TIOCSETD, &initdisc) < 0)
- syslog(LOG_ERR, "ioctl(TIOCSETD): %m");
+ error("ioctl(TIOCSETD): %m");
initdisc = -1;
if (fd == ppp_fd)
break;
}
if (s != NULL) {
- syslog(LOG_WARNING, "Serial link is not 8-bit clean:");
- syslog(LOG_WARNING, "All received characters had %s", s);
+ warn("Serial link is not 8-bit clean:");
+ warn("All received characters had %s", s);
}
}
}
for (speedp = speeds; speedp->speed_int; speedp++)
if (bps == speedp->speed_int)
return speedp->speed_val;
- syslog(LOG_WARNING, "speed %d not supported", bps);
+ warn("speed %d not supported", bps);
return 0;
}
struct termios tios;
if (tcgetattr(fd, &tios) < 0) {
- syslog(LOG_ERR, "tcgetattr: %m");
+ error("tcgetattr: %m");
die(1);
}
* since that implies that the serial port is disabled.
*/
if (speed == B0) {
- syslog(LOG_ERR, "Baud rate for %s is 0; need explicit baud rate",
+ error("Baud rate for %s is 0; need explicit baud rate",
devnam);
die(1);
}
}
if (tcsetattr(fd, TCSAFLUSH, &tios) < 0) {
- syslog(LOG_ERR, "tcsetattr: %m");
+ error("tcsetattr: %m");
die(1);
}
x = 0;
if (ioctl(fd, (crtscts > 0 || modem)? TIOCMODEM: TIOCNMODEM, &x) < 0)
- syslog(LOG_WARNING, "TIOC(N)MODEM: %m");
+ warn("TIOC(N)MODEM: %m");
if (ioctl(fd, (local || !modem)? TIOCNCAR: TIOCCAR) < 0)
- syslog(LOG_WARNING, "TIOC(N)CAR: %m");
+ warn("TIOC(N)CAR: %m");
baud_rate = inspeed = baud_rate_of(speed);
restore_term = TRUE;
}
if (tcsetattr(fd, TCSAFLUSH, &inittermios) < 0)
if (errno != ENXIO)
- syslog(LOG_WARNING, "tcsetattr: %m");
+ warn("tcsetattr: %m");
ioctl(fd, TIOCSWINSZ, &wsinfo);
restore_term = FALSE;
}
void
open_ppp_loopback()
{
- syslog(LOG_ERR, "open_ppp_loopback called!");
+ error("open_ppp_loopback called!");
die(1);
}
int len;
{
if (debug)
- log_packet(p, len, "sent ", LOG_DEBUG);
+ dbglog("sent %P", p, len);
if (write(ttyfd, p, len) < 0) {
if (errno != EIO)
- syslog(LOG_ERR, "write: %m");
+ error("write: %m");
}
}
/*
- * wait_input - wait until there is data available on ttyfd,
+ * wait_input - wait until there is data available,
* for the length of time specified by *timo (indefinite
* if timo is NULL).
*/
fd_set ready;
int n;
- FD_ZERO(&ready);
- FD_SET(ttyfd, &ready);
+ ready = in_fds;
n = select(ttyfd+1, &ready, NULL, &ready, timo);
- if (n < 0 && errno != EINTR) {
- syslog(LOG_ERR, "select: %m");
- die(1);
- }
+ if (n < 0 && errno != EINTR)
+ fatal("select: %m");
}
+/*
+ * add_fd - add an fd to the set that wait_input waits for.
+ */
+void add_fd(int fd)
+{
+ FD_SET(fd, &in_fds);
+ if (fd > max_in_fd)
+ max_in_fd = fd;
+}
+
+/*
+ * remove_fd - remove an fd from the set that wait_input waits for.
+ */
+void remove_fd(int fd)
+{
+ FD_CLR(fd, &in_fds);
+}
+
+#if 0
/*
* wait_loop_output - wait until there is data available on the
* loopback, for the length of time specified by *timo (indefinite
n = select(0, NULL, NULL, NULL, timo);
if (n < 0 && errno != EINTR) {
- syslog(LOG_ERR, "select: %m");
+ error("select: %m");
die(1);
}
}
-
+#endif
/*
* read_packet - get a PPP packet from the serial device.
if ((len = read(ttyfd, buf, PPP_MTU + PPP_HDRLEN)) < 0) {
if (errno == EWOULDBLOCK || errno == EINTR)
return -1;
- syslog(LOG_ERR, "read(fd): %m");
+ error("read(fd): %m");
die(1);
}
return len;
u_int x;
if (ioctl(ppp_fd, PPPIOCSMTU, &mtu) < 0) {
- syslog(LOG_ERR, "ioctl(PPPIOCSMTU): %m");
+ error("ioctl(PPPIOCSMTU): %m");
quit();
}
if (ioctl(ppp_fd, PPPIOCSASYNCMAP, (caddr_t) &asyncmap) < 0) {
- syslog(LOG_ERR, "ioctl(PPPIOCSASYNCMAP): %m");
+ error("ioctl(PPPIOCSASYNCMAP): %m");
quit();
}
if (ioctl(ppp_fd, PPPIOCGFLAGS, (caddr_t) &x) < 0) {
- syslog(LOG_ERR, "ioctl (PPPIOCGFLAGS): %m");
+ error("ioctl (PPPIOCGFLAGS): %m");
quit();
}
x = pcomp? x | SC_COMP_PROT: x &~ SC_COMP_PROT;
x = accomp? x | SC_COMP_AC: x &~ SC_COMP_AC;
if (ioctl(ppp_fd, PPPIOCSFLAGS, (caddr_t) &x) < 0) {
- syslog(LOG_ERR, "ioctl(PPPIOCSFLAGS): %m");
+ error("ioctl(PPPIOCSFLAGS): %m");
quit();
}
}
ext_accm accm;
{
if (ioctl(ppp_fd, PPPIOCSXASYNCMAP, accm) < 0 && errno != ENOTTY)
- syslog(LOG_WARNING, "ioctl(set extended ACCM): %m");
+ warn("ioctl(set extended ACCM): %m");
}
int x;
if (ioctl(ppp_fd, PPPIOCSMRU, (caddr_t) &mru) < 0) {
- syslog(LOG_ERR, "ioctl(PPPIOCSMRU): %m");
+ error("ioctl(PPPIOCSMRU): %m");
quit();
}
if (ioctl(ppp_fd, PPPIOCSRASYNCMAP, (caddr_t) &asyncmap) < 0) {
- syslog(LOG_ERR, "ioctl(PPPIOCSRASYNCMAP): %m");
+ error("ioctl(PPPIOCSRASYNCMAP): %m");
quit();
}
if (ioctl(ppp_fd, PPPIOCGFLAGS, (caddr_t) &x) < 0) {
- syslog(LOG_ERR, "ioctl (PPPIOCGFLAGS): %m");
+ error("ioctl (PPPIOCGFLAGS): %m");
quit();
}
x = !accomp? x | SC_REJ_COMP_AC: x &~ SC_REJ_COMP_AC;
if (ioctl(ppp_fd, PPPIOCSFLAGS, (caddr_t) &x) < 0) {
- syslog(LOG_ERR, "ioctl(PPPIOCSFLAGS): %m");
+ error("ioctl(PPPIOCSFLAGS): %m");
quit();
}
}
int x;
if (ioctl(ppp_fd, PPPIOCGFLAGS, (caddr_t) &x) < 0) {
- syslog(LOG_ERR, "ioctl (PPPIOCGFLAGS): %m");
+ error("ioctl (PPPIOCGFLAGS): %m");
return;
}
x = isopen? x | SC_CCP_OPEN: x &~ SC_CCP_OPEN;
x = isup? x | SC_CCP_UP: x &~ SC_CCP_UP;
if (ioctl(ppp_fd, PPPIOCSFLAGS, (caddr_t) &x) < 0)
- syslog(LOG_ERR, "ioctl(PPPIOCSFLAGS): %m");
+ error("ioctl(PPPIOCSFLAGS): %m");
}
/*
int x;
if (ioctl(ppp_fd, PPPIOCGFLAGS, (caddr_t) &x) < 0) {
- syslog(LOG_ERR, "ioctl(PPPIOCGFLAGS): %m");
+ error("ioctl(PPPIOCGFLAGS): %m");
return 0;
}
return x & SC_DC_FERROR;
u_int x;
if (ioctl(ppp_fd, PPPIOCGFLAGS, (caddr_t) &x) < 0) {
- syslog(LOG_ERR, "ioctl (PPPIOCGFLAGS): %m");
+ error("ioctl (PPPIOCGFLAGS): %m");
return 0;
}
x = vjcomp ? x | SC_COMP_TCP: x &~ SC_COMP_TCP;
x = cidcomp? x & ~SC_NO_TCP_CCID: x | SC_NO_TCP_CCID;
if (ioctl(ppp_fd, PPPIOCSFLAGS, (caddr_t) &x) < 0) {
- syslog(LOG_ERR, "ioctl(PPPIOCSFLAGS): %m");
+ error("ioctl(PPPIOCSFLAGS): %m");
return 0;
}
if (ioctl(ppp_fd, PPPIOCSMAXCID, (caddr_t) &maxcid) < 0) {
- syslog(LOG_ERR, "ioctl(PPPIOCSFLAGS): %m");
+ error("ioctl(PPPIOCSFLAGS): %m");
return 0;
}
return 1;
strlcpy(ifr.ifr_name, sizeof (ifr.ifr_name), ifname);
if (ioctl(sockfd, SIOCGIFFLAGS, (caddr_t) &ifr) < 0) {
- syslog(LOG_ERR, "ioctl (SIOCGIFFLAGS): %m");
+ error("ioctl (SIOCGIFFLAGS): %m");
return 0;
}
ifr.ifr_flags |= IFF_UP;
if (ioctl(sockfd, SIOCSIFFLAGS, (caddr_t) &ifr) < 0) {
- syslog(LOG_ERR, "ioctl(SIOCSIFFLAGS): %m");
+ error("ioctl(SIOCSIFFLAGS): %m");
return 0;
}
if_is_up = 1;
npi.protocol = proto;
npi.mode = mode;
if (ioctl(ppp_fd, PPPIOCSNPMODE, &npi) < 0) {
- syslog(LOG_ERR, "ioctl(set NP %d mode to %d): %m", proto, mode);
+ error("ioctl(set NP %d mode to %d): %m", proto, mode);
return 0;
}
return 1;
strlcpy(ifr.ifr_name, sizeof (ifr.ifr_name), ifname);
if (ioctl(sockfd, SIOCGIFFLAGS, (caddr_t) &ifr) < 0) {
- syslog(LOG_ERR, "ioctl (SIOCGIFFLAGS): %m");
+ error("ioctl (SIOCGIFFLAGS): %m");
rv = 0;
} else {
ifr.ifr_flags &= ~IFF_UP;
if (ioctl(sockfd, SIOCSIFFLAGS, (caddr_t) &ifr) < 0) {
- syslog(LOG_ERR, "ioctl(SIOCSIFFLAGS): %m");
+ error("ioctl(SIOCSIFFLAGS): %m");
rv = 0;
} else
if_is_up = 0;
SET_SA_FAMILY(ifr.ifr_addr, AF_INET);
if (m != 0) {
((struct sockaddr_in *) &ifr.ifr_addr)->sin_addr.s_addr = m;
- syslog(LOG_INFO, "Setting interface mask to %s\n", ip_ntoa(m));
+ info("Setting interface mask to %s\n", ip_ntoa(m));
if (ioctl(sockfd, SIOCSIFNETMASK, (caddr_t) &ifr) < 0) {
- syslog(LOG_ERR, "ioctl(SIOCSIFNETMASK): %m");
+ error("ioctl(SIOCSIFNETMASK): %m");
ret = 0;
}
}
((struct sockaddr_in *) &ifr.ifr_addr)->sin_addr.s_addr = o;
if (ioctl(sockfd, SIOCSIFADDR, (caddr_t) &ifr) < 0) {
- syslog(LOG_ERR, "ioctl(SIOCSIFADDR): %m");
+ error("ioctl(SIOCSIFADDR): %m");
ret = 0;
}
((struct sockaddr_in *) &ifr.ifr_dstaddr)->sin_addr.s_addr = h;
if (ioctl(sockfd, SIOCSIFDSTADDR, (caddr_t) &ifr) < 0) {
- syslog(LOG_ERR, "ioctl(SIOCSIFDSTADDR): %m");
+ error("ioctl(SIOCSIFDSTADDR): %m");
ret = 0;
}
ifaddrs[0] = o;
((struct sockaddr_in *) &rt.rt_gateway)->sin_addr.s_addr = o;
rt.rt_flags = RTF_HOST;
if (ioctl(sockfd, SIOCDELRT, (caddr_t) &rt) < 0) {
- syslog(LOG_ERR, "ioctl(SIOCDELRT): %m");
+ error("ioctl(SIOCDELRT): %m");
return 0;
}
return 1;
((struct sockaddr_in *) &rt.rt_gateway)->sin_addr.s_addr = g;
rt.rt_flags = RTF_GATEWAY;
if (ioctl(sockfd, SIOCADDRT, &rt) < 0) {
- syslog(LOG_ERR, "default route ioctl(SIOCADDRT): %m");
+ error("default route ioctl(SIOCADDRT): %m");
return 0;
}
default_route_gateway = g;
((struct sockaddr_in *) &rt.rt_gateway)->sin_addr.s_addr = g;
rt.rt_flags = RTF_GATEWAY;
if (ioctl(sockfd, SIOCDELRT, &rt) < 0)
- syslog(LOG_WARNING, "default route ioctl(SIOCDELRT): %m");
+ warn("default route ioctl(SIOCDELRT): %m");
default_route_gateway = 0;
return 1;
}
* as our local address.
*/
if (!get_ether_addr(hisaddr, &arpreq.arp_ha)) {
- syslog(LOG_ERR, "Cannot determine ethernet address for proxy ARP");
+ error("Cannot determine ethernet address for proxy ARP");
return 0;
}
((struct sockaddr_in *) &arpreq.arp_pa)->sin_addr.s_addr = hisaddr;
arpreq.arp_flags = ATF_PERM | ATF_PUBL;
if (ioctl(sockfd, SIOCSARP, (caddr_t)&arpreq) < 0) {
- syslog(LOG_ERR, "Couldn't add proxy arp entry: %m");
+ error("Couldn't add proxy arp entry: %m");
return 0;
}
SET_SA_FAMILY(arpreq.arp_pa, AF_INET);
((struct sockaddr_in *) &arpreq.arp_pa)->sin_addr.s_addr = hisaddr;
if (ioctl(sockfd, SIOCDARP, (caddr_t)&arpreq) < 0) {
- syslog(LOG_WARNING, "Couldn't delete proxy arp entry: %m");
+ warn("Couldn't delete proxy arp entry: %m");
return 0;
}
proxy_arp_addr = 0;
ifc.ifc_len = sizeof(ifs);
ifc.ifc_req = ifs;
if (ioctl(sockfd, SIOCGIFCONF, &ifc) < 0) {
- syslog(LOG_ERR, "ioctl(SIOCGIFCONF): %m");
+ error("ioctl(SIOCGIFCONF): %m");
return 0;
}
if (ifr >= ifend)
return 0;
- syslog(LOG_INFO, "found interface %s for proxy arp", ifr->ifr_name);
+ info("found interface %s for proxy arp", ifr->ifr_name);
/*
* Grab the physical address for this interface.
*/
strlcpy(ifdevea.ifr_name, sizeof(ifdevea.ifr_name), ifr->ifr_name);
if (ioctl(sockfd, SIOCRPHYSADDR, &ifdevea) < 0) {
- syslog(LOG_ERR, "Couldn't get h/w address for %s: %m", ifr->ifr_name);
+ error("Couldn't get h/w address for %s: %m", ifr->ifr_name);
return 0;
}
ifc.ifc_len = sizeof(ifs);
ifc.ifc_req = ifs;
if (ioctl(sockfd, SIOCGIFCONF, &ifc) < 0) {
- syslog(LOG_WARNING, "ioctl(SIOCGIFCONF): %m");
+ warn("ioctl(SIOCGIFCONF): %m");
return mask;
}
ifend = (struct ifreq *) (ifc.ifc_buf + ifc.ifc_len);
/* Read the lock file to find out who has the device locked */
n = read(fd, &pid, sizeof(pid));
if (n <= 0) {
- syslog(LOG_ERR, "Can't read pid from lock file %s", lock_file);
+ error("Can't read pid from lock file %s", lock_file);
close(fd);
} else {
if (kill(pid, 0) == -1 && errno == ESRCH) {
/* pid no longer exists - remove the lock file */
if (unlink(lock_file) == 0) {
close(fd);
- syslog(LOG_NOTICE, "Removed stale lock on %s (pid %d)",
+ notice("Removed stale lock on %s (pid %d)",
dev, pid);
continue;
} else
- syslog(LOG_WARNING, "Couldn't remove stale lock on %s",
+ warn("Couldn't remove stale lock on %s",
dev);
} else
- syslog(LOG_NOTICE, "Device %s is locked by pid %d",
+ notice("Device %s is locked by pid %d",
dev, pid);
}
close(fd);
} else
- syslog(LOG_ERR, "Can't create lock file %s: %m", lock_file);
+ error("Can't create lock file %s: %m", lock_file);
free(lock_file);
lock_file = NULL;
return -1;