NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

bin/55754: Exit value of ping6 does not match documentation



>Number:         55754
>Category:       bin
>Synopsis:       ping6 -c 2 -o -X 5 xxx returns error even when host is up
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Oct 26 12:25:00 +0000 2020
>Originator:     Tero Kivinen
>Release:        NetBSD 8.1_STABLE
>Organization:
>Environment:
System: NetBSD fireball.acr.fi 8.1_STABLE NetBSD 8.1_STABLE (FIREBALL) #0: Sat Nov 2 01:30:24 EET 2019 root%fireball.acr.fi@localhost:/usr/obj/sys/arch/amd64/compile/FIREBALL amd64
Architecture: x86_64
Machine: amd64
>Description:

Running command ping6 -c 2 -o -X 5 will exit with non-zero exit status:
----------------------------------------------------------------------
$ ping6 -c 2 -o -X 5 netbsd.org
PING6(56=40+8+8 bytes) 2a0b:5c81:1c1::34 --> 2001:470:a085:999::80
16 bytes from 2001:470:a085:999::80, icmp_seq=0 hlim=52 time=163.276 ms

--- netbsd.org ping6 statistics ---
1 packets transmitted, 1 packets received, 0.0% packet loss
round-trip min/avg/max/std-dev = 163.276/163.276/163.276/0.000 ms
$ echo $?
1
----------------------------------------------------------------------

The man ping6 says:

----------------------------------------------------------------------
...
     -o      Exit successfully after receiving one reply packet.
...
EXIT STATUS
     ping6 exits with 0 on success (the host is alive), and non-zero if the
     arguments are incorrect or the host is not responding.
...
----------------------------------------------------------------------

Ping (ipv4 version of ping6) works like that, i.e., if any packets are
received then it exits with status 0, and it only exits with non-zero
error status if no packets are received.

>How-To-Repeat:


Try

$ ping6 -c -o -X 5 netbsd.org

and it will return with non-zero exit status. If you leave out -o
option and all requests do get reply then it will exit with zero exit
status:
----------------------------------------------------------------------
$ ping6 -c 2 -X 5 netbsd.org
PING6(56=40+8+8 bytes) 2a0b:5c81:1c1::34 --> 2001:470:a085:999::80
16 bytes from 2001:470:a085:999::80, icmp_seq=0 hlim=52 time=165.436 ms
16 bytes from 2001:470:a085:999::80, icmp_seq=1 hlim=52 time=163.565 ms

--- netbsd.org ping6 statistics ---
2 packets transmitted, 2 packets received, 0.0% packet loss
round-trip min/avg/max/std-dev = 163.565/164.500/165.436/1.323 ms
$ echo $?
0
----------------------------------------------------------------------

IPv4 ping does return zero exits status as long as it gets at least one packet in: 
----------------------------------------------------------------------
$ ping -c 2 -o -w 5 netbsd.org
PING netbsd.org (199.233.217.205): 56 data bytes
64 bytes from 199.233.217.205: icmp_seq=0 ttl=244 time=167.652238 ms

----netbsd.org PING Statistics----
1 packets transmitted, 1 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 167.652238/167.652238/167.652238/0.000000 ms
$ echo $?
0
----------------------------------------------------------------------

>Fix:

Here is diff that will make ping6 to return zero exits status if it
ever received any packets, and only return non-zero exit status if it
did not receive any packets:

Index: ping6.c
===================================================================
RCS file: /cvsroot/src/sbin/ping6/ping6.c,v
retrieving revision 1.93
diff -u -r1.93 ping6.c
--- ping6.c	18 Dec 2016 01:30:54 -0000	1.93
+++ ping6.c	26 Oct 2020 12:12:11 -0000
@@ -1069,7 +1069,6 @@
 	struct pollfd fdmaskp[1];
 	struct sockaddr_in6 from;
 	double sec, last, d_last;
-	long orig_npackets = npackets;
 
 	if (npackets == 0)
 		npackets = LONG_MAX;
@@ -1188,10 +1187,7 @@
 
 	summary();
 
-	if (orig_npackets)
-		exit(nreceived != orig_npackets);
-	else
-		exit(nreceived == 0);
+	exit(nreceived == 0);
 }
 
 static void
----------------------------------------------------------------------



Home | Main Index | Thread Index | Old Index