From bkogawa@foo.primenet.com  Sat Aug  2 16:26:24 1997
Received: from foo.primenet.com (ip208.sjc.primenet.com [206.165.96.208])
          by hub.freebsd.org (8.8.5/8.8.5) with ESMTP id QAA21455
          for <FreeBSD-gnats-submit@freebsd.org>; Sat, 2 Aug 1997 16:26:18 -0700 (PDT)
Received: (from bkogawa@localhost) by foo.primenet.com (8.8.6/8.6.12) id QAA05164; Sat, 2 Aug 1997 16:31:07 -0700 (PDT)
Message-Id: <199708022331.QAA05164@foo.primenet.com>
Date: Sat, 2 Aug 1997 16:31:07 -0700 (PDT)
From: bkogawa@primenet.com
Reply-To: bkogawa@primenet.com
To: FreeBSD-gnats-submit@freebsd.org
Subject: change in ping behavior: -c now counts _received_ packets
X-Send-Pr-Version: 3.2

>Number:         4218
>Category:       bin
>Synopsis:       change in ping behavior: -c now counts _received_ packets
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:
>Keywords:
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sat Aug  2 16:30:00 PDT 1997
>Closed-Date:    Sun Aug 3 04:53:56 PDT 1997
>Last-Modified:  Thu Aug  7 00:20:01 PDT 1997
>Originator:     Bryan K. Ogawa
>Release:        FreeBSD 2.2-STABLE i386
>Organization:
>Environment:

Using 2.2-stable as of August 1-2 with kernel from July 30.

>Description:

/sbin/ping -c <count> now pings until <count> pings are _received_,
not until <count> pings are sent.  This behavior is problematic if
you are using ping in scripts to test for a working network:
previously, you could supply a count to ping in a script, and expect
the script to return after a finite time, even if the network is
down--e.g.:

if ( ping -q -c 3 206.165.96.21 | grep " 0% packet loss" )
then
  echo network good
else
  echo network bad
fi

With ping's new behavior, however, this script will run forever if no
packets are received (e.g. in a network failure condition).

	

>How-To-Repeat:

Do a ping -c <count> <host> where the hostname is unreachable (e.g. no
route to host errors).  I presume this will also happen for hosts
which do not return ping packets, but I have not tested it.

	

>Fix:
	
	

Suggested, in order of preference:

(Is there a POSIX reason for the behavior?)

1.  Revert the -c behavior to count sent packets and add a new flag which
    counts only received packets.
2.  Add another flag which only counts sent packets.  
3.  Revert to the -c behavior, removing the current behavior.

>Release-Note:
>Audit-Trail:

From: j@uriah.heep.sax.de (J Wunsch)
To: bkogawa@primenet.com
Cc: FreeBSD-gnats-submit@FreeBSD.ORG
Subject: Re: bin/4218: change in ping behavior: -c now counts _received_ packets
Date: Sun, 3 Aug 1997 09:49:48 +0200

 As bkogawa@primenet.com wrote:
 
 > /sbin/ping -c <count> now pings until <count> pings are _received_,
 > not until <count> pings are sent.
 
 I agree that this behaviour is not what one would usually expect from
 -c, but it seems to be this way in all ping -c versions i've seen so
 far.
 
 What makes you think this has been changed recently?  You can easily
 verify in CVS that it has been this way all the time for FreeBSD, at
 least.  So, while you're constantly speaking about `reverting'
 something, there isn't really something to revert.  Implementing it as
 a count of _sent_ packets would be a plain paradigm change, so it
 should probably be done with a different option.
 
 SysV versions of ping indeed limit the number of sent packets, but
 they don't do it with -c.  They use a positional argument instead (and
 often have a different default semantics anyway).  HP/UX uses -n
 count, but (according to the man page) as a semi-positional argument.
 -n is already in use in BSD ping (with the consistent meaning for all
 network utilities: prevent DNS lookups).
 
 -- 
 cheers, J"org
 
 joerg_wunsch@uriah.heep.sax.de -- http://www.sax.de/~joerg/ -- NIC: JW11-RIPE
 Never trust an operating system you don't have sources for. ;-)

From: "Bryan K. Ogawa" <bkogawa@primenet.com>
To: Joerg Wunsch <joerg_wunsch@uriah.heep.sax.de>
Cc: FreeBSD-gnats-submit@FreeBSD.ORG
Subject: Re: bin/4218: change in ping behavior: -c now counts _received_ packets
Date: Sun, 3 Aug 1997 03:44:58 -0700 (PDT)

 On Sun, 3 Aug 1997, J Wunsch wrote:
 
 > As bkogawa@primenet.com wrote:
 > 
 > > /sbin/ping -c <count> now pings until <count> pings are _received_,
 > > not until <count> pings are sent.
 > 
 > I agree that this behaviour is not what one would usually expect from
 > -c, but it seems to be this way in all ping -c versions i've seen so
 > far.
 > 
 > What makes you think this has been changed recently?  You can easily
 > verify in CVS that it has been this way all the time for FreeBSD, at
 > least.  So, while you're constantly speaking about `reverting'
 > something, there isn't really something to revert.  Implementing it as
 > a count of _sent_ packets would be a plain paradigm change, so it
 > should probably be done with a different option.
 
 It looks like I was unknowingly depending on a longstanding bug fixed in
 2.2-STABLE.
 
 I just checked the version off of the 2.2.2 CD #2: it appears to count
 pings which error out with "No route to host" as being "received".  If I
 do "ping -q -c 3 206.165.5.104" with PPP off, it does 3 pings, gets 3
 "sendto: No route to host"s and then folds up and quits. 
 
 2.2-STABLE doesn't do this, matching the manpage (and apparently, the
 historically correct) behavior.
 
 If you'd like to downgrade to feature-request/close this one, please do,
 unless by some off chance it's _right_ to consider no route to host a
 reply being received.
 
 Thanks for taking the time to clear this up for me.
 
 bryan k ogawa  <bkogawa@primenet.com>   http://www.primenet.com/~bkogawa/
 
State-Changed-From-To: open->closed 
State-Changed-By: davidg 
State-Changed-When: Sun Aug 3 04:53:56 PDT 1997 
State-Changed-Why:  

Ping is working as it was intended. It does indeed wait for 
the received packets, but times out after a short period. 

From: j@uriah.heep.sax.de (J Wunsch)
To: freebsd-gnats-submit@freebsd.org
Cc:  Subject: bin/4218 [julian@FreeBSD.ORG: cvs commit: src/sbin/ping ping.c]
Date: Thu, 7 Aug 1997 08:40:22 +0200

 (Followup sent to GNATS so Bryan K. Ogawa gets notified, too.)
 
 -----Forwarded message from julian@FreeBSD.ORG (Julian Elischer)-----
 
 From: Julian Elischer <julian@FreeBSD.ORG>
 Date: Wed, 6 Aug 1997 19:41:16 -0700 (PDT)
 Message-Id: <199708070241.TAA11010@freefall.freebsd.org>
 To: cvs-committers@FreeBSD.ORG, cvs-all@FreeBSD.ORG, cvs-sbin@FreeBSD.ORG
 Subject: cvs commit: src/sbin/ping ping.c
 
 julian      1997/08/06 19:41:16 PDT
 
   Modified files:
     sbin/ping            ping.c 
   Log:
   don't lose track of how many packets we've sent
   if we get 'host unreachable'. (or any other errors than ENOBUFS)
   makes -c work again even if you can't get there..
   This really needs a rework..
   
   Revision  Changes    Path
   1.27      +3 -3      src/sbin/ping/ping.c
 
 -----End of forwarded message-----
 
 -- 
 cheers, J"org
 
 joerg_wunsch@uriah.heep.sax.de -- http://www.sax.de/~joerg/ -- NIC: JW11-RIPE
 Never trust an operating system you don't have sources for. ;-)
>Unformatted:
