From owner-freebsd-bugs Wed Nov 28 8:50:36 2001 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 288D037B41E for ; Wed, 28 Nov 2001 08:50:05 -0800 (PST) Received: (from gnats@localhost) by freefall.freebsd.org (8.11.6/8.11.6) id fASGo5c68419; Wed, 28 Nov 2001 08:50:05 -0800 (PST) (envelope-from gnats) Date: Wed, 28 Nov 2001 08:50:05 -0800 (PST) Message-Id: <200111281650.fASGo5c68419@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org Cc: From: Ruslan Ermilov Subject: Re: bin/32354: ping -c 0 Reply-To: Ruslan Ermilov 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 The following reply was made to PR bin/32354; it has been noted by GNATS. From: Ruslan Ermilov To: root@topcat.zoonami.com, djones@zoonami.com, setantae , Peter Pentchev Cc: bug-followup@FreeBSD.org Subject: Re: bin/32354: ping -c 0 Date: Wed, 28 Nov 2001 18:47:44 +0200 On Wed, Nov 28, 2001 at 08:10:02AM -0800, setantae wrote: > On Wed, Nov 28, 2001 at 03:47:23PM +0000, djones@zoonami.com wrote: > > At the command line: > > > > # ping -l 5 -c 0 gateway > > > > yields the error: > > > > ping: invalid count of packets to transmit: `0' > > > > whereas in this case I think -c 0 specifies something reasonable: > > Send 5 packets as quickly as possible, then no more, then exit. > > It doesn't though, does it ? > > -c count > Stop after sending (and receiving) count ECHO_RESPONSE packets. > > I think you'd be after : > > rhadamanth# ping -l 5 -c 5 archaia > PING archaia.private.submonkey.net. (192.168.10.2): 56 data bytes > 64 bytes from 192.168.10.2: icmp_seq=0 ttl=255 time=1.387 ms > 64 bytes from 192.168.10.2: icmp_seq=1 ttl=255 time=1.566 ms > 64 bytes from 192.168.10.2: icmp_seq=2 ttl=255 time=1.882 ms > 64 bytes from 192.168.10.2: icmp_seq=3 ttl=255 time=2.110 ms > 64 bytes from 192.168.10.2: icmp_seq=4 ttl=255 time=2.406 ms > > --- archaia.private.submonkey.net. ping statistics --- > 6 packets transmitted, 5 packets received, 16% packet loss > round-trip min/avg/max/stddev = 1.387/1.870/2.406/0.366 ms > rhadamanth# > While the above is true, that the -c limits the total number of packets ping(8) sends, there's still some weirdness in the ping operation. In the output above, note that it sends 6 packets instead of 5. Also, if -l operand is greater than -c, it sends (l + 1) packets, where it should have sent exactly "c" packets. Also, if -c was not specified (or greater than -l), ping sends (l + 1) packets "as fast as possible", instead of documented "l". The following patch fixes all these problems. Please test. Index: ping.c =================================================================== RCS file: /home/ncvs/src/sbin/ping/ping.c,v retrieving revision 1.52.2.8 diff -u -p -r1.52.2.8 ping.c --- ping.c 2001/10/02 15:56:03 1.52.2.8 +++ ping.c 2001/11/28 16:39:14 @@ -620,6 +620,10 @@ main(argc, argv) tcsetattr(STDOUT_FILENO, TCSANOW, &ts); } + if (npackets && preload > npackets) + preload = npackets; + if (preload) /* we send the last ping below */ + --preload; while (preload--) /* fire off them quickies */ pinger(); Cheers, -- Ruslan Ermilov Oracle Developer/DBA, ru@sunbay.com Sunbay Software AG, ru@FreeBSD.org FreeBSD committer, +380.652.512.251 Simferopol, Ukraine http://www.FreeBSD.org The Power To Serve http://www.oracle.com Enabling The Information Age To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message