From: florian Date: Sat, 17 Oct 2015 13:08:14 +0000 (+0000) Subject: Implement -w maxwait now that the -w flag is free in ping6. Same X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=663693e3b761d72589c6344f11724c44fe11cb8e;p=openbsd Implement -w maxwait now that the -w flag is free in ping6. Same behaviour as ping(8). --- diff --git a/sbin/ping6/ping6.8 b/sbin/ping6/ping6.8 index 00065732f7a..b597b934602 100644 --- a/sbin/ping6/ping6.8 +++ b/sbin/ping6/ping6.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: ping6.8,v 1.56 2015/10/17 12:38:29 florian Exp $ +.\" $OpenBSD: ping6.8,v 1.57 2015/10/17 13:08:14 florian Exp $ .\" $KAME: ping6.8,v 1.57 2002/05/26 13:18:25 itojun Exp $ .\" .\" Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -46,6 +46,7 @@ .Op Fl p Ar pattern .Op Fl s Ar packetsize .Op Fl V Ar rtable +.Op Fl w Ar maxwait .Ar host .Sh DESCRIPTION .Nm @@ -201,8 +202,10 @@ Set the routing table to be used for outgoing packets. Verbose output. All ICMP packets that are received are listed. -.It Ar host -The IPv6 address of the final destination node. +.It Fl w Ar maxwait +Specifies the maximum number of seconds to wait for responses +after the last request has been sent. +The default is 10. .El .Pp When using diff --git a/sbin/ping6/ping6.c b/sbin/ping6/ping6.c index 0763b033e7e..c5cca98cc9b 100644 --- a/sbin/ping6/ping6.c +++ b/sbin/ping6/ping6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ping6.c,v 1.126 2015/10/17 13:07:02 florian Exp $ */ +/* $OpenBSD: ping6.c,v 1.127 2015/10/17 13:08:14 florian Exp $ */ /* $KAME: ping6.c,v 1.163 2002/10/25 02:19:06 itojun Exp $ */ /* @@ -128,6 +128,7 @@ struct payload { #define EXTRA 256 /* for AH and various other headers. weird. */ #define DEFDATALEN ICMP6ECHOTMLEN #define MAXDATALEN MAXPACKETLEN - IP6LEN - ICMP6ECHOLEN +#define MAXWAIT_DEFAULT 10 /* secs to wait for response */ #define A(bit) rcvd_tbl[(bit)>>3] /* identify byte in array */ #define B(bit) (1 << ((bit) & 0x07)) /* identify bit in byte */ @@ -180,6 +181,7 @@ struct timeval interval = {1, 0}; /* interval between packets */ /* timing */ int timing; /* flag to do timing */ +unsigned int maxwait = MAXWAIT_DEFAULT; /* max seconds to wait for response */ double tmin = 999999999.0; /* minimum round trip time */ double tmax = 0.0; /* maximum round trip time */ double tsum = 0.0; /* sum of all times, for doing average */ @@ -250,7 +252,7 @@ main(int argc, char *argv[]) preload = 0; datap = &outpack[ICMP6ECHOLEN + ICMP6ECHOTMLEN]; while ((ch = getopt(argc, argv, - "c:dEefg:Hh:I:i:l:mNnp:qS:s:vV:")) != -1) { + "c:dEefg:Hh:I:i:l:mNnp:qS:s:V:vw:")) != -1) { switch (ch) { case 'c': npackets = strtonum(optarg, 0, INT_MAX, &errstr); @@ -367,6 +369,12 @@ main(int argc, char *argv[]) case 'v': options |= F_VERBOSE; break; + case 'w': + maxwait = strtonum(optarg, 1, INT_MAX, &errstr); + if (errstr) + errx(1, "maxwait value is %s: %s", + errstr, optarg); + break; default: usage(); /*NOTREACHED*/ @@ -773,15 +781,14 @@ retransmit(void) /* * If we're not transmitting any more packets, change the timer * to wait two round-trip times if we've received any packets or - * ten seconds if we haven't. + * maxwait seconds if we haven't. */ -#define MAXWAIT 10 if (nreceived) { itimer.it_value.tv_sec = 2 * tmax / 1000; if (itimer.it_value.tv_sec == 0) itimer.it_value.tv_sec = 1; } else - itimer.it_value.tv_sec = MAXWAIT; + itimer.it_value.tv_sec = maxwait; itimer.it_interval.tv_sec = 0; itimer.it_interval.tv_usec = 0; itimer.it_value.tv_usec = 0; @@ -1651,6 +1658,6 @@ usage(void) "nqv" "] [-c count] [-g gateway]\n\t" "[-h hoplimit] [-I sourceaddr] [-i wait] [-l preload] [-p pattern]" - "\n\t[-s packetsize] [-V rtable] host\n"); + "\n\t[-s packetsize] [-V rtable] [-w maxwait] host\n"); exit(1); }