Subject: bin/3329: enhancement for ping
To: None <gnats-bugs@gnats.netbsd.org>
From: David Jones <dej@inode.org>
List: netbsd-bugs
Date: 03/13/1997 16:58:17
>Number: 3329
>Category: bin
>Synopsis: enhancement for ping
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: bin-bug-people (Utility Bug People)
>State: open
>Class: change-request
>Submitter-Id: net
>Arrival-Date: Thu Mar 13 17:20:02 1997
>Last-Modified:
>Originator: David Jones
>Organization:
INODE Community Networking
>Release: 1.2
>Environment:
System: NetBSD qpoint 1.2 NetBSD 1.2 (GENERIC) #0: Thu Sep 26 10:27:49 EDT 1996 chopps@water.emich.edu:/exp/NetBSD/NetBSD-1-2/src/sys/arch/amiga/compile/GENERIC amiga
>Description:
ping can be used in a link-integrity check application - it can return
a status code to a script if a link is down, and the script can attempt
to re-establish a downed link. However, with the -c option, ping will
send ALL requested packets, even if the link is up.
This patch adds the "-o" option: exit upon receiving the first valid
ICMP reply. So:
ping -o -c 10 otherend.net
will send up to 10 ICMP requests, and exit upon receiving first reply.
In practice, the reply will come back before the second request goes out,
so traffic on the link is minimized. However, if the link is slow,
ping will still try for up to 10 seconds to discover some sign of life.
>How-To-Repeat:
n/a
>Fix:
*** /mnt/netbsd/src/src/sbin/ping/ping.c Thu Nov 7 07:14:23 1996
--- ping.c Sun Feb 16 18:02:30 1997
***************
*** 115,120 ****
--- 115,121 ----
#define F_SO_DONTROUTE 0x080
#define F_VERBOSE 0x100
#define F_SADDR 0x200
+ #define F_ONCE 0x400
/* multicast options */
int moptions;
***************
*** 189,195 ****
preload = 0;
datap = &outpack[8 + sizeof(struct timeval)];
! while ((ch = getopt(argc, argv, "I:LRS:c:dfh:i:l:np:qrs:t:vw:")) != EOF)
switch(ch) {
case 'c':
npackets = atoi(optarg);
--- 190,196 ----
preload = 0;
datap = &outpack[8 + sizeof(struct timeval)];
! while ((ch = getopt(argc, argv, "I:LRS:c:dfh:i:l:nop:qrs:t:vw:")) != EOF)
switch(ch) {
case 'c':
npackets = atoi(optarg);
***************
*** 229,234 ****
--- 230,238 ----
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);
***************
*** 416,421 ****
--- 420,427 ----
}
pr_pack((char *)packet, cc, &from);
if (npackets && nreceived >= npackets)
+ break;
+ if (nreceived > 0 && (options & F_ONCE))
break;
}
finish();
>Audit-Trail:
>Unformatted: