From 65b7f542d622dc59ce43d9fd84dc88b8dcc7f296 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Henric=20M=C3=BCller?= Date: Tue, 17 Jan 2017 16:14:26 +0100 Subject: [PATCH] Fixing tests that asume IPV4 when first adapter is IPV6 --- mcs/class/System/System.Net.NetworkInformation/Ping.cs | 6 +++--- .../System/Test/System.Net.Sockets/UdpClientTest.cs | 10 ++++++++-- mcs/class/System/Test/System.Net/HttpListener2Test.cs | 10 ++++++++-- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/mcs/class/System/System.Net.NetworkInformation/Ping.cs b/mcs/class/System/System.Net.NetworkInformation/Ping.cs index 1d2786002e1..90d0e3a59ca 100644 --- a/mcs/class/System/System.Net.NetworkInformation/Ping.cs +++ b/mcs/class/System/System.Net.NetworkInformation/Ping.cs @@ -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)) { diff --git a/mcs/class/System/Test/System.Net.Sockets/UdpClientTest.cs b/mcs/class/System/Test/System.Net.Sockets/UdpClientTest.cs index 33dc4464c86..29ab8ef2ca6 100644 --- a/mcs/class/System/Test/System.Net.Sockets/UdpClientTest.cs +++ b/mcs/class/System/Test/System.Net.Sockets/UdpClientTest.cs @@ -991,8 +991,14 @@ namespace MonoTests.System.Net.Sockets { "BeginSend #4"); } - IPEndPoint ep = new IPEndPoint (Dns.GetHostEntry (string.Empty).AddressList[0], 1236); - + IPAddress[] addresses = Dns.GetHostEntry (string.Empty).AddressList; + IPEndPoint ep = null; + foreach (IPAddress a in addresses) { + if (a.AddressFamily == AddressFamily.InterNetwork) { + ep = new IPEndPoint (a, 1236); + break; + } + } BSCalledBack.Reset (); client.BeginSend (bytes, bytes.Length, ep, diff --git a/mcs/class/System/Test/System.Net/HttpListener2Test.cs b/mcs/class/System/Test/System.Net/HttpListener2Test.cs index 51e2990c0d1..abf4bf12bb6 100644 --- a/mcs/class/System/Test/System.Net/HttpListener2Test.cs +++ b/mcs/class/System/Test/System.Net/HttpListener2Test.cs @@ -874,8 +874,14 @@ namespace MonoTests.System.Net { int port = NetworkHelpers.FindFreePort ();; var h = new HttpListener (); - h.Prefixes.Add ("http://" + machineAddress [0] + ":" + port + "/"); - h.Start (); + // Listen on the first IPV4 interface + foreach (IPAddress a in machineAddress) { + if (a.AddressFamily == AddressFamily.InterNetwork) { + h.Prefixes.Add ("http://" + a + ":" + port + "/"); + h.Start (); + break; + } + } try { var c = new TcpClient ("localhost", port); -- 2.25.1