[System.Data] Use same socket family for data receiver as it has its client. Fixes...
[mono.git] / mcs / class / System.Data / System.Data.SqlClient / SqlConnection.cs
index 415f5832e863fbb51dd0606f4129b71a03c3f3ef..f7248acb6bcc5dd554bf5b75c6c64609d52a1261 100644 (file)
@@ -930,7 +930,11 @@ namespace System.Data.SqlClient
 
                                if (Client.Available <= 0)
                                        return -1; // Error
-                               IPEndPoint endpoint = new IPEndPoint (Dns.GetHostEntry ("localhost").AddressList [0], 0);
+
+                               IPEndPoint endpoint = CreateLocalEndpoint ();
+                               if (endpoint == null)
+                                       return -1;
+
                                Byte [] rawrs;
 
                                rawrs = Receive (ref endpoint);
@@ -955,6 +959,16 @@ namespace System.Data.SqlClient
 
                                return SqlServerTcpPort;
                        }
+
+                       IPEndPoint CreateLocalEndpoint ()
+                       {
+                               foreach (var addr in Dns.GetHostEntry ("localhost").AddressList) {
+                                       if (addr.AddressFamily == Client.AddressFamily)
+                                               return new IPEndPoint (addr, 0);
+                               }
+
+                               return null;
+                       }
                }
 
                struct ColumnInfo