diff options
author | Jun-ichiro itojun Hagino <itojun@cvs.openbsd.org> | 2002-10-26 20:23:21 +0000 |
---|---|---|
committer | Jun-ichiro itojun Hagino <itojun@cvs.openbsd.org> | 2002-10-26 20:23:21 +0000 |
commit | ee2bda90aadd745b0da4a9602c47af98701d83c6 (patch) | |
tree | d2eba2b8072374db3d28108b76c318e52fe372bb /usr.sbin/rtsold | |
parent | 9c5590fe5b25ed0af87f52e93ba901900d4cd5bc (diff) |
use poll(2). sync w/kame
Diffstat (limited to 'usr.sbin/rtsold')
-rw-r--r-- | usr.sbin/rtsold/Makefile | 4 | ||||
-rw-r--r-- | usr.sbin/rtsold/probe.c | 6 | ||||
-rw-r--r-- | usr.sbin/rtsold/rtsold.c | 47 |
3 files changed, 49 insertions, 8 deletions
diff --git a/usr.sbin/rtsold/Makefile b/usr.sbin/rtsold/Makefile index a7d148f726e..143d5d493d6 100644 --- a/usr.sbin/rtsold/Makefile +++ b/usr.sbin/rtsold/Makefile @@ -1,9 +1,9 @@ -# $OpenBSD: Makefile,v 1.4 2001/12/01 23:27:24 miod Exp $ +# $OpenBSD: Makefile,v 1.5 2002/10/26 20:23:20 itojun Exp $ PROG= rtsold SRCS= rtsold.c rtsol.c if.c probe.c dump.c -CPPFLAGS+=-DINET6 -DHAVE_ARC4RANDOM -DHAVE_GETIFADDRS +CPPFLAGS+=-DINET6 -DHAVE_ARC4RANDOM -DHAVE_GETIFADDRS -DHAVE_POLL_H MAN= rtsold.8 MLINKS= rtsold.8 rtsol.8 diff --git a/usr.sbin/rtsold/probe.c b/usr.sbin/rtsold/probe.c index f34d8d88baa..7cef798c417 100644 --- a/usr.sbin/rtsold/probe.c +++ b/usr.sbin/rtsold/probe.c @@ -1,5 +1,5 @@ -/* $OpenBSD: probe.c,v 1.8 2002/06/10 19:57:35 espie Exp $ */ -/* $KAME: probe.c,v 1.14 2002/05/31 10:10:03 itojun Exp $ */ +/* $OpenBSD: probe.c,v 1.9 2002/10/26 20:23:20 itojun Exp $ */ +/* $KAME: probe.c,v 1.16 2002/06/10 20:00:36 itojun Exp $ */ /* * Copyright (C) 1998 WIDE Project. @@ -109,7 +109,7 @@ defrouter_probe(struct ifinfo *ifinfo) return; } memset(&dr, 0, sizeof(dr)); - strcpy(dr.ifname, "lo0"); /* dummy interface */ + strlcpy(dr.ifname, "lo0", sizeof dr.ifname); /* dummy interface */ if (ioctl(s, SIOCGDRLST_IN6, (caddr_t)&dr) < 0) { warnmsg(LOG_ERR, __func__, "ioctl(SIOCGDRLST_IN6): %s", strerror(errno)); diff --git a/usr.sbin/rtsold/rtsold.c b/usr.sbin/rtsold/rtsold.c index 44d633b91a8..2e0301db5d8 100644 --- a/usr.sbin/rtsold/rtsold.c +++ b/usr.sbin/rtsold/rtsold.c @@ -1,5 +1,5 @@ -/* $OpenBSD: rtsold.c,v 1.25 2002/09/08 01:33:35 itojun Exp $ */ -/* $KAME: rtsold.c,v 1.55 2002/09/08 01:26:03 itojun Exp $ */ +/* $OpenBSD: rtsold.c,v 1.26 2002/10/26 20:23:20 itojun Exp $ */ +/* $KAME: rtsold.c,v 1.57 2002/09/20 21:59:55 itojun Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -52,6 +52,9 @@ #include <stdarg.h> #include <ifaddrs.h> #include <util.h> +#ifdef HAVE_POLL_H +#include <poll.h> +#endif #include "rtsold.h" @@ -105,11 +108,16 @@ main(argc, argv) int argc; char **argv; { - int s, maxfd, ch, once = 0; + int s, ch, once = 0; struct timeval *timeout; char *argv0, *opts; +#ifdef HAVE_POLL_H + struct pollfd set[2]; +#else fd_set *fdsetp, *selectfdp; int fdmasks; + int maxfd; +#endif #ifdef USE_RTSOCK int rtsock; #endif @@ -204,17 +212,33 @@ main(argc, argv) exit(1); /*NOTREACHED*/ } +#ifdef HAVE_POLL_H + set[0].fd = s; + set[0].events = POLLIN; +#else maxfd = s; +#endif + +#ifdef HAVE_POLL_H + set[1].fd = -1; +#endif + #ifdef USE_RTSOCK if ((rtsock = rtsock_open()) < 0) { warnmsg(LOG_ERR, __func__, "failed to open a socket"); exit(1); /*NOTREACHED*/ } +#ifdef HAVE_POLL_H + set[1].fd = rtsock; + set[1].events = POLLIN; +#else if (rtsock > maxfd) maxfd = rtsock; #endif +#endif +#ifndef HAVE_POLL_H fdmasks = howmany(maxfd + 1, NFDBITS) * sizeof(fd_mask); if ((fdsetp = malloc(fdmasks)) == NULL) { err(1, "malloc"); @@ -224,6 +248,7 @@ main(argc, argv) err(1, "malloc"); /*NOTREACHED*/ } +#endif /* configuration per interface */ if (ifinit()) { @@ -261,15 +286,19 @@ main(argc, argv) } } +#ifndef HAVE_POLL_H memset(fdsetp, 0, fdmasks); FD_SET(s, fdsetp); #ifdef USE_RTSOCK FD_SET(rtsock, fdsetp); #endif +#endif while (1) { /* main loop */ int e; +#ifndef HAVE_POLL_H memcpy(selectfdp, fdsetp, fdmasks); +#endif if (do_dump) { /* SIGUSR1 */ do_dump = 0; @@ -293,7 +322,11 @@ main(argc, argv) if (ifi == NULL) break; } +#ifdef HAVE_POLL_H + e = poll(set, 2, timeout ? (timeout->tv_sec * 1000 + timeout->tv_usec / 1000) : INFTIM); +#else e = select(maxfd + 1, selectfdp, NULL, NULL, timeout); +#endif if (e < 1) { if (e < 0 && errno != EINTR) { warnmsg(LOG_ERR, __func__, "select: %s", @@ -304,10 +337,18 @@ main(argc, argv) /* packet reception */ #ifdef USE_RTSOCK +#ifdef HAVE_POLL_H + if (set[1].revents & POLLIN) +#else if (FD_ISSET(rtsock, selectfdp)) +#endif rtsock_input(rtsock); #endif +#ifdef HAVE_POLL_H + if (set[0].revents & POLLIN) +#else if (FD_ISSET(s, selectfdp)) +#endif rtsol_input(s); } /* NOTREACHED */ |