diff options
author | Jun-ichiro itojun Hagino <itojun@cvs.openbsd.org> | 2002-10-25 02:25:44 +0000 |
---|---|---|
committer | Jun-ichiro itojun Hagino <itojun@cvs.openbsd.org> | 2002-10-25 02:25:44 +0000 |
commit | 081a37a2f00c30e24d701e29887158407d9027be (patch) | |
tree | 5f921f100e5dff190d11491a2ac5f380e4306e4e /sbin/ping6 | |
parent | e8bae89d5b7899f4b017b68a647dee84471d1c5d (diff) |
use poll(2). sync w/kame (originally from netbsd)
Diffstat (limited to 'sbin/ping6')
-rw-r--r-- | sbin/ping6/Makefile | 4 | ||||
-rw-r--r-- | sbin/ping6/ping6.c | 36 |
2 files changed, 36 insertions, 4 deletions
diff --git a/sbin/ping6/Makefile b/sbin/ping6/Makefile index 1565db43f90..25c97fd187e 100644 --- a/sbin/ping6/Makefile +++ b/sbin/ping6/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.6 2002/05/26 13:02:17 itojun Exp $ +# $OpenBSD: Makefile,v 1.7 2002/10/25 02:25:43 itojun Exp $ PROG= ping6 MAN= ping6.8 @@ -6,7 +6,7 @@ MAN= ping6.8 LDADD= -lm DPADD= ${LIBM} -CPPFLAGS+= -DINET6 +CPPFLAGS+= -DINET6 -DHAVE_POLL_H BINOWN= root BINGRP= bin diff --git a/sbin/ping6/ping6.c b/sbin/ping6/ping6.c index 9674238697a..e5f5636b6f1 100644 --- a/sbin/ping6/ping6.c +++ b/sbin/ping6/ping6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ping6.c,v 1.50 2002/10/25 02:24:27 itojun Exp $ */ +/* $OpenBSD: ping6.c,v 1.51 2002/10/25 02:25:43 itojun Exp $ */ /* $KAME: ping6.c,v 1.163 2002/10/25 02:19:06 itojun Exp $ */ /* @@ -126,6 +126,9 @@ static char sccsid[] = "@(#)ping.c 8.1 (Berkeley) 6/5/93"; #include <stdlib.h> #include <string.h> #include <unistd.h> +#ifdef HAVE_POLL_H +#include <poll.h> +#endif #ifdef IPSEC #include <netinet6/ah.h> @@ -283,10 +286,18 @@ main(argc, argv) { struct itimerval itimer; struct sockaddr_in6 from; +#ifdef HAVE_POLL_H + int timeout; +#else struct timeval timeout, *tv; +#endif struct addrinfo hints; +#ifdef HAVE_POLL_H + struct pollfd fdmaskp[1]; +#else fd_set *fdmaskp; int fdmasks; +#endif int cc, i; int ch, hold, packlen, preload, optval, ret_ga; u_char *datap, *packet; @@ -1045,9 +1056,11 @@ main(argc, argv) retransmit(); } +#ifndef HAVE_POLL_H fdmasks = howmany(s + 1, NFDBITS) * sizeof(fd_mask); if ((fdmaskp = malloc(fdmasks)) == NULL) err(1, "malloc"); +#endif seenalrm = seenint = 0; #ifdef SIGINFO @@ -1081,17 +1094,36 @@ main(argc, argv) if (options & F_FLOOD) { (void)pinger(); +#ifdef HAVE_POLL_H + timeout = 10; +#else timeout.tv_sec = 0; timeout.tv_usec = 10000; tv = &timeout; - } else +#endif + } else { +#ifdef HAVE_POLL_H + timeout = INFTIM; +#else tv = NULL; +#endif + } +#ifdef HAVE_POLL_H + fdmaskp[0].fd = s; + fdmaskp[0].events = POLLIN; + cc = poll(fdmaskp, 1, timeout); +#else memset(fdmaskp, 0, fdmasks); FD_SET(s, fdmaskp); cc = select(s + 1, fdmaskp, NULL, NULL, tv); +#endif if (cc < 0) { if (errno != EINTR) { +#ifdef HAVE_POLL_H + warn("poll"); +#else warn("select"); +#endif sleep(1); } continue; |