From djones@zoonami.com  Wed Nov 28 07:46:01 2001
Return-Path: <djones@zoonami.com>
Received: from topcat.zoonami.com (topcat.zoonami.com [193.112.141.198])
	by hub.freebsd.org (Postfix) with ESMTP id 0073E37B405
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 28 Nov 2001 07:46:00 -0800 (PST)
Received: (from root@localhost)
	by topcat.zoonami.com (8.11.3/8.11.3) id fASFlNM33441;
	Wed, 28 Nov 2001 15:47:23 GMT
	(envelope-from djones)
Message-Id: <200111281547.fASFlNM33441@topcat.zoonami.com>
Date: Wed, 28 Nov 2001 15:47:23 GMT
From: djones@zoonami.com
Reply-To: root@topcat.zoonami.com
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: ping -c 0
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         32354
>Category:       bin
>Synopsis:       # "ping -l 5 -c 0 gateway", slightly unreasonably, gives an error.
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    ru
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Wed Nov 28 07:50:01 PST 2001
>Closed-Date:    Fri Feb 1 00:30:56 PST 2002
>Last-Modified:  Fri Feb 01 00:35:01 PST 2002
>Originator:     David Jones
>Release:        FreeBSD 4.3-RELEASE i386
>Organization:
Zoonami Limited
>Environment:
System: FreeBSD topcat.zoonami.com 4.3-RELEASE FreeBSD 4.3-RELEASE #0: Thu Nov 1 14:13:13 GMT 2001 root@topcat.zoonami.com:/usr/src/sys/compile/GENERIC i386


>Description:
  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.

Perhaps it could be changed to accept -c 0 if -l has been used?

>How-To-Repeat:
  as above
>Fix:
  later

>Release-Note:
>Audit-Trail:

From: setantae <setantae@submonkey.net>
To: root@topcat.zoonami.com
Cc: FreeBSD-gnats-submit@freebsd.org
Subject: Re: bin/32354: ping -c 0
Date: Wed, 28 Nov 2001 16:02:34 +0000

 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#
 
 Ceri

From: Peter Pentchev <roam@ringlet.net>
To: root@topcat.zoonami.com
Cc: FreeBSD-gnats-submit@freebsd.org
Subject: Re: bin/32354: ping -c 0
Date: Wed, 28 Nov 2001 18:02:28 +0200

 On Wed, Nov 28, 2001 at 03:47:23PM +0000, djones@zoonami.com wrote:
 > 
 > >Number:         32354
 > >Category:       bin
 > >Synopsis:       # "ping -l 5 -c 0 gateway", slightly unreasonably, gives an error.
 > >Originator:     David Jones
 > >Release:        FreeBSD 4.3-RELEASE i386
 > >Organization:
 > Zoonami Limited
 > >Environment:
 > System: FreeBSD topcat.zoonami.com 4.3-RELEASE FreeBSD 4.3-RELEASE #0: Thu Nov 1 14:13:13 GMT 2001 root@topcat.zoonami.com:/usr/src/sys/compile/GENERIC i386
 > 
 > 
 > >Description:
 >   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.
 > 
 > Perhaps it could be changed to accept -c 0 if -l has been used?
 
 'c' specifies the *total* number of packets to send.
 Try ping -l 5 -c 5 gateway, then try ping -l 5 -c 8 gateway.
 
 G'luck,
 Peter
 
 -- 
 If I were you, who would be reading this sentence?
State-Changed-From-To: open->feedback 
State-Changed-By: roam 
State-Changed-When: Wed Nov 28 08:11:24 PST 2001 
State-Changed-Why:  
Is 'ping -l 5 -c 5' what you are looking for? 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=32354 
State-Changed-From-To: feedback->closed 
State-Changed-By: roam 
State-Changed-When: Wed Nov 28 08:36:33 PST 2001 
State-Changed-Why:  
The submitter is satisfied with -l 5 -c 5 :) 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=32354 

From: "Alexey V. Neyman" <alex.neyman@auriga.ru>
To: setantae <setantae@submonkey.net>, bug-followup@FreeBSD.org,
	roam@ringlet.net
Cc:  
Subject: Re: bin/32354: ping -c 0
Date: Wed, 28 Nov 2001 19:43:37 +0300

 hi, there!
 
 On 28 November 2001 19:10, setantae wrote:
 >  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
 Doesn't the line above warn you?
 It says that it has transmitted 6 (not 5, as it was requested) packets - an 
 thus disobeys its orders :)
 
 IMO this should be in ping.c:
 
 --- ping.c   Tue Oct 30 17:08:33 2001
 +++ ping.c   Wed Nov 28 22:36:10 2001
 @@ -397,6 +397,9 @@
                 }
         }
  
 +       if (preload > npackets)
 +               errx(EX_USAGE, "preload(%d) > count(%ld)", preload, npackets);
 +
         if (argc - optind != 1)
                 usage();
         target = argv[optind];
 @@ -631,8 +634,10 @@
                 intvl.tv_usec = interval % 1000 * 1000;
         }
  
 -       pinger();                       /* send the first ping */
 -       (void)gettimeofday(&last, NULL);
 +       if (ntransmitted < npackets) {
 +               pinger();                       /* send the first ping */
 +               (void)gettimeofday(&last, NULL);
 +       }
  
         while (!finish_up) {
                 register int cc;
 
 <------------------------->
  ) May the Sun and Water (   Regards, Alexey V. Neyman
  ) always fall upon you! (   mailto:alex.neyman@auriga.ru
 <------------------------->

From: Ruslan Ermilov <ru@FreeBSD.org>
To: root@topcat.zoonami.com, djones@zoonami.com,
	setantae <setantae@submonkey.net>, Peter Pentchev <roam@FreeBSD.org>
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
State-Changed-From-To: closed->analyzed 
State-Changed-By: roam 
State-Changed-When: Wed Nov 28 08:52:02 PST 2001 
State-Changed-Why:  
OK, it seems that I was too quick. 
There is another problem with ping's handling of -l. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=32354 
Responsible-Changed-From-To: freebsd-bugs->ru 
Responsible-Changed-By: ru 
Responsible-Changed-When: Wed Nov 28 08:53:17 PST 2001 
Responsible-Changed-Why:  
I have a patch. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=32354 

From: "Alexey V. Neyman" <alex.neyman@auriga.ru>
To: bug-followup@FreeBSD.org, root@topcat.zoonami.com, ru@FreeBSD.org
Cc:  
Subject: Re: bin/32354: # "ping -l 5 -c 0 gateway", slightly unreasonably, gives an error.
Date: Wed, 28 Nov 2001 20:13:03 +0300

 hi, there!
 
 On Wed, 28 Nov 2001 18:47:44, ru@FreeBSD.org wrote:
 
 >+      if (npackets && preload > npackets)
 >+              preload = npackets;
 
 I just think that silently dropping erroneous user input is not RightThing.
 IMHO better way would be complain about preload > npackets.
 Save this, it fixes forementioned problems.
 
 A minor nit: it'd be a bit more effective to
 
 while (--preload > 0)
 	pinger();
 
 instead of
 
 if (preload)
 	--preload;
 while (preload--)
 	pinger();
 
 Regards,
 Alexey.
 
 -- 
 <------------------------->
  ) May the Sun and Water (   Regards, Alexey V. Neyman
  ) always fall upon you! (   mailto:alex.neyman@auriga.ru
 <------------------------->

From: Ruslan Ermilov <ru@FreeBSD.org>
To: "Alexey V. Neyman" <alex.neyman@auriga.ru>
Cc: bug-followup@FreeBSD.org, root@topcat.zoonami.com
Subject: Re: bin/32354: # "ping -l 5 -c 0 gateway", slightly unreasonably, gives an error.
Date: Wed, 28 Nov 2001 19:53:25 +0200

 On Wed, Nov 28, 2001 at 08:13:03PM +0300, Alexey V. Neyman wrote:
 > hi, there!
 > 
 > On Wed, 28 Nov 2001 18:47:44, ru@FreeBSD.org wrote:
 > 
 > >+      if (npackets && preload > npackets)
 > >+              preload = npackets;
 > 
 > I just think that silently dropping erroneous user input is not RightThing.
 > IMHO better way would be complain about preload > npackets.
 > Save this, it fixes forementioned problems.
 > 
 It may be not the right thing, but it's against POLA.  It worked before,
 why it should stop working now?  It may upset some people or scripts.
 
 > A minor nit: it'd be a bit more effective to
 > 
 > while (--preload > 0)
 > 	pinger();
 > 
 > instead of
 > 
 > if (preload)
 > 	--preload;
 > while (preload--)
 > 	pinger();
 > 
 Yeah, and one day someone changes the type of "preload" to unsigned,
 this will screw up the whole thing.  :-)
 
 
 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

From: "Alexey V. Neyman" <alex.neyman@auriga.ru>
To: Ruslan Ermilov <ru@FreeBSD.org>, bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/32354: # "ping -l 5 -c 0 gateway", slightly unreasonably, gives an error.
Date: Thu, 29 Nov 2001 00:51:48 +0300

 hi, there!
 
 When fixing this, don't forget about src/sbin/ping6/ping6.c - it seems 
 subject to the same case.
 
 Regards,
 Alexey.
State-Changed-From-To: analyzed->feedback 
State-Changed-By: ru 
State-Changed-When: Mon Jan 14 06:34:05 PST 2002 
State-Changed-Why:  
Fix committed into 5.0-CURRENT (src/sbin/ping/ping.c,v 1.61). 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=32354 
State-Changed-From-To: feedback->closed 
State-Changed-By: ru 
State-Changed-When: Fri Feb 1 00:30:56 PST 2002 
State-Changed-Why:  
Fixed in RELENG_4 in the following files/revisions: 

sbin/ping/ping.c,v 1.52.2.9 
sbin/ping6/ping6.c,v 1.4.2.7 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=32354 
>Unformatted:
