Skip to content

Commit 6e16bc5

Browse files
committed
Correct the ping implementation on OS X.
* Our version of the Mono class libraries assume the ping utility is located at /bin/ping, which is not correct in newer versions of OS X. The upstream implementation probes a few locations, so we'll take that implementation instead. * This change corrects Unity case 801973.
1 parent 9659e3c commit 6e16bc5

File tree

1 file changed

+17
-1
lines changed
  • mcs/class/System/System.Net.NetworkInformation

1 file changed

+17
-1
lines changed

mcs/class/System/System.Net.NetworkInformation/Ping.cs

+17-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
//
2929
#if NET_2_0
3030
using System;
31+
using System.IO;
3132
using System.Text;
3233
using System.Diagnostics;
3334
using System.Globalization;
@@ -56,7 +57,13 @@ struct cap_user_data_t
5657
}
5758

5859
const int DefaultCount = 1;
59-
const string PingBinPath = "/bin/ping";
60+
static readonly string [] PingBinPaths = new string [] {
61+
"/bin/ping",
62+
"/sbin/ping",
63+
"/usr/sbin/ping",
64+
"/system/bin/ping"
65+
};
66+
static readonly string PingBinPath;
6067
const int default_timeout = 4000; // 4 sec.
6168
const int identifier = 1; // no need to be const, but there's no place to change it.
6269

@@ -79,9 +86,18 @@ static Ping ()
7986
CheckLinuxCapabilities ();
8087
if (!canSendPrivileged && WindowsIdentity.GetCurrent ().Name == "root")
8188
canSendPrivileged = true;
89+
90+
foreach (string ping_path in PingBinPaths)
91+
if (File.Exists (ping_path)) {
92+
PingBinPath = ping_path;
93+
break;
94+
}
8295
}
8396
else
8497
canSendPrivileged = true;
98+
99+
if (PingBinPath == null)
100+
PingBinPath = "/bin/ping";
85101
}
86102

87103
public Ping ()

0 commit comments

Comments
 (0)