Merge remote branch 'upstream/master'
[mono.git] / mcs / class / System / System.Net / IPEndPoint.cs
index 22aae683ec68d6f580f6be78723077c8163bf40f..3aa2b182b88de1953b4ca5d7214696095027e2ab 100644 (file)
@@ -43,14 +43,16 @@ namespace System.Net {
                public IPEndPoint (IPAddress address, int port)
                {
                        if (address == null)
-                               throw new ArgumentNullException ("Value cannot be null");
+                               throw new ArgumentNullException ("address");
 
                        Address = address;
                        Port = port;
                }
                
-               public IPEndPoint (long iaddr, int port) : this (new IPAddress (iaddr), port)
+               public IPEndPoint (long iaddr, int port)
                {
+                       Address = new IPAddress (iaddr);
+                       Port = port;
                }
 
                public IPAddress Address {
@@ -84,18 +86,18 @@ namespace System.Net {
 
                // bytes 2 and 3 store the port, the rest
                // stores the address
-               public override EndPoint Create(SocketAddress sockaddr) {
-                       int size=sockaddr.Size;
-                       
-                       // LAMESPEC: no mention of what to do if
-                       // sockaddr is bogus
-                       if(size<8) {
-                               // absolute minimum amount needed for
-                               // an address family, buffer size,
-                               // port and address
-                               return(null);
-                       }
+               public override EndPoint Create (SocketAddress socketAddress)
+               {
+                       if (socketAddress == null)
+                               throw new ArgumentNullException ("socketAddress");
+
+                       if (socketAddress.Family != AddressFamily)
+                               throw new ArgumentException ("The IPEndPoint was created using " + AddressFamily + 
+                                               " AddressFamily but SocketAddress contains " + socketAddress.Family + 
+                                               " instead, please use the same type.");
 
+                       SocketAddress sockaddr = socketAddress;
+                       int size =sockaddr.Size;
                        AddressFamily family = sockaddr.Family;
                        int port;