summaryrefslogtreecommitdiffstats
path: root/sbin/ping/ping.c
diff options
context:
space:
mode:
authordd <dd@FreeBSD.org>2002-10-02 03:24:27 +0000
committerdd <dd@FreeBSD.org>2002-10-02 03:24:27 +0000
commite49b56bfca88ba96da91bc14f9dfc149741da965 (patch)
treee57064d8a849900780d05e95486ed114ebe853dc /sbin/ping/ping.c
parent4be0d09ad35a2492cce9a9a891c2c800ad5c9669 (diff)
downloadFreeBSD-src-e49b56bfca88ba96da91bc14f9dfc149741da965.zip
FreeBSD-src-e49b56bfca88ba96da91bc14f9dfc149741da965.tar.gz
Add an -o option to exit after receiving one reply. This can be used
to test whether a link is live. PR: 38573 Submitted by: David Taylor <davidt@yadt.co.uk> Obtained from: NetBSD
Diffstat (limited to 'sbin/ping/ping.c')
-rw-r--r--sbin/ping/ping.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/sbin/ping/ping.c b/sbin/ping/ping.c
index ca7a69b..99a4c0e 100644
--- a/sbin/ping/ping.c
+++ b/sbin/ping/ping.c
@@ -137,6 +137,7 @@ int options;
#endif /*IPSEC*/
#define F_TTL 0x8000
#define F_MISSED 0x10000
+#define F_ONCE 0x20000
/*
* MAX_DUP_CHK is the number of bits in received table, i.e. the maximum
@@ -242,7 +243,7 @@ main(argc, argv)
datap = &outpack[MINICMPLEN + PHDR_LEN];
while ((ch = getopt(argc, argv,
- "AI:LQRS:T:c:adfi:l:m:np:qrs:t:v"
+ "AI:LQRS:T:c:adfi:l:m:nop:qrs:t:v"
#ifdef IPSEC
#ifdef IPSEC_POLICY_IPSEC
"P:"
@@ -320,6 +321,9 @@ main(argc, argv)
case 'n':
options |= F_NUMERIC;
break;
+ case 'o':
+ options |= F_ONCE;
+ break;
case 'p': /* fill buffer with user pattern */
options |= F_PINGFILLED;
fill((char *)datap, optarg);
@@ -696,7 +700,8 @@ main(argc, argv)
t = &now;
}
pr_pack((char *)packet, cc, &from, t);
- if (npackets && nreceived >= npackets)
+ if (options & F_ONCE && nreceived ||
+ npackets && nreceived >= npackets)
break;
}
if (n == 0 || options & F_FLOOD) {
@@ -1441,7 +1446,7 @@ static void
usage()
{
(void)fprintf(stderr, "%s\n%s\n%s\n",
-"usage: ping [-AQRadfnqrv] [-c count] [-i wait] [-l preload] [-m ttl]",
+"usage: ping [-AQRadfnoqrv] [-c count] [-i wait] [-l preload] [-m ttl]",
" [-p pattern] "
#ifdef IPSEC
#ifdef IPSEC_POLICY_IPSEC
OpenPOWER on IntegriCloud