Date: 26 May 2002 15:49:02 -0000 From: David Taylor <davidt@yadt.co.uk> To: FreeBSD-gnats-submit@FreeBSD.org Subject: bin/38573: ping -o option (exit after one reply) Message-ID: <20020526154902.26857.qmail@gattaca.yadt.co.uk>
next in thread | raw e-mail | index | archive | help
>Number: 38573 >Category: bin >Synopsis: ping -o option (exit after one reply) >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: update >Submitter-Id: current-users >Arrival-Date: Sun May 26 08:50:01 PDT 2002 >Closed-Date: >Last-Modified: >Originator: David Taylor >Release: FreeBSD 5.0-CURRENT i386 >Organization: >Environment: System: FreeBSD gattaca.yadt.co.uk 5.0-CURRENT FreeBSD 5.0-CURRENT #7: Tue Feb 12 22:04:28 GMT 2002 root@:/usr/obj/usr/src/sys/GATTACA i386 >Description: Whilst trying to make a script written for NetBSD run on FreeBSD, I discovered the script used a non-existant (on FreeBSD) ping option ``-o''. ping -o will exit after receiving a single reply packet, which is useful for trying to see if a host/link is alive at all (which is what the script was attempting to to do :). I checked cvsweb, and discovered the changes required to implement -o were pretty simple, so created the patch below, and decided it might be useful to the FreeBSD community. >How-To-Repeat: N/A >Fix: --- ping_o_option.diff begins here --- Index: ping.8 =================================================================== RCS file: /usr/ncvs/src/sbin/ping/ping.8,v retrieving revision 1.34 diff -u -r1.34 ping.8 --- ping.8 7 Feb 2002 16:47:22 -0000 1.34 +++ ping.8 26 May 2002 15:36:23 -0000 @@ -42,7 +42,7 @@ packets to network hosts .Sh SYNOPSIS .Nm -.Op Fl AQRadfnqrv +.Op Fl AQRadfnoqrv .Op Fl c Ar count .Op Fl i Ar wait .Op Fl l Ar preload @@ -159,6 +159,8 @@ .It Fl n Numeric output only. No attempt will be made to lookup symbolic names for host addresses. +.It Fl o +Exit successfully after receiving one reply packet. .It Fl p Ar pattern You may specify up to 16 .Dq pad Index: ping.c =================================================================== RCS file: /usr/ncvs/src/sbin/ping/ping.c,v retrieving revision 1.66 diff -u -r1.66 ping.c --- ping.c 2 Apr 2002 10:15:32 -0000 1.66 +++ ping.c 26 May 2002 15:38:49 -0000 @@ -136,6 +136,7 @@ #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 @@ -241,7 +242,7 @@ datap = &outpack[8 + 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:" @@ -319,6 +320,9 @@ 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); @@ -687,7 +691,8 @@ 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) { @@ -1444,7 +1449,7 @@ usage() { (void)fprintf(stderr, "%s\n%s\n%s\n", -"usage: ping [-QRadfnqrv] [-c count] [-i wait] [-l preload] [-m ttl]", +"usage: ping [-QRadfnoqrv] [-c count] [-i wait] [-l preload] [-m ttl]", " [-p pattern] " #ifdef IPSEC #ifdef IPSEC_POLICY_IPSEC --- ping_o_option.diff ends here --- >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020526154902.26857.qmail>