summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJun-ichiro itojun Hagino <itojun@cvs.openbsd.org>2002-10-26 20:16:14 +0000
committerJun-ichiro itojun Hagino <itojun@cvs.openbsd.org>2002-10-26 20:16:14 +0000
commit494d0c27ec8020f0ec7c107a2eee4e81ac5a140c (patch)
treef3d669a2412e20e276bb34d2b08d743e4ea86891
parent2a750eaaafebdb7ba595d3d0aba4f09ab116338b (diff)
use poll(2). sync w/kame originally from netbsd
-rw-r--r--usr.sbin/route6d/Makefile4
-rw-r--r--usr.sbin/route6d/route6d.c53
2 files changed, 48 insertions, 9 deletions
diff --git a/usr.sbin/route6d/Makefile b/usr.sbin/route6d/Makefile
index b8834ae9263..085d1a1d78f 100644
--- a/usr.sbin/route6d/Makefile
+++ b/usr.sbin/route6d/Makefile
@@ -1,10 +1,10 @@
-# $OpenBSD: Makefile,v 1.5 2001/12/01 23:27:23 miod Exp $
+# $OpenBSD: Makefile,v 1.6 2002/10/26 20:16:13 itojun Exp $
PROG= route6d
MAN= route6d.8
LDADD+= -lutil
DPADD+= ${LIBUTIL}
-CPPFLAGS+= -DINET6
+CPPFLAGS+= -DINET6 -DHAVE_POLL_H
.include <bsd.prog.mk>
diff --git a/usr.sbin/route6d/route6d.c b/usr.sbin/route6d/route6d.c
index 5187cc1768d..6a8519f2a1d 100644
--- a/usr.sbin/route6d/route6d.c
+++ b/usr.sbin/route6d/route6d.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: route6d.c,v 1.32 2002/10/26 20:14:27 itojun Exp $ */
+/* $OpenBSD: route6d.c,v 1.33 2002/10/26 20:16:13 itojun Exp $ */
/* $KAME: route6d.c,v 1.94 2002/10/26 20:08:55 itojun Exp $ */
/*
@@ -31,7 +31,7 @@
*/
#if 0
-static char _rcsid[] = "$OpenBSD: route6d.c,v 1.32 2002/10/26 20:14:27 itojun Exp $";
+static char _rcsid[] = "$OpenBSD: route6d.c,v 1.33 2002/10/26 20:16:13 itojun Exp $";
#endif
#include <stdio.h>
@@ -47,6 +47,9 @@ static char _rcsid[] = "$OpenBSD: route6d.c,v 1.32 2002/10/26 20:14:27 itojun Ex
#include <errno.h>
#include <err.h>
#include <util.h>
+#ifdef HAVE_POLL_H
+#include <poll.h>
+#endif
#include <sys/types.h>
#include <sys/param.h>
@@ -135,12 +138,16 @@ int nifc; /* number of valid ifc's */
struct ifc **index2ifc;
int nindex2ifc;
struct ifc *loopifcp = NULL; /* pointing to loopback */
+#ifdef HAVE_POLL_H
+struct pollfd set[2];
+#else
fd_set *sockvecp; /* vector to select() for receiving */
fd_set *recvecp;
int fdmasks;
+int maxfd; /* maximum fd for select() */
+#endif
int rtsock; /* the routing socket */
int ripsock; /* socket to send/receive RIP datagram */
-int maxfd; /* maximum fd for select() */
struct rip6 *ripbuf; /* packet buffer for sending */
@@ -442,8 +449,13 @@ main(argc, argv)
continue;
}
+#ifdef HAVE_POLL_H
+ switch (poll(set, 2, INFTIM))
+#else
memcpy(recvecp, sockvecp, fdmasks);
- switch (select(maxfd + 1, recvecp, 0, 0, 0)) {
+ switch (select(maxfd + 1, recvecp, 0, 0, 0))
+#endif
+ {
case -1:
if (errno != EINTR) {
fatal("select");
@@ -453,12 +465,22 @@ main(argc, argv)
case 0:
continue;
default:
- if (FD_ISSET(ripsock, recvecp)) {
+#ifdef HAVE_POLL_H
+ if (set[0].revents & POLLIN)
+#else
+ if (FD_ISSET(ripsock, recvecp))
+#endif
+ {
sigprocmask(SIG_BLOCK, &mask, &omask);
riprecv();
sigprocmask(SIG_SETMASK, &omask, NULL);
}
- if (FD_ISSET(rtsock, recvecp)) {
+#ifdef HAVE_POLL_H
+ if (set[1].revents & POLLIN)
+#else
+ if (FD_ISSET(rtsock, recvecp))
+#endif
+ {
sigprocmask(SIG_BLOCK, &mask, &omask);
rtrecv();
sigprocmask(SIG_SETMASK, &omask, NULL);
@@ -641,18 +663,34 @@ init()
}
memcpy(&ripsin, res->ai_addr, res->ai_addrlen);
+#ifdef HAVE_POLL_H
+ set[0].fd = ripsock;
+ set[0].events = POLLIN;
+#else
maxfd = ripsock;
+#endif
if (nflag == 0) {
if ((rtsock = socket(PF_ROUTE, SOCK_RAW, 0)) < 0) {
fatal("route socket");
/*NOTREACHED*/
}
+#ifdef HAVE_POLL_H
+ set[1].fd = rtsock;
+ set[1].events = POLLIN;
+#else
if (rtsock > maxfd)
maxfd = rtsock;
- } else
+#endif
+ } else {
+#ifdef HAVE_POLL_H
+ set[1].fd = -1;
+#else
rtsock = -1; /*just for safety */
+#endif
+ }
+#ifndef HAVE_POLL_H
fdmasks = howmany(maxfd + 1, NFDBITS) * sizeof(fd_mask);
if ((sockvecp = malloc(fdmasks)) == NULL) {
fatal("malloc");
@@ -666,6 +704,7 @@ init()
FD_SET(ripsock, sockvecp);
if (rtsock >= 0)
FD_SET(rtsock, sockvecp);
+#endif
}
#define RIPSIZE(n) \