Fix #275: "net.tcp://localhost:<port>/<path>" should listen on IPAddress.Any.
authorMartin Baulig <martin.baulig@xamarin.com>
Wed, 5 Sep 2012 20:43:59 +0000 (22:43 +0200)
committerMartin Baulig <martin.baulig@xamarin.com>
Wed, 5 Sep 2012 20:43:59 +0000 (22:43 +0200)
mcs/class/System.ServiceModel/System.ServiceModel.Channels.NetTcp/TcpChannelListener.cs

index 083640c66b96e411c9ba383c442e45802d6c42fa..9fc6f5d921734451bac785798fd3f10364832135 100644 (file)
@@ -174,13 +174,19 @@ namespace System.ServiceModel.Channels.NetTcp
 
                protected override void OnOpen (TimeSpan timeout)
                {
-                       IPHostEntry entry = Dns.GetHostEntry (Uri.Host);
-                       
-                       if (entry.AddressList.Length ==0)
-                               throw new ArgumentException (String.Format ("Invalid listen URI: {0}", Uri));
+                       IPAddress address;
+
+                       if (string.Equals (Uri.Host, "localhost", StringComparison.InvariantCultureIgnoreCase))
+                               address = IPAddress.Any;
+                       else {
+                               IPHostEntry entry = Dns.GetHostEntry (Uri.Host);
+                               if (entry.AddressList.Length == 0)
+                                       throw new ArgumentException (String.Format ("Invalid listen URI: {0}", Uri));
+                               address = entry.AddressList [0];
+                       }
                        
                        int explicitPort = Uri.Port;
-                       tcp_listener = new TcpListener (entry.AddressList [0], explicitPort <= 0 ? TcpTransportBindingElement.DefaultPort : explicitPort);
+                       tcp_listener = new TcpListener (address, explicitPort <= 0 ? TcpTransportBindingElement.DefaultPort : explicitPort);
                        tcp_listener.Start ();
                        tcp_listener.BeginAcceptTcpClient (TcpListenerAcceptedClient, tcp_listener);
                }