| Summary: | # "ping -l 5 -c 0 gateway", slightly unreasonably, gives an error. | ||
|---|---|---|---|
| Product: | Base System | Reporter: | David Jones <djones> |
| Component: | bin | Assignee: | ru <ru> |
| Status: | Closed FIXED | ||
| Severity: | Affects Only Me | ||
| Priority: | Normal | ||
| Version: | 4.3-RELEASE | ||
| Hardware: | Any | ||
| OS: | Any | ||
|
Description
David Jones
2001-11-28 15:50:01 UTC
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? 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 State Changed From-To: open->feedback Is 'ping -l 5 -c 5' what you are looking for? State Changed From-To: feedback->closed The submitter is satisfied with -l 5 -c 5 :) 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 <-------------------------> 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 OK, it seems that I was too quick. There is another problem with ping's handling of -l. Responsible Changed From-To: freebsd-bugs->ru I have a patch. 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 <-------------------------> 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 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 Fix committed into 5.0-CURRENT (src/sbin/ping/ping.c,v 1.61). State Changed From-To: feedback->closed 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 |