Hello everybody,
I recently updated from Raspbmc to OSMC and additionally from a Pi 1 to Pi 3.
While transfering and adapting my old little programms I came across a problem with the ping command.
In my programm I use ping -c 1 10.0.0.1 to check if my NAS is currently online. On the old Pi it always exits after one or two seconds with “From x.x.x.x icmp_seq=1 Destination Host Unreachable”.
On the new one it lasts at least 5-10 seconds and doesn’t quit with the error. It justs says 0 packets received.
Thats unfortunately bad to use in my programm.
I realized that in OSMC the ping command is from busybox, maybe that’s a reason?
However, I am a bit confused, so does anyone know a solution to this?
Thanks a lot
F
Ping in OSMC is the busybox version of ping:
osmc@vero:~$ ping
BusyBox v1.22.1 (Debian 1:1.22.0-9+deb8u1) multi-call binary.
Usage: ping [OPTIONS] HOST
Send ICMP ECHO_REQUEST packets to network hosts
-4,-6 Force IP or IPv6 name resolution
-c CNT Send only CNT pings
-s SIZE Send SIZE data bytes in packets (default:56)
-t TTL Set TTL
-I IFACE/IP Use interface or IP address as source
-W SEC Seconds to wait for the first response (default:10)
(after all -c CNT packets are sent)
-w SEC Seconds until ping exits (default:infinite)
(can exit earlier with -c CNT)
-q Quiet, only displays output at start
and when finished
You can customise the wait time with -W.
By the way, I don’t see any problems with the return codes:
osmc@vero:~$ ping -c 1 -W 1 10.4.12.4
PING 10.4.12.4 (10.4.12.4): 56 data bytes
--- 10.4.12.4 ping statistics ---
1 packets transmitted, 0 packets received, 100% packet loss
osmc@vero:~$ echo $?
1
What actually troubles me is the fact, that on the older Pi my device more or less directly realizes that the host is unreachable. In the busybox ping version it seems to me that it is finishing the ping because of timeout or something like this. And this takes much longer which is quite annoying.
Furthermore, when I start an endless ping with “ping 10.0.0.1” on the old device it returns many of "
From 192.168.0.39 icmp_seq=1 Destination Host Unreachable" answers while on the OSMC device it simply does not give any answer.
I guess theres a way to handle this properly in PHP, but in fact I’m interested in this difference and if it is correctly.
Thanks
F
Assuming you are testing on a TCP host, you could use fsckopen() with a small timeout to get similar behaviour to a ping.
Sam
As I pointed out - the default timeout waiting for a response is 10 seconds on busybox ping. You can change this with the -W option. You can also use -w to limit the maximum run time.
I’m not sure what you need to parse the output for ? Just check the exit code - it is 1 if there is no reply and 0 if there is.
And finally, if you want the full version of ping simply install the iputils-ping debian package.
Okay so its just another implementation, got it.
That was the solution for me, thanks!