Fixing tests that asume IPV4 when first adapter is IPV6
[mono.git] / mcs / class / System / System.Net.NetworkInformation / Ping.cs
index 1d2786002e102552f4c112c91ef8522c71a8a490..90d0e3a59ca568e3ed6340b534f1c9a7237e1f2c 100644 (file)
@@ -207,11 +207,11 @@ namespace System.Net.NetworkInformation {
                        return Send (addresses [0], timeout, buffer, options);
                }
 
-               static IPAddress GetNonLoopbackIP ()
+               static IPAddress GetNonLoopbackIPV4 ()
                {
 #pragma warning disable 618
                        foreach (IPAddress addr in Dns.GetHostByName (Dns.GetHostName ()).AddressList)
-                               if (!IPAddress.IsLoopback (addr))
+                               if (!IPAddress.IsLoopback (addr) && addr.AddressFamily == AddressFamily.InterNetwork)
                                        return addr;
 #pragma warning restore 618
 
@@ -243,7 +243,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 (GetNonLoopbackIP (), 0);
+                       IPEndPoint client = new IPEndPoint (GetNonLoopbackIPV4 (), 0);
 
                        // FIXME: support IPv6
                        using (Socket s = new Socket (AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.Icmp)) {