Bug 53267 - System.Net.NetworkInformation.Ping Always return ttl expired when ip is not assigned to any host
Summary: System.Net.NetworkInformation.Ping Always return ttl expired when ip is not a...
Status: RESOLVED DUPLICATE of bug 53284
Alias: None
Product: Android
Classification: Xamarin
Component: General ()
Version: unspecified
Hardware: Other Other
: --- normal
Target Milestone: ---
Assignee: Jonathan Pryor
URL:
: 53268 53269 ()
Depends on:
Blocks:
 
Reported: 2017-03-12 17:59 UTC by Emin Kokalari
Modified: 2017-03-13 18:08 UTC (History)
1 user (show)

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

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 on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED DUPLICATE of bug 53284

Description Emin Kokalari 2017-03-12 17:59:25 UTC
System.Net.NetworkInformation Ping always return TTL Expire when ip is not assigned to any host

PingReply Reply = await pingo.SendPingAsync(ip-adress, timeout, 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();
                        break;

                    case IPStatus.TimedOut:

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

                    case IPStatus.TimeExceeded:

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

                    case IPStatus.DestinationHostUnreachable:


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

                    case IPStatus.DestinationNetworkUnreachable:

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

                    case IPStatus.DestinationUnreachable:

                        Toast.MakeText(Activity, Reply.Status.ToString(), ToastLength.Long).Show();
                        break;
                }
For example i add a ip adress that is not assigned to any device and is doesnt return : Destination Host Unreachable or something else , but only ttl expired !

Whats wrong ?
Comment 1 Brendan Zagaeski (Xamarin Team, assistant) 2017-03-12 23:15:26 UTC
*** Bug 53268 has been marked as a duplicate of this bug. ***
Comment 2 Brendan Zagaeski (Xamarin Team, assistant) 2017-03-12 23:17:44 UTC
*** Bug 53269 has been marked as a duplicate of this bug. ***
Comment 3 Emin Kokalari 2017-03-13 16:28:46 UTC
mono/Ping.cs at master · mono/mono.
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 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

OR FIX THIS BUG ITS VERY ANNOYING
Comment 4 Brendan Zagaeski (Xamarin Team, assistant) 2017-03-13 18:08:34 UTC
## Note to the Xamarin team

Based on the pattern of bug filing by the reporter of this bug, it looks like the reporter did some further investigation in Comment 3 and decided that the best option was to open a new bug report to provide a clean starting place for investigation.  I will accordingly mark this bug as a duplicate of that new one for bookkeeping.

*** This bug has been marked as a duplicate of bug 53284 ***