From owner-freebsd-bugs Sun May 26 8:50:25 2002 Delivered-To: freebsd-bugs@hub.freebsd.org Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21]) by hub.freebsd.org (Postfix) with ESMTP id 13FDF37B407 for ; Sun, 26 May 2002 08:50:02 -0700 (PDT) Received: (from gnats@localhost) by freefall.freebsd.org (8.11.6/8.11.6) id g4QFo2J60079; Sun, 26 May 2002 08:50:02 -0700 (PDT) (envelope-from gnats) Received: from mail.yadt.co.uk (yadt.demon.co.uk [158.152.4.134]) by hub.freebsd.org (Postfix) with SMTP id B9BA437B446 for ; Sun, 26 May 2002 08:49:05 -0700 (PDT) Received: (qmail 97649 invoked from network); 26 May 2002 15:49:03 -0000 Received: from unknown (HELO mail.gattaca.yadt.co.uk) (qmailr@10.0.0.2) by yadt.demon.co.uk with SMTP; 26 May 2002 15:49:03 -0000 Received: (qmail 26858 invoked by uid 1000); 26 May 2002 15:49:02 -0000 Message-Id: <20020526154902.26857.qmail@gattaca.yadt.co.uk> Date: 26 May 2002 15:49:02 -0000 From: David Taylor Reply-To: David Taylor To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Subject: bin/38573: ping -o option (exit after one reply) Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org >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