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/ping6.c | |
parent | e8bae89d5b7899f4b017b68a647dee84471d1c5d (diff) |
use poll(2). sync w/kame (originally from netbsd)
Diffstat (limited to 'sbin/ping6/ping6.c')
-rw-r--r-- | sbin/ping6/ping6.c | 36 |
1 files changed, 34 insertions, 2 deletions
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; |