summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sbin/ping/ping.83
-rw-r--r--sbin/ping/ping.c19
2 files changed, 18 insertions, 4 deletions
diff --git a/sbin/ping/ping.8 b/sbin/ping/ping.8
index fca80ac..813381c 100644
--- a/sbin/ping/ping.8
+++ b/sbin/ping/ping.8
@@ -219,6 +219,9 @@ force the source address to be something other than the IP address
of the interface the probe packet is sent on. If the IP address
is not one of this machine's interface addresses, an error is
returned and nothing is sent.
+.It Fl t Ar timeout
+Specify a timeout, in seconds, before ping exits regardless of how
+many packets have been recieved.
.It Fl T Ar ttl
Set the IP Time To Live for multicasted packets.
This flag only applies if the ping destination is a multicast address.
diff --git a/sbin/ping/ping.c b/sbin/ping/ping.c
index 15bac46..074f367 100644
--- a/sbin/ping/ping.c
+++ b/sbin/ping/ping.c
@@ -217,6 +217,7 @@ main(argc, argv)
char *policy_in = NULL;
char *policy_out = NULL;
#endif
+ int alarmtimeout = 0;
/*
* Do the stuff that we need root priv's for *first*, and
@@ -233,10 +234,10 @@ main(argc, argv)
datap = &outpack[8 + PHDR_LEN];
#ifndef IPSEC
- while ((ch = getopt(argc, argv, "I:LQRT:c:adfi:l:np:qrs:v")) != -1)
+ while ((ch = getopt(argc, argv, "I:LQRT:c:adfi:l:np:qrs:t:v")) != -1)
#else
#ifdef IPSEC_POLICY_IPSEC
- while ((ch = getopt(argc, argv, "I:LQRT:c:adfi:l:np:qrs:vP:")) != -1)
+ while ((ch = getopt(argc, argv, "I:LQRT:c:adfi:l:np:qrs:t:vP:")) != -1)
#endif /*IPSEC_POLICY_IPSEC*/
#endif
{
@@ -340,6 +341,13 @@ main(argc, argv)
case 'S':
source = optarg;
break;
+ case 't':
+ alarmtimeout = (int)strtoul(optarg, &ep, 0);
+ if (alarmtimeout < 1)
+ errx(EX_USAGE, "invalid timeout: `%s'",
+ optarg);
+ alarm(alarmtimeout);
+ break;
case 'T': /* multicast TTL */
ultmp = strtoul(optarg, &ep, 0);
if (*ep || ep == optarg || ultmp > 255)
@@ -558,6 +566,9 @@ main(argc, argv)
if (sigaction(SIGINFO, &si_sa, 0) == -1) {
err(EX_OSERR, "sigaction");
}
+ si_sa.sa_handler = stopit;
+ if (sigaction(SIGALRM, &si_sa, 0) == -1)
+ err(EX_OSERR, "sigaction SIGALRM");
bzero(&msg, sizeof(msg));
msg.msg_name = (caddr_t)&from;
@@ -1391,7 +1402,7 @@ usage()
"[-P policy] "
#endif
#endif
-"[-s packetsize] [-S src_addr]",
- "[host | [-L] [-I iface] [-T ttl] mcast-group]");
+"[-s packetsize] [-S src_addr] [-t timeout]",
+" [host | [-L] [-I iface] [-T ttl] mcast-group]");
exit(EX_USAGE);
}
OpenPOWER on IntegriCloud