Bug 53284 - Ping IP or HOSTNAME , always returns : TTL expired ! even if timeout , host unreachable or other problem
Summary: Ping IP or HOSTNAME , always returns : TTL expired ! even if timeout , host u...
Alias: None
Product: Android
Classification: Xamarin
Component: Android+BCL Integration ()
Version: 7.3 (15.2)
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Martin Baulig
: 53267 ()
Depends on:
Reported: 2017-03-13 17:14 UTC by Emin Kokalari
Modified: 2017-06-05 01:27 UTC (History)
4 users (show)

Tags: c#, xamarin android, visual studio
Is this bug a regression?: ---
Last known good build:

ScreenShot of Ping.cs at MONO Github Project (95.96 KB, image/jpeg)
2017-03-13 17:14 UTC, Emin Kokalari
Test Project (5.31 KB, application/zip)
2017-03-14 20:15 UTC, Jon Goldberger [MSFT]

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report for Bug 53284 on Developer Community or GitHub if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:

Description Emin Kokalari 2017-03-13 17:14:28 UTC
Created attachment 20290 [details]
ScreenShot of Ping.cs at MONO Github Project

can be found at mono/Ping.cs (line 339)
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.

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 other possible solutions:

To treat a TTL expired as host not alive (but this will then ignore ignore real TTL expired detections)

Please fix ASAP this is very very annoying . It should be there a IPStatus for :

Destination Host Unreachable , Timeout , Destination Network Unreachable and ect ....
Comment 1 Brendan Zagaeski (Xamarin Team, assistant) 2017-03-13 18:08:34 UTC
*** Bug 53267 has been marked as a duplicate of this bug. ***
Comment 2 Emin Kokalari 2017-03-14 15:46:05 UTC
Any answer here ?
Comment 3 Jon Goldberger [MSFT] 2017-03-14 20:15:06 UTC
Created attachment 20324 [details]
Test Project

I just tested this in Mono 4.8 and a pure .NET Console project.

In Mono 4.8 I was able to kind of reproduce this issue, but on my end I am always getting TimedOut not TtlExpired as noted in the bug description.

In pure .NET, on the first ping I get the DestinationHostUNreachable, but on subsequent pings to the same address I get TimedOut. 

Simple Console Test project attached. Just run the test project and enter an IP Address to ping in the console. Press any key to send another ping to the same address.
Comment 4 Emin Kokalari 2017-03-14 23:18:10 UTC
I understand you , but i have this problem when testing in android (xamarin.android) ... in this platform is not working
Comment 5 Jon Goldberger [MSFT] 2017-03-14 23:23:36 UTC
I tested in Android too and still got the TimeOut rather than TtlExpired.
Comment 6 Emin Kokalari 2017-03-15 13:09:15 UTC
I dont think that you are correct ! ... Anyway , try this code in android with an inexistence IP adress

PingReply Reply = await pingo.SendPingAsync(ipadress, 4000, buffer, options);
                Toast.MakeText(Activity, Reply.Status.ToString(), ToastLength.Long).Show();
                switch (Reply.Status)
                    case IPStatus.Success:

                        Toast.MakeText(Activity, Reply.Status.ToString(), ToastLength.Long).Show();

                    case IPStatus.TimedOut:

                        Toast.MakeText(Activity, Reply.Status.ToString(), ToastLength.Long).Show();

                    case IPStatus.TimeExceeded:

                        Toast.MakeText(Activity, Reply.Status.ToString(), ToastLength.Long).Show();

                    case IPStatus.DestinationHostUnreachable:

                       Toast.MakeText(Activity, Reply.Status.ToString(), ToastLength.Long).Show();

                    case IPStatus.DestinationNetworkUnreachable:

                        Toast.MakeText(Activity, Reply.Status.ToString(), ToastLength.Long).Show();

                    case IPStatus.DestinationUnreachable:

                        Toast.MakeText(Activity, Reply.Status.ToString(), ToastLength.Long).Show();
Comment 7 Emin Kokalari 2017-03-15 17:39:13 UTC
did you try it ?
Comment 8 Jon Goldberger [MSFT] 2017-03-15 18:55:47 UTC
OK, you are correct. On Android I am getting TtlExpired.
Comment 9 Emin Kokalari 2017-03-15 23:00:28 UTC
ok, so is there any chance to be solved ? and when ?
Comment 10 Emin Kokalari 2017-03-16 02:36:18 UTC
@Jon Goldberger , hey.. sorry for my before-reply . i'm not very good in english and was a little drunk yesterday :D :D :D ... i mean that i just need to know if this will be fixed in next alpha build or something like this... My project depend in that feature. :). It can be solved via an exec process too with Java.Lang.Process , but i like to use System.Net.NetworkInformaion from MONO . Have a nice time , bye .. and thanks for your time.
Comment 11 Emin Kokalari 2017-03-17 22:30:46 UTC
hello there ... what will happen with that bug :) ?
Comment 13 Emin Kokalari 2017-06-05 01:26:34 UTC
any solution ? long time without replying