[System] Put back handling of direct ip addresses to ServicePoint::HostEntry (removed...
authorMarek Safar <marek.safar@gmail.com>
Thu, 16 Jun 2016 15:42:55 +0000 (17:42 +0200)
committerMarek Safar <marek.safar@gmail.com>
Thu, 16 Jun 2016 15:46:18 +0000 (17:46 +0200)
mcs/class/System/System.Net/ServicePoint.cs

index ef22ed44c2b20935947099b7dcab2425614eaf3b..108de70ffb3282873158d25fac7044fffd43a99b 100644 (file)
@@ -42,7 +42,7 @@ namespace System.Net
 {
        public class ServicePoint
        {
-               Uri uri;
+               readonly Uri uri;
                int connectionLimit;
                int maxIdleTime;
                int currentConnections;
@@ -345,15 +345,31 @@ namespace System.Net
                                lock (hostE) {
                                        string uriHost = uri.Host;
 
-                                       if (host == null || HasTimedOut) {
-                                               lastDnsResolve = DateTime.UtcNow;
+                                       if (host == null) {
+                                               // Cannot do DNS resolution on literal IP addresses
+                                               if (uri.HostNameType == UriHostNameType.IPv6 || uri.HostNameType == UriHostNameType.IPv4) {
 
-                                               try {
-                                                       host = Dns.GetHostEntry (uriHost);
-                                               }
-                                               catch (Exception) {
-                                                       return null;
+                                                       if (uri.HostNameType == UriHostNameType.IPv6) {
+                                                               // Remove square brackets
+                                                               uriHost = uriHost.Substring (1, uriHost.Length - 2);
+                                                       }
+
+                                                       // Creates IPHostEntry
+                                                       host = new IPHostEntry();
+                                                       host.AddressList = new IPAddress[] { IPAddress.Parse (uriHost) };
+                                                       return host;
                                                }
+                                       } else {
+                                               if (!HasTimedOut)
+                                                       return host;
+                                       }
+
+                                       lastDnsResolve = DateTime.UtcNow;
+
+                                       try {
+                                               host = Dns.GetHostEntry (uriHost);
+                                       } catch {
+                                               return null;
                                        }
                                }