You are trying to ping a system in the same network. So there is no router involved that might return a
Destination Host Unreachable
. There is no other device reacting on the echo request besides the adressed one and if that is not present a time out will occur.
When using the ADB shell, the ping command is executed on your Android device which is probably located in a different subnet (WLAN). Then a router is involved (forwarding packages from WLAN to LAN) and may generate an unreachable message.
[EDIT]
I overlooked that the problem is that TTL expired is returned instead of a time out.
When using Mono, the used sources can be found at
mono/Ping.cs at master · mono/mono · GitHub[
^].
That calls the system
ping command and checks the exit code:
if (!ping.WaitForExit (timeout) || (ping.HasExited && ping.ExitCode == 2))
status = IPStatus.TimedOut;
else if (ping.ExitCode == 0)
status = IPStatus.Success;
else if (ping.ExitCode == 1)
status = IPStatus.TtlExpired;
So TTL expired is set when there was no timeout, no error or success (exit code 2 or 0), and the exit code was 1.
See
ping(8) - Linux man page[
^] for the cases of returning 1:
Quote:
If ping does not receive any reply packets at all it will exit with code 1. If a packet count and deadline are both specified, and fewer than count packets are received by the time the deadline has arrived, it will also exit with code 1. On other error it exits with code 2. Otherwise it exits with code 0. This makes it possible to use the exit code to see if a host is alive or not.
So a return value of 1 indicates that no response has been received (for various reasons) and the Mono implementation sets the TTL expired status in this case. I would expect that a time out status would be returned in such cases. But it seems that the timeout detection of the Mono implementation is not triggered here (e.g. because the
ping command exits upon on it's own timeout before).
So there are two possible solutions:
- Treat a TTL expired as host not alive (but this will then ignore ignore real TTL expired detections)
- Check the Mono sources to see if the internal timeout value can be lowered (or the value passed to the ping command can be enhanced) and send a bug report
[/EDIT]