summaryrefslogtreecommitdiffstats
path: root/sbin/ping6
diff options
context:
space:
mode:
authorhrs <hrs@FreeBSD.org>2014-10-17 09:33:09 +0000
committerhrs <hrs@FreeBSD.org>2014-10-17 09:33:09 +0000
commit0799e08a15f0c983ad8b41f1fb69eb4cb9d8ff21 (patch)
treecdcbf95bb696e9516798e5079850518e82b7fed1 /sbin/ping6
parent95ad85717f11ad1db7c1cdf5b70e6d7151d9e07c (diff)
downloadFreeBSD-src-0799e08a15f0c983ad8b41f1fb69eb4cb9d8ff21.zip
FreeBSD-src-0799e08a15f0c983ad8b41f1fb69eb4cb9d8ff21.tar.gz
Add -x waittime and -X timeout options for feature parity. These are
equivalent to -W and -t options of ping(8). Different letters are used because both have already been used for another purposes in ping6(8).
Diffstat (limited to 'sbin/ping6')
-rw-r--r--sbin/ping6/ping6.817
-rw-r--r--sbin/ping6/ping6.c55
2 files changed, 63 insertions, 9 deletions
diff --git a/sbin/ping6/ping6.8 b/sbin/ping6/ping6.8
index 60a6980..99111e2 100644
--- a/sbin/ping6/ping6.8
+++ b/sbin/ping6/ping6.8
@@ -29,7 +29,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd May 5, 2013
+.Dd September 22, 2014
.Dt PING6 8
.Os
.Sh NAME
@@ -65,6 +65,12 @@ packets to network hosts
.Op Fl i Ar wait
.Ek
.Bk -words
+.Op Fl x Ar waittime
+.Ek
+.Bk -words
+.Op Fl X Ar timeout
+.Ek
+.Bk -words
.Op Fl l Ar preload
.Ek
.Bk -words
@@ -191,6 +197,15 @@ The default is to wait for one second between each packet.
This option is incompatible with the
.Fl f
option.
+.It Fl x Ar waittime
+Time in milliseconds to wait for a reply for each packet sent.
+If a reply arrives later,
+the packet is not printed as replied,
+but considered as replied when calculating statistics.
+.It Fl X Ar timeout
+Specify a timeout,
+in seconds,
+before ping exits regardless of how many packets have been received.
.It Fl l Ar preload
If
.Ar preload
diff --git a/sbin/ping6/ping6.c b/sbin/ping6/ping6.c
index 14f689d..9ad285c 100644
--- a/sbin/ping6/ping6.c
+++ b/sbin/ping6/ping6.c
@@ -152,6 +152,8 @@ struct tv32 {
#define DEFDATALEN ICMP6ECHOTMLEN
#define MAXDATALEN MAXPACKETLEN - IP6LEN - ICMP6ECHOLEN
#define NROUTES 9 /* number of record route slots */
+#define MAXWAIT 10000 /* max ms to wait for response */
+#define MAXALARM (60 * 60) /* max seconds for alarm timeout */
#define A(bit) rcvd_tbl[(bit)>>3] /* identify byte in array */
#define B(bit) (1 << ((bit) & 0x07)) /* identify bit in byte */
@@ -188,6 +190,7 @@ struct tv32 {
#define F_MISSED 0x800000
#define F_DONTFRAG 0x1000000
#define F_NOUSERDATA (F_NODEADDR | F_FQDN | F_FQDNOLD | F_SUPTYPES)
+#define F_WAITTIME 0x2000000
u_int options;
#define IN6LEN sizeof(struct in6_addr)
@@ -228,6 +231,8 @@ long nreceived; /* # of packets we got back */
long nrepeats; /* number of duplicates */
long ntransmitted; /* sequence # for outbound packets = #sent */
int interval = 1000; /* interval between packets in ms */
+int waittime = MAXWAIT; /* timeout for each packet */
+long nrcvtimeout = 0; /* # of packets we got back after waittime */
/* timing */
int timing; /* flag to do timing */
@@ -312,6 +317,7 @@ main(int argc, char *argv[])
char *policy_out = NULL;
#endif
double t;
+ u_long alarmtimeout;
size_t rthlen;
#ifdef IPV6_USE_MIN_MTU
int mflag = 0;
@@ -321,7 +327,7 @@ main(int argc, char *argv[])
memset(&smsghdr, 0, sizeof(smsghdr));
memset(&smsgiov, 0, sizeof(smsgiov));
- preload = 0;
+ alarmtimeout = preload = 0;
datap = &outpack[ICMP6ECHOLEN + ICMP6ECHOTMLEN];
#ifndef IPSEC
#define ADDOPTS
@@ -333,7 +339,7 @@ main(int argc, char *argv[])
#endif /*IPSEC_POLICY_IPSEC*/
#endif
while ((ch = getopt(argc, argv,
- "a:b:c:DdfHg:h:I:i:l:mnNop:qrRS:s:tvwW" ADDOPTS)) != -1) {
+ "a:b:c:DdfHg:h:I:i:l:mnNop:qrRS:s:tvwWx:X:" ADDOPTS)) != -1) {
#undef ADDOPTS
switch (ch) {
case 'a':
@@ -541,6 +547,24 @@ main(int argc, char *argv[])
options &= ~F_NOUSERDATA;
options |= F_FQDNOLD;
break;
+ case 'x':
+ t = strtod(optarg, &e);
+ if (*e || e == optarg || t > (double)INT_MAX)
+ err(EX_USAGE, "invalid timing interval: `%s'",
+ optarg);
+ options |= F_WAITTIME;
+ waittime = (int)t;
+ break;
+ case 'X':
+ alarmtimeout = strtoul(optarg, &e, 0);
+ if ((alarmtimeout < 1) || (alarmtimeout == ULONG_MAX))
+ errx(EX_USAGE, "invalid timeout: `%s'",
+ optarg);
+ if (alarmtimeout > MAXALARM)
+ errx(EX_USAGE, "invalid timeout: `%s' > %d",
+ optarg, MAXALARM);
+ alarm((int)alarmtimeout);
+ break;
#ifdef IPSEC
#ifdef IPSEC_POLICY_IPSEC
case 'P':
@@ -1057,6 +1081,10 @@ main(int argc, char *argv[])
err(EX_OSERR, "sigaction SIGINFO");
seeninfo = 0;
#endif
+ if (alarmtimeout > 0) {
+ if (sigaction(SIGALRM, &si_sa, 0) == -1)
+ err(EX_OSERR, "sigaction SIGALRM");
+ }
if (options & F_FLOOD) {
intvl.tv_sec = 0;
intvl.tv_usec = 10000;
@@ -1157,17 +1185,18 @@ main(int argc, char *argv[])
/*
* 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.
+ * if we've received any packets or (waittime)
+ * milliseconds if we haven't.
*/
-#define MAXWAIT 10
intvl.tv_usec = 0;
if (nreceived) {
intvl.tv_sec = 2 * tmax / 1000;
if (intvl.tv_sec == 0)
intvl.tv_sec = 1;
- } else
- intvl.tv_sec = MAXWAIT;
+ } else {
+ intvl.tv_sec = waittime / 1000;
+ intvl.tv_usec = waittime % 1000 * 1000;
+ }
}
gettimeofday(&last, NULL);
if (ntransmitted - nreceived - 1 > nmissedmax) {
@@ -1181,6 +1210,7 @@ main(int argc, char *argv[])
si_sa.sa_flags = 0;
si_sa.sa_handler = SIG_IGN;
sigaction(SIGINT, &si_sa, 0);
+ sigaction(SIGALRM, &si_sa, 0);
summary();
if (res != NULL)
@@ -1198,6 +1228,7 @@ onsignal(int sig)
switch (sig) {
case SIGINT:
+ case SIGALRM:
seenint++;
break;
#ifdef SIGINFO
@@ -1521,6 +1552,11 @@ pr_pack(u_char *buf, int cc, struct msghdr *mhdr)
if (options & F_QUIET)
return;
+ if (options & F_WAITTIME && triptime > waittime) {
+ ++nrcvtimeout;
+ return;
+ }
+
if (options & F_FLOOD)
(void)write(STDOUT_FILENO, &BSPACE, 1);
else {
@@ -2216,6 +2252,8 @@ summary(void)
((((double)ntransmitted - nreceived) * 100.0) /
ntransmitted));
}
+ if (nrcvtimeout)
+ printf(", %ld packets out of wait time", nrcvtimeout);
(void)putchar('\n');
if (nreceived && timing) {
/* Only display average to microseconds */
@@ -2741,6 +2779,7 @@ usage(void)
#endif
"\n"
" [-p pattern] [-S sourceaddr] [-s packetsize] "
- "[hops ...] host\n");
+ "[-x waittime]\n"
+ " [-X timeout] [hops ...] host\n");
exit(1);
}
OpenPOWER on IntegriCloud