Re: [net PATCH 1/2] selftests: net: lib: fix broken ping with coreutils ping util

From: Vladimir Oltean
Date: Mon Dec 02 2024 - 16:27:16 EST


On Mon, Dec 02, 2024 at 09:39:15PM +0100, Christian Marangi wrote:
> Mhh the problem seems to be -c
>
> Let me post some outputs...
>
> root@OpenWrt:~# ping -V
> ping from iputils 20240117
> libcap: no, IDN: no, NLS: no, error.h: no, getrandom(): yes, __fpending(): yes
> root@OpenWrt:~# ping -c 10 192.168.1.1
> PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.
> 64 bytes from 192.168.1.1: icmp_seq=1 ttl=64 time=0.102 ms
> 64 bytes from 192.168.1.1: icmp_seq=2 ttl=64 time=0.084 ms
> 64 bytes from 192.168.1.1: icmp_seq=3 ttl=64 time=0.236 ms
> ^C
> --- 192.168.1.1 ping statistics ---
> 3 packets transmitted, 3 received, 0% packet loss, time 2080ms
> rtt min/avg/max/mdev = 0.084/0.140/0.236/0.067 ms
> root@OpenWrt:~# ping 192.168.1.1 -c 10
> ping: -c: Name does not resolve
>
> As you can see swapping the ip cause this "Name does not resolve" error.

Ok, I opened the iputils source code and there isn't any relevant recent
change there. But it uses getopt(3), and that seems to be implemented
more simplistically for musl libc:
https://wiki.musl-libc.org/functional-differences-from-glibc.html
"musl and the POSIX standard getopt stop processing options at the first
non-option argument with no permutation."

On GNU libc:
$ ping 192.168.1.1 -c 1
PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.
64 bytes from 192.168.1.1: icmp_seq=1 ttl=64 time=0.696 ms

--- 192.168.1.1 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.696/0.696/0.696/0.000 ms