From 7b51e84dc54d1b846e712d5f0a41dadda766aa5a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jochen=20K=C3=BChner?= Date: Mon, 29 May 2017 23:05:34 +0200 Subject: [PATCH] Bugfix Ping.cs (#4936) --- .../System/System.Net.NetworkInformation/Ping.cs | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/mcs/class/System/System.Net.NetworkInformation/Ping.cs b/mcs/class/System/System.Net.NetworkInformation/Ping.cs index f1f5936be75..0ef32ad3433 100644 --- a/mcs/class/System/System.Net.NetworkInformation/Ping.cs +++ b/mcs/class/System/System.Net.NetworkInformation/Ping.cs @@ -207,17 +207,6 @@ namespace System.Net.NetworkInformation { return Send (addresses [0], timeout, buffer, options); } - static IPAddress GetNonLoopbackIPV4 () - { -#pragma warning disable 618 - foreach (IPAddress addr in Dns.GetHostByName (Dns.GetHostName ()).AddressList) - if (!IPAddress.IsLoopback (addr) && addr.AddressFamily == AddressFamily.InterNetwork) - return addr; -#pragma warning restore 618 - - throw new InvalidOperationException ("Could not resolve non-loopback IP address for localhost"); - } - public PingReply Send (IPAddress address, int timeout, byte [] buffer, PingOptions options) { if (address == null) @@ -243,8 +232,7 @@ namespace System.Net.NetworkInformation { private PingReply SendPrivileged (IPAddress address, int timeout, byte [] buffer, PingOptions options) { IPEndPoint target = new IPEndPoint (address, 0); - IPEndPoint client = new IPEndPoint (GetNonLoopbackIPV4 (), 0); - + // FIXME: support IPv6 using (Socket s = new Socket (AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.Icmp)) { if (options != null) { @@ -264,7 +252,7 @@ namespace System.Net.NetworkInformation { // receive bytes = new byte [100]; do { - EndPoint endpoint = client; + EndPoint endpoint = target; SocketError error = 0; int rc = s.ReceiveFrom (bytes, 0, 100, SocketFlags.None, ref endpoint, out error); -- 2.25.1