Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Peterson <petersonjm1@gmail.com>2016-09-22 16:49:18 +0300
committerMiguel de Icaza <miguel@gnome.org>2016-09-22 16:49:18 +0300
commit087c016f5c7200a64cf74edb90524a74faa6183b (patch)
tree6ac94ea233e49f21c2dea6f5ac8b763dbe935db1 /mcs/class/System.Runtime.Remoting
parent2f1e6655e2c9a9dd28c0a8b14f26d3d6b1c720bd (diff)
Try to use an IPv4 address first for TCP remoting (#3507)
* In the .NET implementation of TcpServerChannel, if IPv4 is supported, the address for the host will use the first IPv4 address. * Even if the first address is an IPv6 address, it should be skipped, as the server side will expect and IPv4 address. * Change this implementation to look for an IPv4 address first, then fall back to whatever the first address is (IPv4 or IPv6) if things don't work out.
Diffstat (limited to 'mcs/class/System.Runtime.Remoting')
-rw-r--r--mcs/class/System.Runtime.Remoting/System.Runtime.Remoting.Channels.Tcp/TcpServerChannel.cs23
1 files changed, 22 insertions, 1 deletions
diff --git a/mcs/class/System.Runtime.Remoting/System.Runtime.Remoting.Channels.Tcp/TcpServerChannel.cs b/mcs/class/System.Runtime.Remoting/System.Runtime.Remoting.Channels.Tcp/TcpServerChannel.cs
index cab5d342086..2ca12fb601a 100644
--- a/mcs/class/System.Runtime.Remoting/System.Runtime.Remoting.Channels.Tcp/TcpServerChannel.cs
+++ b/mcs/class/System.Runtime.Remoting/System.Runtime.Remoting.Channels.Tcp/TcpServerChannel.cs
@@ -71,7 +71,12 @@ namespace System.Runtime.Remoting.Channels.Tcp
else {
IPHostEntry he = Dns.Resolve (Dns.GetHostName());
if (he.AddressList.Length == 0) throw new RemotingException ("IP address could not be determined for this host");
- host = he.AddressList [0].ToString ();
+ AddressFamily addressFamily = (Socket.OSSupportsIPv4) ? AddressFamily.InterNetwork : AddressFamily.InterNetworkV6;
+ IPAddress addr = GetMachineAddress (he, addressFamily);
+ if (addr != null)
+ host = addr.ToString ();
+ else
+ host = he.AddressList [0].ToString ();
}
}
else
@@ -259,6 +264,22 @@ namespace System.Runtime.Remoting.Channels.Tcp
server_thread.Join ();
server_thread = null;
}
+
+ private static IPAddress GetMachineAddress (IPHostEntry host, AddressFamily addressFamily)
+ {
+ IPAddress result = null;
+ if (host != null) {
+ IPAddress[] addressList = host.AddressList;
+ for (int i = 0; i < addressList.Length; i++) {
+ if (addressList[i].AddressFamily == addressFamily) {
+ result = addressList[i];
+ break;
+ }
+ }
+ }
+
+ return result;
+ }
}
class ClientConnection