Bladeren bron

[System] IPAddress from referencesource

Marek Safar 9 jaren geleden
bovenliggende
commit
008f7272d3

+ 0 - 107
mcs/class/System/System.Net/DnsEndPoint.cs

@@ -1,107 +0,0 @@
-//
-// System.Net.DnsEndPoint
-//
-// Authors:
-//	Stephane Delcroix  <[email protected]>
-//
-// (c) 2007, 2009 Novell, Inc. (http://www.novell.com)
-//
-
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-// 
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-// 
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-
-using System.Net.Sockets;
-
-namespace System.Net { 
-
-#if NET_2_1
-	sealed
-#endif
-	public class DnsEndPoint : EndPoint {
-		string host;
-		int port;
-		AddressFamily addressFamily = AddressFamily.Unspecified;
-
-		public DnsEndPoint (string host, int port)
-		{
-			if (host == null)
-				throw new ArgumentNullException ("host");
-			if (host == String.Empty)
-				throw new ArgumentException ("host parameter contains an empty string");
-			if (port < 0 || port > 0xffff)
-				throw new ArgumentOutOfRangeException ("port is less than 0 or greater than 0xffff");
-
-			this.host = host;
-			this.port = port;
-		}
-
-		public DnsEndPoint (string host, int port, AddressFamily addressFamily) : this (host, port)
-		{
-			switch (addressFamily) {
-			case AddressFamily.InterNetwork:
-			case AddressFamily.InterNetworkV6:
-			case AddressFamily.Unspecified:
-				this.addressFamily = addressFamily;
-				break;
-			default:
-				// throw for Unknown or any invalid value
-				throw new ArgumentException ("addressFamily");
-			}
-		}
-
-		public override bool Equals (object comparand)
-		{
-			DnsEndPoint dep = (comparand as DnsEndPoint);
-			return (comparand != null) && Equals (dep);
-		}
-
-		private bool Equals (DnsEndPoint other)
-		{
-			if (port != other.port || addressFamily != other.addressFamily|| host != other.host)
-				return false;
-			return true;
-		}
-
-		public override int GetHashCode ()
-		{
-			return port ^ (int)addressFamily ^ host.GetHashCode ();
-		}
-
-		public override string ToString ()
-		{
-			return String.Format ("{0}/{1}:{2}", addressFamily, host, port);
-		}
-
-		public override AddressFamily AddressFamily {
-			get { return addressFamily; }
-		}
-
-		public string Host {
-			get { return host; }
-		}
-
-		public int Port {
-			get { return port; }
-		}
-	}
-}
-

+ 0 - 65
mcs/class/System/System.Net/EndPoint.cs

@@ -1,65 +0,0 @@
-//
-// System.Net.EndPoint.cs
-//
-// Author:
-//   Dick Porter ([email protected])
-//
-// (C) Ximian, Inc.  http://www.ximian.com
-//
-
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-// 
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-// 
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-using System.Net.Sockets;
-
-namespace System.Net {
-	[Serializable]
-	public abstract class EndPoint {
-
-		// NB: These methods really do nothing but throw
-		// NotImplementedException
-		
-		public virtual AddressFamily AddressFamily {
-			get { throw NotImplemented (); }
-		}
-		
-		public virtual EndPoint Create (SocketAddress socketAddress)
-		{
-			throw NotImplemented ();
-		}
-
-		public virtual SocketAddress Serialize ()
-		{
-			throw NotImplemented ();
-		}
-
-		protected EndPoint ()
-		{
-		}
-
-		static Exception NotImplemented ()
-		{
-			// hide the "normal" NotImplementedException from corcompare-like tools
-			return new NotImplementedException ();
-		}
-	}
-}
-

+ 0 - 529
mcs/class/System/System.Net/IPAddress.cs

@@ -1,529 +0,0 @@
-//
-// System.Net.IPAddress.cs
-//
-// Author:
-//   Miguel de Icaza ([email protected])
-//   Lawrence Pit ([email protected])
-//
-// (C) Ximian, Inc.  http://www.ximian.com
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-// 
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-// 
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-using System;
-using System.Globalization;
-using System.Net.Sockets;
-using System.Runtime.InteropServices;
-
-namespace System.Net {
-
-	/// <remarks>
-	///   Encapsulates an IP Address.
-	/// </remarks>
-	[Serializable]
-	public class IPAddress {
-		// Don't change the name of this field without also
-		// changing socket-io.c in the runtime
-		// The IP address is stored in little-endian order inside the int, 
-		// meaning the lower order bytes contain the netid
-		private long m_Address;
-		private AddressFamily m_Family;
-		private ushort[] m_Numbers;	/// ip6 Stored in network order (as ip4)
-		private long m_ScopeId;
-
-		public static readonly IPAddress Any = new IPAddress(0);
-		public static readonly IPAddress Broadcast = IPAddress.Parse ("255.255.255.255");
-		public static readonly IPAddress Loopback = IPAddress.Parse ("127.0.0.1");
-		public static readonly IPAddress None = IPAddress.Parse ("255.255.255.255");
-		public static readonly IPAddress IPv6Any = IPAddress.ParseIPV6 ("::");
-		public static readonly IPAddress IPv6Loopback = IPAddress.ParseIPV6 ("::1");
-		public static readonly IPAddress IPv6None = IPAddress.ParseIPV6 ("::");
-
-		private static short SwapShort (short number)
-		{
-			return (short) ( ((number >> 8) & 0xFF) | ((number << 8) & 0xFF00) );
-		}
-
-		private static int SwapInt (int number)
-		{
-			return (((number >> 24) & 0xFF)
-				  | ((number >> 08) & 0xFF00)
-				  | ((number << 08) & 0xFF0000)
-				  | ((number << 24)));
-		}
-
-		private static long SwapLong(long number)
-		{
-			return (((number >> 56) & 0xFF)
-				  | ((number >> 40) & 0xFF00)
-				  | ((number >> 24) & 0xFF0000)
-				  | ((number >> 08) & 0xFF000000)
-				  | ((number << 08) & 0xFF00000000)
-				  | ((number << 24) & 0xFF0000000000)
-				  | ((number << 40) & 0xFF000000000000)
-				  | ((number << 56)));
-		}
-
-		public static short HostToNetworkOrder(short host) {
-			if (!BitConverter.IsLittleEndian)
-				return(host);
-
-			return SwapShort (host);
-		}
-
-		public static int HostToNetworkOrder(int host) {
-			if (!BitConverter.IsLittleEndian)
-				return(host);
-
-			return SwapInt (host);
-		}
-		
-		public static long HostToNetworkOrder(long host) {
-			if (!BitConverter.IsLittleEndian)
-				return(host);
-
-			return SwapLong (host);
-		}
-
-		public static short NetworkToHostOrder(short network) {
-			if (!BitConverter.IsLittleEndian)
-				return(network);
-
-			return SwapShort (network);
-		}
-
-		public static int NetworkToHostOrder(int network) {
-			if (!BitConverter.IsLittleEndian)
-				return(network);
-
-			return SwapInt (network);
-		}
-
-		public static long NetworkToHostOrder(long network) {
-			if (!BitConverter.IsLittleEndian)
-				return(network);
-
-			return SwapLong (network);
-		}
-		
-		/// <summary>
-		///   Constructor from a 32-bit constant with the address bytes in
-		///   little-endian order (the lower order bytes contain the netid)
-		/// </summary>
-		public IPAddress (long newAddress)
-		{
-			m_Address = newAddress;
-			m_Family = AddressFamily.InterNetwork;
-		}
-
-		public IPAddress (byte[] address)
-		{
-			if (address == null)
-				throw new ArgumentNullException ("address");
-
-			int len = address.Length;
-
-			if (len != 16 && len != 4)
-				throw new ArgumentException ("An invalid IP address was specified.",
-					"address");
-
-			if (len == 16) {
-				m_Numbers = new ushort [8];
-				Buffer.BlockCopy(address, 0, m_Numbers, 0, 16);
-				m_Family = AddressFamily.InterNetworkV6;
-				m_ScopeId = 0;
-			} else {
-				m_Address = ((uint) address [3] << 24) + (address [2] << 16) +
-					(address [1] << 8) + address [0];
-				m_Family = AddressFamily.InterNetwork;
-			}
-		}
-
-		public IPAddress(byte[] address, long scopeid)
-		{
-			if (address == null)
-				throw new ArgumentNullException ("address");
-
-			if (address.Length != 16)
-				throw new ArgumentException ("An invalid IP address was specified.",
-					"address");
-
-			m_Numbers = new ushort [8];
-			Buffer.BlockCopy(address, 0, m_Numbers, 0, 16);
-			m_Family = AddressFamily.InterNetworkV6;
-			m_ScopeId = scopeid;
-		}
-
-		internal IPAddress(ushort[] address, long scopeId)
-		{
-			m_Numbers = address;
-
-			for(int i=0; i<8; i++)
-				m_Numbers[i] = (ushort)HostToNetworkOrder((short)m_Numbers[i]);
-
-			m_Family = AddressFamily.InterNetworkV6;
-			m_ScopeId = scopeId;
-		}
-
-		public static IPAddress Parse (string ipString)
-		{
-            if (ipString == null)
-                throw new ArgumentNullException("ipString");
-
-			IPAddress ret;
-			if (TryParse (ipString, out ret))
-				return ret;
-			throw new FormatException ("An invalid IP address was specified.");
-		}
-
-		public static bool TryParse (string ipString, out IPAddress address)
-		{
-			if (ipString == null)
-			{
-				address = null;
-				return false;
-			}
-
-			if ((address = ParseIPV4 (ipString)) == null)
-				if ((address = ParseIPV6 (ipString)) == null)
-					return false;
-			return true;
-		}
-
-		private static IPAddress ParseIPV4 (string ip)
-		{
-
-			int pos = ip.IndexOf (' ');
-			if (pos != -1) {
-				string [] nets = ip.Substring (pos + 1).Split (new char [] {'.'});
-				if (nets.Length > 0) {
-					string lastNet = nets [nets.Length - 1];
-					if (lastNet.Length == 0)
-						return null;
-					foreach (char c in lastNet)
-						if (!Uri.IsHexDigit (c))
-							return null;
-				}
-				ip = ip.Substring (0, pos);
-			}
-
-			if (ip.Length == 0 || ip [ip.Length - 1] == '.')
-				return null;
-
-			string [] ips = ip.Split (new char [] {'.'});
-			if (ips.Length > 4)
-				return null;
-			
-			// Make the number in network order
-			try {
-				long a = 0;
-				long val = 0;
-				for (int i = 0; i < ips.Length; i++) {
-					string subnet = ips [i];
-					if ((3 <= subnet.Length && subnet.Length <= 4) &&
-					    (subnet [0] == '0') && (subnet [1] == 'x' || subnet [1] == 'X')) {
-						if (subnet.Length == 3)
-							val = (byte) Uri.FromHex (subnet [2]);
-						else 
-							val = (byte) ((Uri.FromHex (subnet [2]) << 4) | Uri.FromHex (subnet [3]));
-					} else if (subnet.Length == 0)
-						return null;
-					else if (subnet [0] == '0') {
-						// octal
-						val = 0;
-						for (int j = 1; j < subnet.Length; j++) {
-							if ('0' <= subnet [j] && subnet [j] <= '7')
-								val = (val << 3) + subnet [j] - '0';
-							else
-								return null;
-						}
-					}
-					else {
-						if (!Int64.TryParse (subnet, NumberStyles.None, null, out val))
-							return null;
-					}
-
-					if (i == (ips.Length - 1)) {
-						if (i != 0  && val >= (256 << ((3 - i) * 8)))
-							return null;
-						else if (val > 0xffffffff)
-							return null;
-						i = 3;
-					} else if (val >= 0x100)
-						return null;
-					for (int j = 0; val > 0; j++, val /= 0x100)
-						a |= (val & 0xFF) << ((i - j) << 3);
-				}
-
-				return (new IPAddress (a));
-			} catch (Exception) {
-				return null;
-			}
-		}
-		
-		private static IPAddress ParseIPV6 (string ip)
-		{
-			IPv6Address newIPv6Address;
-
-			if (IPv6Address.TryParse(ip, out newIPv6Address))
-				return  new IPAddress (newIPv6Address.Address, newIPv6Address.ScopeId);
-			return null;
-		}
-
-		[Obsolete("This property is obsolete. Use GetAddressBytes.")]
-		public long Address 
-		{
-			get {
-				if(m_Family != AddressFamily.InterNetwork)
-					throw new Exception("The attempted operation is not supported for the type of object referenced");
-
-				return m_Address;
-			}
-			set {
-				/* no need to do this test, ms.net accepts any value.
-				if (value < 0 || value > 0x00000000FFFFFFFF)
-					throw new ArgumentOutOfRangeException (
-						"the address must be between 0 and 0xFFFFFFFF");
-				*/
-
-				if(m_Family != AddressFamily.InterNetwork)
-					throw new Exception("The attempted operation is not supported for the type of object referenced");
-
-				m_Address = value;
-			}
-		}
-
-		internal long InternalIPv4Address {
-			get { return m_Address; }
-		}
-
-		public bool IsIPv6LinkLocal {
-			get {
-				if (m_Family == AddressFamily.InterNetwork)
-					return false;
-				int v = NetworkToHostOrder ((short) m_Numbers [0]) & 0xFFF0;
-				return 0xFE80 <= v && v < 0xFEC0;
-			}
-		}
-
-		public bool IsIPv6SiteLocal {
-			get {
-				if (m_Family == AddressFamily.InterNetwork)
-					return false;
-				int v = NetworkToHostOrder ((short) m_Numbers [0]) & 0xFFF0;
-				return 0xFEC0 <= v && v < 0xFF00;
-			}
-		}
-
-		public bool IsIPv6Multicast {
-			get {
-				return m_Family != AddressFamily.InterNetwork &&
-					((ushort) NetworkToHostOrder ((short) m_Numbers [0]) & 0xFF00) == 0xFF00;
-			}
-		}
-
-		public bool IsIPv6Teredo {
-			get {
-				return m_Family != AddressFamily.InterNetwork &&
-					NetworkToHostOrder ((short) m_Numbers [0]) == 0x2001 &&
-					m_Numbers[1] == 0;
-			}
-		}
-
-		public long ScopeId {
-			get {
-				if (m_Family != AddressFamily.InterNetworkV6)
-					throw new SocketException ((int) SocketError.OperationNotSupported);
-
-				return m_ScopeId;
-			}
-			set {
-				if (m_Family != AddressFamily.InterNetworkV6)
-					throw new SocketException ((int) SocketError.OperationNotSupported);
-				if ((value < 0) || (value > UInt32.MaxValue))
-					throw new ArgumentOutOfRangeException ();
-
-				m_ScopeId = value;
-			}
-		}
-
-		public byte [] GetAddressBytes () 
-		{
-			if(m_Family == AddressFamily.InterNetworkV6) {
-				byte [] addressBytes = new byte [16];
-				Buffer.BlockCopy (m_Numbers, 0, addressBytes, 0, 16);
-				return addressBytes;
-			} else {
-				return new byte [4] { (byte)(m_Address & 0xFF),
-						     (byte)((m_Address >> 8) & 0xFF),
-						     (byte)((m_Address >> 16) & 0xFF),
-						     (byte)(m_Address >> 24) }; 
-			}
-		}
-
-		public AddressFamily AddressFamily 
-		{
-			get {
-				return m_Family;
-			}
-		}
-
-#if NET_4_5
-
-		public IPAddress MapToIPv4 ()
-		{
-			if (AddressFamily == AddressFamily.InterNetwork)
-				return this;
-			if (AddressFamily != AddressFamily.InterNetworkV6)
-				throw new Exception ("Only AddressFamily.InterNetworkV6 can be converted to IPv4");
-
-			//Test for 0000 0000 0000 0000 0000 FFFF xxxx xxxx
-			for (int i = 0; i < 5; i++) {
-				if (m_Numbers [i] != 0x0000)
-					throw new Exception ("Address does not have the ::FFFF prefix");
-			}
-			if (m_Numbers [5] != 0xFFFF)
-				throw new Exception ("Address does not have the ::FFFF prefix");
-
-			//We've got an IPv4 address
-			byte [] ipv4Bytes = new byte [4];
-			Buffer.BlockCopy (m_Numbers, 12, ipv4Bytes, 0, 4);
-			return new IPAddress (ipv4Bytes);
-		}
-
-		public IPAddress MapToIPv6 ()
-		{
-			if (AddressFamily == AddressFamily.InterNetworkV6)
-				return this;
-			if (AddressFamily != AddressFamily.InterNetwork)
-				throw new Exception ("Only AddressFamily.InterNetworkV4 can be converted to IPv6");
-
-			byte [] ipv4Bytes = GetAddressBytes ();
-			byte [] ipv6Bytes = new byte [16] {
-				0,0, 0,0, 0,0, 0,0, 0,0, 0xFF,0xFF,
-				ipv4Bytes [0], ipv4Bytes [1], ipv4Bytes [2], ipv4Bytes [3]
-			};
-			return new IPAddress (ipv6Bytes);
-		}
-
-#endif
-
-		/// <summary>
-		///   Used to tell whether an address is a loopback.
-		///   All IP addresses of the form 127.X.Y.Z, where X, Y, and Z are in 
-		///   the range 0-255, are loopback addresses.
-		/// </summary>
-		/// <param name="addr">Address to compare</param>
-		/// <returns></returns>
-		public static bool IsLoopback (IPAddress address)
-		{
-			if(address.m_Family == AddressFamily.InterNetwork)
-				return (address.m_Address & 0xFF) == 127;
-			else {
-				for(int i=0; i<6; i++) {
-					if(address.m_Numbers[i] != 0)
-						return false;
-				}
-
-				return NetworkToHostOrder((short)address.m_Numbers[7]) == 1;
-			}
-		}
-
-		/// <summary>
-		///   Overrides System.Object.ToString to return
-		///   this object rendered in a quad-dotted notation
-		/// </summary>
-		public override string ToString ()
-		{
-			if(m_Family == AddressFamily.InterNetwork)
-				return ToString (m_Address);
-			else
-			{
-				ushort[] numbers = m_Numbers.Clone() as ushort[];
-
-				for(int i=0; i<numbers.Length; i++)
-					numbers[i] = (ushort)NetworkToHostOrder((short)numbers[i]);
-
-				IPv6Address v6 = new IPv6Address(numbers);
-				v6.ScopeId = ScopeId;
-				return v6.ToString();
-			}
-		}
-
-		/// <summary>
-		///   Returns this object rendered in a quad-dotted notation
-		/// </summary>
-		static string ToString (long addr)
-		{
-			// addr is in network order
-			return  (addr & 0xff).ToString () + "." +
-				((addr >> 8) & 0xff).ToString () + "." +
-				((addr >> 16) & 0xff).ToString () + "." +
-				((addr >> 24) & 0xff).ToString ();
-		}
-
-		/// <returns>
-		///   Whether both objects are equal.
-		/// </returns>
-		public override bool Equals (object comparand)
-		{
-			IPAddress otherAddr = comparand as IPAddress;
-			if (otherAddr != null){
-				if(AddressFamily != otherAddr.AddressFamily)
-					return false;
-
-				if(AddressFamily == AddressFamily.InterNetwork) {
-					return m_Address == otherAddr.m_Address;
-				} else {
-					ushort[] vals = otherAddr.m_Numbers;
-
-					for(int i=0; i<8; i++)
-						if(m_Numbers[i] != vals[i])
-							return false;
-
-					return true;
-				}
-			}
-			return false;
-		}
-
-		public override int GetHashCode ()
-		{
-			if(m_Family == AddressFamily.InterNetwork)
-				return (int)m_Address;
-			else
-				return Hash (((((int) m_Numbers[0]) << 16) + m_Numbers [1]), 
-					((((int) m_Numbers [2]) << 16) + m_Numbers [3]),
-					((((int) m_Numbers [4]) << 16) + m_Numbers [5]),
-					((((int) m_Numbers [6]) << 16) + m_Numbers [7]));
-		}
-
-		private static int Hash (int i, int j, int k, int l) 
-		{
-			return i ^ (j << 13 | j >> 19) ^ (k << 26 | k >> 6) ^ (l << 7 | l >> 25);
-		}
-
-#pragma warning disable 169
-		// Added for serialization compatibility with MS.NET
-		private int m_HashCode;
-#pragma warning restore
-		
-	}
-}

+ 0 - 212
mcs/class/System/System.Net/IPEndPoint.cs

@@ -1,212 +0,0 @@
-//
-// System.Net.IPEndPoint.cs
-//
-// Author:
-//   Miguel de Icaza ([email protected])
-//
-// (C) Ximian, Inc.  http://www.ximian.com
-//
-
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-// 
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-// 
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-using System.Net.Sockets;
-
-namespace System.Net {
-	[Serializable]
-	public class IPEndPoint : EndPoint {
-
-		private IPAddress address;
-		private int port;
-
-		public const int MaxPort = 65535;
-		public const int MinPort = 0;
-		
-		public IPEndPoint (IPAddress address, int port)
-		{
-			if (address == null)
-				throw new ArgumentNullException ("address");
-
-			Address = address;
-			Port = port;
-		}
-		
-		public IPEndPoint (long address, int port)
-		{
-			Address = new IPAddress (address);
-			Port = port;
-		}
-
-		public IPAddress Address {
-			get {
-				return (address);
-			}
-			set {
-				address=value;
-			}
-		}
-
-		public override AddressFamily AddressFamily {
-			get {
-				return address.AddressFamily;
-			}
-		}
-
-		public int Port {
-			get {
-				return port;
-			}
-			set {
-				// LAMESPEC: no mention of sanity checking
-				// PS: MS controls the range when setting the value
-				if (value < MinPort || value > MaxPort)
-					throw new ArgumentOutOfRangeException ("Invalid port");
-			
-				port = value;
-			}
-		}
-
-		// bytes 2 and 3 store the port, the rest
-		// stores the address
-		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;
-
-			IPEndPoint ipe = null;
-			switch(family)
-			{
-				case AddressFamily.InterNetwork:
-					if (size < 8) {
-						return(null);
-					}
-					
-					port = (((int)sockaddr[2])<<8) + (int)sockaddr[3];
-					long address=(((long)sockaddr[7])<<24) +
-						(((long)sockaddr[6])<<16) +
-						(((long)sockaddr[5])<<8) +
-						(long)sockaddr[4];
-
-					ipe = new IPEndPoint(address, port);
-					break;
-				case AddressFamily.InterNetworkV6:
-					if (size < 28) {
-						return(null);
-					}
-					
-					port	= (((int)sockaddr[2])<<8) + (int)sockaddr[3];
-
-					/// maybe flowid ?
-					/*
-					int unknown	= (int)sockaddr[4] +
-						(((int)sockaddr[5])<<8) +
-						(((int)sockaddr[6])<<16) +
-						(((int)sockaddr[7])<<24);
-					*/
-
-					int scopeId	= (int)sockaddr[24] +
-						(((int)sockaddr[25])<<8) +
-						(((int)sockaddr[26])<<16) +
-						(((int)sockaddr[27])<<24);
-
-					ushort[] addressData = new ushort[8];
-					for(int i=0; i<8; i++)
-						addressData[i] = (ushort)((sockaddr[8+i*2] << 8) + sockaddr[8+i*2+1]);
-
-					ipe = new IPEndPoint (new IPAddress(addressData, scopeId), port);
-					break;
-				default:
-					return null;
-			}
-
-			return(ipe);
-		}
-
-		public override SocketAddress Serialize() {
-			SocketAddress sockaddr = null;
-
-			switch (address.AddressFamily)
-			{
-				case AddressFamily.InterNetwork:
-					// .net produces a 16 byte buffer, even though
-					// only 8 bytes are used. I guess its just a
-					// holdover from struct sockaddr padding.
-					sockaddr = new SocketAddress(AddressFamily.InterNetwork, 16);
-
-					// bytes 2 and 3 store the port, the rest
-					// stores the address
-					sockaddr [2] = (byte) ((port>>8) & 0xff);
-					sockaddr [3] = (byte) (port & 0xff);
-					long addr = address.InternalIPv4Address;
-					sockaddr [4] = (byte) (addr & 0xff);
-					sockaddr [5] = (byte) ((addr >> 8) & 0xff);
-					sockaddr [6] = (byte) ((addr >> 16) & 0xff);
-					sockaddr [7] = (byte) ((addr >> 24) & 0xff);
-					break;
-
-				case AddressFamily.InterNetworkV6:
-					sockaddr = new SocketAddress(AddressFamily.InterNetworkV6, 28);
-
-					sockaddr [2] = (byte) ((port>>8) & 0xff);
-					sockaddr [3] = (byte) (port & 0xff);
-
-					byte[] addressBytes = address.GetAddressBytes();
-					for(int i=0; i<16; i++)
-						sockaddr[8+i] = addressBytes[i];
-					
-					sockaddr [24] = (byte) (address.ScopeId & 0xff);
-					sockaddr [25] = (byte) ((address.ScopeId >> 8) & 0xff);
-					sockaddr [26] = (byte) ((address.ScopeId >> 16) & 0xff);
-					sockaddr [27] = (byte) ((address.ScopeId >> 24) & 0xff);
-					break;
-			}
-
-			return(sockaddr);
-		}
-
-		public override string ToString() {
-			return(address.ToString() + ":" + port);
-		}
-
-		public override bool Equals (object comparand)
-		{
-			IPEndPoint p = comparand as IPEndPoint;
-			return p != null && 
-			       p.port == port && 
-			       p.address.Equals (address);
-		}
-
-		public override int GetHashCode ()
-		{
-			return address.GetHashCode () + port;
-		}
-	}
-}

+ 45 - 366
mcs/class/System/System.Net/IPv6Address.cs

@@ -1,16 +1,8 @@
 //
-// System.Net.IPv6Address.cs
+// System.Net.IPv6AddressFormatter.cs
 //
 // Author:
 //   Lawrence Pit ([email protected])
-//
-// Note I: This class is not defined in the specs of .Net
-//
-// Note II : The name of this class is perhaps unfortunate as it turns
-//           out that in ms.net there's an internal class called
-//           IPv6Address in namespace System.
-//
-
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -32,284 +24,35 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
-
-using System;
 using System.Globalization;
-using System.Net.Sockets;
-using System.Runtime.InteropServices;
 using System.Text;
 
 namespace System.Net {
 
-	/// <remarks>
-	///   Encapsulates an IPv6 Address.
-	///   See RFC 2373 for more info on IPv6 addresses.
-	/// </remarks>
-	[Serializable]
-	internal class IPv6Address {
-		private ushort [] address;
-		private int prefixLength;
-		private long scopeId = 0;
-
-		public static readonly IPv6Address Loopback = IPv6Address.Parse ("::1");
-		public static readonly IPv6Address Unspecified = IPv6Address.Parse ("::");
+	struct IPv6AddressFormatter
+	{
+		ushort [] address;
+		long scopeId;
 
-		public IPv6Address (ushort [] addr)
-		{
-			if (addr == null)
-				throw new ArgumentNullException ("addr");	
-			if (addr.Length != 8)	
-				throw new ArgumentException ("addr");
-			address = addr;			
-		}
-		
-		public IPv6Address (ushort [] addr, int prefixLength) : this (addr)
-		{
-			if (prefixLength < 0 || prefixLength > 128)
-				throw new ArgumentException ("prefixLength");
-			this.prefixLength = prefixLength;
-		}
-	
-		public IPv6Address (ushort [] addr, int prefixLength, int scopeId) : this (addr, prefixLength)
+		public IPv6AddressFormatter (ushort[] addr, long scopeId)
 		{
+			this.address = addr;
 			this.scopeId = scopeId;
 		}
 
-		public static IPv6Address Parse (string ipString)
-		{
-			if (ipString == null)
-				throw new ArgumentNullException ("ipString");
-
-			IPv6Address result;
-			if (TryParse (ipString, out result))
-				return result;
-			throw new FormatException ("Not a valid IPv6 address");
-		}
-
-		static int Fill (ushort [] addr, string ipString)
-		{
-			int p = 0;
-			int pdigits = 0;
-			int slot = 0;
-
-			if (ipString.Length == 0)
-				return 0;
-			
-			// Catch double uses of ::
-			if (ipString.IndexOf ("::", StringComparison.Ordinal) != -1)
-				return -1;
-
-			for (int i = 0; i < ipString.Length; i++){
-				char c = ipString [i];
-				int n;
-
-				if (c == ':'){
-					// Leading : is not allowed.
-					if (i == 0)
-                                               return -1;
-				       
-					// Trailing : is not allowed.
-					if (i == ipString.Length-1)
-						return -1;
-					
-					if (slot == 8)
-						return -1;
-					
-					addr [slot++] = (ushort) p;
-					p = 0;
-					pdigits = 0;
-					continue;
-				}
-				pdigits++;
-				if (pdigits > 4)
-					return -1;
-				if ('0' <= c && c <= '9')
-					n = (int) (c - '0');
-				else if ('a' <= c && c <= 'f')
-					n = (int) (c - 'a' + 10);
-				else if ('A' <= c && c <= 'F')
-					n = (int) (c - 'A' + 10);
-				else 
-					return -1;
-				p = (p << 4) + n;
-				if (p > UInt16.MaxValue)
-					return -1;
-			}
-
-			if (slot == 8)
-				return -1;
-			
-			addr [slot++] = (ushort) p;
-
-			return slot;
-		}
-
-		static bool TryParse (string prefix, out int res)
-		{
-			return Int32.TryParse (prefix, NumberStyles.Integer, CultureInfo.InvariantCulture, out res);
-		}
-		
-		public static bool TryParse (string ipString, out IPv6Address result)
-		{
-			result = null;
-			if (ipString == null)
-				return false;
-
-			if (ipString.Length > 2 && 
-			    ipString [0] == '[' && 
-			    ipString [ipString.Length - 1] == ']')
-				ipString = ipString.Substring (1, ipString.Length - 2);
-
-			if (ipString.Length  < 2)
-				return false;
-
-			int prefixLen = 0;
-			int scopeId = 0;
-			int pos = ipString.LastIndexOf ('/');
-			if (pos != -1) {
-				string prefix = ipString.Substring (pos + 1);
-				if (!TryParse (prefix , out prefixLen))
-					prefixLen = -1;
-				if (prefixLen < 0 || prefixLen > 128)
-					return false;
-				ipString = ipString.Substring (0, pos);
-			} else {
-				pos = ipString.LastIndexOf ('%');
-				if (pos != -1) {
-					string prefix = ipString.Substring (pos + 1);
-					if (!TryParse (prefix, out scopeId))
-						scopeId = 0;
-					ipString = ipString.Substring (0, pos);
-				}			
-			}
-
-			//
-			// At this point the prefix/suffixes have been removed
-			// and we only have to deal with the ipv4 or ipv6 addressed
-			//
-			ushort [] addr = new ushort [8];
-
-			//
-			// Is there an ipv4 address at the end?
-			//
-			int pos2 = ipString.LastIndexOf (':');
-			if (pos2 == -1)
-				return false;
-
-			int slots = 0;
-			if (pos2 < (ipString.Length - 1)) {
-				string ipv4Str = ipString.Substring (pos2 + 1);
-				if (ipv4Str.IndexOf ('.') != -1) {
-					IPAddress ip;
-					
-					if (!IPAddress.TryParse (ipv4Str, out ip))
-						return false;
-					
-					long a = ip.InternalIPv4Address;
-					addr [6] = (ushort) (((int) (a & 0xff) << 8) + ((int) ((a >> 8) & 0xff)));
-					addr [7] = (ushort) (((int) ((a >> 16) & 0xff) << 8) + ((int) ((a >> 24) & 0xff)));
-					if (pos2 > 0 && ipString [pos2 - 1] == ':') 
-						ipString = ipString.Substring (0, pos2 + 1);
-					else
-						ipString = ipString.Substring (0, pos2);
-					slots = 2;
-				}
-			}	
-
-			//
-			// Only an ipv6 block remains, either:
-			// "hexnumbers::hexnumbers", "hexnumbers::" or "hexnumbers"
-			//
-			int c = ipString.IndexOf ("::", StringComparison.Ordinal);
-			if (c != -1){
-				int right_slots = Fill (addr, ipString.Substring (c+2));
-				if (right_slots == -1){
-					return false;
-				}
-
-				if (right_slots + slots > 8){
-					return false;
-				}
-
-				int d = 8-slots-right_slots;
-				for (int i = right_slots; i > 0; i--){
-					addr [i+d-1] = addr [i-1];
-					addr [i-1] = 0;
-				}
-				
-				int left_slots = Fill (addr, ipString.Substring (0, c));
-				if (left_slots == -1)
-					return false;
-
-				if (left_slots + right_slots + slots > 7)
-					return false;
-			} else {
-				if (Fill (addr, ipString) != 8-slots)
-					return false;
-			}
-
-			result = new IPv6Address (addr, prefixLen, scopeId);
-			return true;
-		}
-
-		public ushort [] Address {
-			get { return address; }
-		}
-
-		public int PrefixLength {
-			get { return this.prefixLength; }
-		}
-		
-		public long ScopeId {
-			get {
-				return scopeId;
-			}
-			set {
-				scopeId = value;
-			}
-		}
-
-		public ushort this [int index] {
-			get { return address [index]; }
-		}		
-
-		public AddressFamily AddressFamily {
-			get { return AddressFamily.InterNetworkV6; }
-		}
-
-		public static bool IsLoopback (IPv6Address addr)
-		{
-			if (addr.address [7] != 1)
-				return false;
-
-			int x = addr.address [6] >> 8;
-			if (x != 0x7f && x != 0)
-				return false;
-
-			for (int i = 0; i < 4; i++) {
-				if (addr.address [i] != 0)
-					return false;
-			}
-
-			if (addr.address [5] != 0 && addr.address [5] != 0xffff)
-				return false;
-
-			return true;
-		}
-
-		private static ushort SwapUShort (ushort number)
+		static ushort SwapUShort (ushort number)
 		{
 			return (ushort) ( ((number >> 8) & 0xFF) + ((number << 8) & 0xFF00) );
 		}
 
 		// Convert the address into a format expected by the IPAddress (long) ctor
 		// This needs to be unsigned to satisfy the '> 1' test in IsIPv4Compatible()
-		private uint AsIPv4Int ()
+		uint AsIPv4Int ()
 		{
 			return (uint)(SwapUShort (address [7]) << 16) + SwapUShort (address [6]);
 		}			
 
-		public bool IsIPv4Compatible ()
+		bool IsIPv4Compatible ()
 		{
 			for (int i = 0; i < 6; i++) 
 				if (address [i] != 0)
@@ -323,7 +66,7 @@ namespace System.Net {
 			return (AsIPv4Int () > 1);
 		}
 		
-		public bool IsIPv4Mapped ()
+		bool IsIPv4Mapped ()
 		{
 			for (int i = 0; i < 5; i++) 
 				if (address [i] != 0)
@@ -338,10 +81,6 @@ namespace System.Net {
 			return address [5] == 0xffff;
 		}
 		
-		/// <summary>
-		///   Overrides System.Object.ToString to return
-		///   this object rendered in a canonicalized notation
-		/// </summary>
 		public override string ToString ()
 		{
 			StringBuilder s = new StringBuilder ();
@@ -358,112 +97,52 @@ namespace System.Net {
 
 				return s.ToString ();
 			}
-			else
-			{
-				int bestChStart = -1; // Best chain start
-				int bestChLen = 0; // Best chain length
-				int currChLen = 0; // Current chain length
+			
+			int bestChStart = -1; // Best chain start
+			int bestChLen = 0; // Best chain length
+			int currChLen = 0; // Current chain length
 
-				// Looks for the longest zero chain
-				for (int i=0; i<8; i++)
+			// Looks for the longest zero chain
+			for (int i=0; i<8; i++)
+			{
+				if (address[i] != 0)
 				{
-					if (address[i] != 0)
+					if ((currChLen > bestChLen) 
+						&& (currChLen > 1))
 					{
-						if ((currChLen > bestChLen) 
-							&& (currChLen > 1))
-						{
-							bestChLen = currChLen;
-							bestChStart = i - currChLen;
-						}
-						currChLen = 0;
+						bestChLen = currChLen;
+						bestChStart = i - currChLen;
 					}
-					else
-						currChLen++;
-				}
-				if ((currChLen > bestChLen) 
-					&& (currChLen > 1))
-				{
-					bestChLen = currChLen;
-					bestChStart = 8 - currChLen;
+					currChLen = 0;
 				}
+				else
+					currChLen++;
+			}
+			if ((currChLen > bestChLen) 
+				&& (currChLen > 1))
+			{
+				bestChLen = currChLen;
+				bestChStart = 8 - currChLen;
+			}
 
-				// makes the string
-				if (bestChStart == 0)
-					s.Append(":");
-				for (int i=0; i<8; i++)
+			// makes the string
+			if (bestChStart == 0)
+				s.Append(":");
+			for (int i=0; i<8; i++)
+			{
+				if (i == bestChStart)
 				{
-					if (i == bestChStart)
-					{
-						s.Append (":");
-						i += (bestChLen - 1);
-						continue;
-					}
-					s.AppendFormat("{0:x}", address [i]);
-					if (i < 7) s.Append (':');
+					s.Append (":");
+					i += (bestChLen - 1);
+					continue;
 				}
+				s.AppendFormat("{0:x}", address [i]);
+				if (i < 7) s.Append (':');
 			}
+			
 			if (scopeId != 0)
 				s.Append ('%').Append (scopeId);
 			return s.ToString ();
 		}
-
-		public string ToString (bool fullLength)
-		{
-			if (!fullLength)
-				return ToString ();
-
-			StringBuilder sb = new StringBuilder ();
-			for (int i=0; i < address.Length - 1; i++) {
-				sb.AppendFormat ("{0:X4}:", address [i]);
-			}
-			sb.AppendFormat ("{0:X4}", address [address.Length - 1]);
-			return sb.ToString ();
-		}
-
-		/// <returns>
-		///   Whether both objects are equal.
-		/// </returns>
-		public override bool Equals (object other)
-		{
-			System.Net.IPv6Address ipv6 = other as System.Net.IPv6Address;
-			if (ipv6 != null) {
-				for (int i = 0; i < 8; i++) 
-					if (this.address [i] != ipv6.address [i])
-						return false;
-				return true;
-			}
-			
-			System.Net.IPAddress ipv4 = other as System.Net.IPAddress;
-			if (ipv4 != null) {
-				for (int i = 0; i < 5; i++) 
-					if (address [i] != 0)
-						return false;
-
-				if (address [5] != 0 && address [5] != 0xffff)
-					return false;
-
-				long a = ipv4.InternalIPv4Address;
-				if (address [6] != (ushort) (((int) (a & 0xff) << 8) + ((int) ((a >> 8) & 0xff))) ||
-				    address [7] != (ushort) (((int) ((a >> 16) & 0xff) << 8) + ((int) ((a >> 24) & 0xff))))
-					return false;
-
-				return true;
-			}
-			
-			return false;
-		}
-
-		public override int GetHashCode ()
-		{
-			return Hash (((((int) address [0]) << 16) + address [1]), 
-						((((int) address [2]) << 16) + address [3]),
-						((((int) address [4]) << 16) + address [5]),
-						((((int) address [6]) << 16) + address [7]));
-		}
-		
-		private static int Hash (int i, int j, int k, int l) 
-		{
-			return i ^ (j << 13 | j >> 19) ^ (k << 26 | k >> 6) ^ (l << 7 | l >> 25);
-		}
 	}
 }

+ 0 - 122
mcs/class/System/System.Net/SocketAddress.cs

@@ -1,122 +0,0 @@
-//
-// System.Net.SocketAddress.cs
-//
-// Author:
-//   Miguel de Icaza ([email protected])
-//   Dick Porter ([email protected])
-//
-// (C) Ximian, Inc.  http://www.ximian.com
-//
-
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-// 
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-// 
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-using System.Net.Sockets;
-
-namespace System.Net {
-
-	public class SocketAddress {
-		private byte[] data;
-		
-		public SocketAddress (AddressFamily family, int size)
-		{
-			if(size<2) {
-				throw new ArgumentOutOfRangeException("size is too small");
-			}
-			
-			data=new byte[size];
-			data[0]=(byte)family;
-			data[1]=(byte) ((int) family >> 8);
-		}
-
-		public SocketAddress (AddressFamily family)
-			: this (family, 32)
-		{
-		}
-		
-		//LAMESPEC: the MS doc about this class is wrong. The size is not stored in byte 1. Instead
-		// byte [0] and byte [1] hold the family (little endian).
-		public AddressFamily Family {
-			get {
-				return (AddressFamily) (data [0] + (data [1] << 8));
-			}
-		}
-
-		public int Size {
-			get {
-				return data.Length;
-			}
-		}
-
-		public byte this [ int offset ] {
-			get {
-				return(data[offset]);
-			}
-
-			set {
-				data[offset]=value;
-			}
-		}
-
-		public override string ToString() {
-			string af=((AddressFamily)data[0]).ToString();
-			int size = data.Length;
-			string ret=af+":"+size+":{";
-			
-			for(int i=2; i<size; i++) {
-				int val=(int)data[i];
-				ret=ret+val;
-				if(i<size-1) {
-					ret=ret+",";
-				}
-			}
-			
-			ret=ret+"}";
-			
-			return(ret);
-		}
-
-		public override bool Equals (object comparand)
-		{
-			SocketAddress sa = (comparand as SocketAddress);
-			if ((sa != null) && (sa.data.Length == data.Length)) {
-				byte [] otherData = sa.data;
-				for (int i = 0; i < data.Length; i++)
-					if (otherData [i] != data [i])
-						return false;
-
-				return true;
-			}
-
-			return false;
-		}
-
-		public override int GetHashCode ()
-		{
-			int code = 0;
-
-			for (int i = 0; i < data.Length; i++)
-				code += data [i] + i;
-
-			return code;
-		}
-	}
-}

+ 5 - 5
mcs/class/System/System.dll.sources

@@ -253,10 +253,8 @@ System.Net/DecompressionMethods.cs
 System.Net/DefaultCertificatePolicy.cs
 System.Net/DigestClient.cs
 System.Net/Dns.cs
-System.Net/DnsEndPoint.cs
 System.Net/DnsPermissionAttribute.cs
 System.Net/DnsPermission.cs
-System.Net/EndPoint.cs
 System.Net/EndPointListener.cs
 System.Net/EndPointManager.cs
 System.Net/EndpointPermission.cs
@@ -283,8 +281,6 @@ System.Net/HttpStreamAsyncResult.cs
 System.Net/HttpWebRequest.cs
 System.Net/HttpWebResponse.cs
 System.Net/ICredentialPolicy.cs
-System.Net/IPAddress.cs
-System.Net/IPEndPoint.cs
 System.Net/IPv6Address.cs
 System.Net/IWebProxyScript.cs
 System.Net/IWebConnectionState.cs
@@ -410,7 +406,6 @@ System.Net/ServicePoint.cs
 System.Net/ServicePointManager.cs
 System.Net/ServicePointManager.extra.cs
 System.Net/SimpleAsyncResult.cs
-System.Net/SocketAddress.cs
 System.Net/SocketPermissionAttribute.cs
 System.Net/SocketPermission.cs
 ../referencesource/System/net/System/Net/Sockets/AddressFamily.cs
@@ -1013,6 +1008,8 @@ ReferenceSources/_SslStream.cs
 ../referencesource/System/net/System/Net/cookiecollection.cs
 ../referencesource/System/net/System/Net/cookiecontainer.cs
 ../referencesource/System/net/System/Net/cookieexception.cs
+../referencesource/System/net/System/Net/DnsEndPoint.cs
+../referencesource/System/net/System/Net/EndPoint.cs
 ../referencesource/System/net/System/Net/FtpStatusCode.cs
 ../referencesource/System/net/System/Net/HttpListenerException.cs
 ../referencesource/System/net/System/Net/HttpListenerRequestUriBuilder.cs
@@ -1025,6 +1022,8 @@ ReferenceSources/_SslStream.cs
 ../referencesource/System/net/System/Net/ICredentials.cs
 ../referencesource/System/net/System/Net/ICredentialsByHost.cs
 ../referencesource/System/net/System/Net/Internal.cs
+../referencesource/System/net/System/Net/IPAddress.cs
+../referencesource/System/net/System/Net/IPEndPoint.cs
 ../referencesource/System/net/System/Net/IPHostEntry.cs
 ../referencesource/System/net/System/Net/iwebproxy.cs
 ../referencesource/System/net/System/Net/IWebRequestCreate.cs
@@ -1035,6 +1034,7 @@ ReferenceSources/_SslStream.cs
 ../referencesource/System/net/System/Net/UnicodeDecodingConformance.cs
 ../referencesource/System/net/System/Net/UnicodeEncodingConformance.cs
 ../referencesource/System/net/System/Net/ServicePointManager.cs
+../referencesource/System/net/System/Net/SocketAddress.cs
 ../referencesource/System/net/System/Net/webclient.cs
 ../referencesource/System/net/System/Net/WebException.cs
 ../referencesource/System/net/System/Net/WebExceptionStatus.cs

+ 30 - 30
mcs/class/System/Test/System.Net/IPAddressTest.cs

@@ -145,16 +145,8 @@ public class IPAddressTest
 		"0xff.0x7f.0x20.0xf", "255.127.32.15",
 		"0.0.0.0", IPAddress.Any.ToString(),
 		"255.255.255.255", IPAddress.Broadcast.ToString(),
-		"12.1.1.3 abc", "12.1.1.3",
-		"12.1 .1.2", "12.0.0.1",
-		"12.1 .zzzz.2", "12.0.0.1",
 		"12.1.7", "12.1.0.7",
 		"12", "0.0.0.12",
-		"12.5.3 foo.67.test.test.7FFFFFFFFFfaFFF789FFFFFFFFFFFFFFF", "12.5.0.3",
-		"12.1 foo.bar.test.test.baf", "12.0.0.1",
-		"12.1.4.6 foo.bar.test.test.baf", "12.1.4.6",
-		"12.3 foo.bar.test.test.4", "12.0.0.3",
-		"12 foo.bar.test.test.baf", "0.0.0.12",
 		"65536", "0.1.0.0",
 		"65535", "0.0.255.255",
 		"20.65535", "20.0.255.255",
@@ -187,6 +179,14 @@ public class IPAddressTest
 		"12...",
 		"  ",
 		"7848198702",
+		"12.1.1.3 abc",
+		"12.1 .1.2",
+		"12.1 .zzzz.2",
+		"12.5.3 foo.67.test.test.7FFFFFFFFFfaFFF789FFFFFFFFFFFFFFF",
+		"12.1 foo.bar.test.test.baf",
+		"12.1.4.6 foo.bar.test.test.baf",
+		"12.3 foo.bar.test.test.4",
+		"12 foo.bar.test.test.baf",
 	};
 
 	static byte [] ipv4MappedIPv6Prefix = new byte [] { 0,0, 0,0, 0,0, 0,0, 0,0, 0xFF,0xFF };
@@ -197,8 +197,8 @@ public class IPAddressTest
 		Assert.AreEqual ((long) 0, IPAddress.Any.Address, "#1");
 		Assert.AreEqual ((long) 0xFFFFFFFF, IPAddress.Broadcast.Address, "#2");
 		long loopback = IPAddress.HostToNetworkOrder (BitConverter.IsLittleEndian ? 
-							      0x7f000001 : 
-							      0x0100007f);
+								  0x7f000001 : 
+								  0x0100007f);
 		Assert.AreEqual (loopback, IPAddress.Loopback.Address, "#3");
 		Assert.AreEqual ((long) 0xFFFFFFFF, IPAddress.None.Address, "#4");
 	}
@@ -241,8 +241,8 @@ public class IPAddressTest
 	[Test]
 	public void IsLoopbackV6 ()
 	{
-		if (!Socket.SupportsIPv6)
-			Assert.Ignore ("IPv6 must be enabled in machine.config");
+//		if (!Socket.SupportsIPv6)
+//			Assert.Ignore ("IPv6 must be enabled in machine.config");
 
 		IPAddress ip = IPAddress.IPv6Loopback;
 		Assert.IsTrue (IPAddress.IsLoopback (ip), "#1");
@@ -277,24 +277,16 @@ public class IPAddressTest
 	[Test]
 	public void Address ()
 	{
-		// hm, lame, anything is accepted by ms.net
-		/*
 		try {
 			IPAddress ip1 = new IPAddress (0x0000000100000000);
 			Assertion.Fail ("#1");
 		} catch (ArgumentOutOfRangeException) {}
+		
 		IPAddress ip = IPAddress.Parse ("127.0.0.1");
 		ip.Address = 0;
 		ip.Address = 0xffffffff;
-		try {
-			ip.Address = -1;
-			Assertion.Fail ("#2");
-		} catch (ArgumentOutOfRangeException) {}
-		try {
-			ip.Address = 0x0000000100000000;
-			Assertion.Fail ("#3");
-		} catch (ArgumentOutOfRangeException) {}
-		*/
+		ip.Address = -1;
+		ip.Address = 0x0000000100000000;
 	}
 
 	[Test]
@@ -620,8 +612,8 @@ public class IPAddressTest
 	[Test]
 	public void ParseWrongV6 ()
 	{
-		if (!Socket.SupportsIPv6)
-			Assert.Ignore ("IPv6 must be enabled in machine.config");
+		//if (!Socket.SupportsIPv6)
+		//	Assert.Ignore ("IPv6 must be enabled in machine.config");
 
 		for (int i = 0; i < ipv6ParseWrong.Length; i++) {
 			string ipAddress = ipv6ParseWrong [i];
@@ -631,14 +623,12 @@ public class IPAddressTest
 				Assert.Fail ("#1:" + i + " (" + ipAddress + ")");
 			} catch (FormatException ex) {
 				Assert.AreEqual (typeof (FormatException), ex.GetType (), "#2:" + i);
-				Assert.IsNull (ex.InnerException, "#3:" + i);
+				Assert.AreEqual(typeof(SocketException), ex.InnerException.GetType (), "#3:" + i);
 				Assert.IsNotNull (ex.Message, "#4:" + i);
 			}
 		}
 	}
 
-#if NET_4_5
-
 	[Test]
 	public void MapToIPv6 ()
 	{
@@ -673,8 +663,6 @@ public class IPAddressTest
 		return true;
 	}
 
-#endif
-
 	[Test]
 	public void EqualsFromBytes ()
 	{
@@ -686,6 +674,18 @@ public class IPAddressTest
 
 	}
 
+	[Test]
+	[Category ("NotDotNet")]
+	public void UnixInterfaceNameAsZoneIndex ()
+	{
+		var ip = IPAddress.Parse ("fe80::bae8:56ff:fe47:af7e%en0");
+
+		// Should be en0 but it's of long type!
+		Assert.AreEqual (0, ip.ScopeId);
+		
+		Assert.AreEqual ("fe80::bae8:56ff:fe47:af7e", ip.ToString ());
+	}
+
 }
 }
 

+ 5 - 7
mcs/class/System/mobile_System.dll.sources

@@ -132,7 +132,6 @@ System.Net.Security/NegotiateStream.cs
 System.Net.Security/RemoteCertificateValidationCallback.cs
 System.Net.Security/SslPolicyErrors.cs
 System.Net.Security/SslStream.cs
-System.Net/SocketAddress.cs
 System.Net/SocketPermissionAttribute.cs
 System.Net/SocketPermission.cs
 ../referencesource/System/net/System/Net/Sockets/AddressFamily.cs
@@ -175,8 +174,6 @@ System.Net/DecompressionMethods.cs
 System.Net/DefaultCertificatePolicy.cs
 System.Net/DigestClient.cs
 System.Net/Dns.cs
-System.Net/DnsEndPoint.cs
-System.Net/EndPoint.cs
 System.Net/EndPointListener.cs
 System.Net/EndPointManager.cs
 System.Net/EndpointPermission.cs
@@ -203,9 +200,6 @@ System.Net/HttpStreamAsyncResult.cs
 System.Net/HttpWebRequest.cs
 System.Net/HttpWebResponse.cs
 System.Net/ICredentialPolicy.cs
-System.Net/IPAddress.cs
-System.Net/IPAddress.cs
-System.Net/IPEndPoint.cs
 System.Net/IPv6Address.cs
 System.Net/IPv6Address.cs
 System.Net/IWebConnectionState.cs
@@ -222,7 +216,6 @@ System.Net/ServicePoint.cs
 System.Net/ServicePointManager.cs
 System.Net/ServicePointManager.extra.cs
 System.Net/SimpleAsyncResult.cs
-System.Net/SocketAddress.cs
 System.Net/WebAsyncResult.cs
 System.Net/WebConnection.cs
 System.Net/WebConnectionData.cs
@@ -727,6 +720,8 @@ ReferenceSources/Win32Exception.cs
 ../referencesource/System/net/System/Net/cookiecollection.cs
 ../referencesource/System/net/System/Net/cookiecontainer.cs
 ../referencesource/System/net/System/Net/cookieexception.cs
+../referencesource/System/net/System/Net/DnsEndPoint.cs
+../referencesource/System/net/System/Net/EndPoint.cs
 ../referencesource/System/net/System/Net/FtpStatusCode.cs
 ../referencesource/System/net/System/Net/HttpListenerException.cs
 ../referencesource/System/net/System/Net/HttpRequestHeader.cs
@@ -739,6 +734,8 @@ ReferenceSources/Win32Exception.cs
 ../referencesource/System/net/System/Net/ICredentials.cs
 ../referencesource/System/net/System/Net/ICredentialsByHost.cs
 ../referencesource/System/net/System/Net/Internal.cs
+../referencesource/System/net/System/Net/IPAddress.cs
+../referencesource/System/net/System/Net/IPEndPoint.cs
 ../referencesource/System/net/System/Net/IPHostEntry.cs
 ../referencesource/System/net/System/Net/iwebproxy.cs
 ../referencesource/System/net/System/Net/IWebRequestCreate.cs
@@ -749,6 +746,7 @@ ReferenceSources/Win32Exception.cs
 ../referencesource/System/net/System/Net/UnicodeDecodingConformance.cs
 ../referencesource/System/net/System/Net/UnicodeEncodingConformance.cs
 ../referencesource/System/net/System/Net/ServicePointManager.cs
+../referencesource/System/net/System/Net/SocketAddress.cs
 ../referencesource/System/net/System/Net/webclient.cs
 ../referencesource/System/net/System/Net/WebException.cs
 ../referencesource/System/net/System/Net/WebExceptionStatus.cs

+ 1 - 1
mcs/class/corlib/System/Environment.cs

@@ -57,7 +57,7 @@ namespace System {
 		 * of icalls, do not require an increment.
 		 */
 #pragma warning disable 169
-		private const int mono_corlib_version = 146;
+		private const int mono_corlib_version = 147;
 #pragma warning restore 169
 
 		[ComVisible (true)]

+ 19 - 3
mcs/class/referencesource/System/net/System/Net/IPAddress.cs

@@ -171,7 +171,7 @@ namespace System.Net {
             //
             if (ipString.IndexOf(':') != -1 ) {
 
-#if !FEATURE_PAL
+#if !FEATURE_PAL || MONO
                 //
                 // If the address string contains the colon character
                 // then it can only be an IPv6 address. Use a separate
@@ -184,6 +184,7 @@ namespace System.Net {
                 //
                 SocketException e = null;
                 long   scope = 0;
+#if !MONO
                 if(Socket.OSSupportsIPv6)
                 {
                     byte[] bytes = new byte[IPv6AddressBytes];
@@ -221,6 +222,7 @@ namespace System.Net {
                     e = new SocketException();
                 }
                 else
+#endif
                 {
                     unsafe
                     {
@@ -251,7 +253,14 @@ namespace System.Net {
                                 scopeId = scopeId.Substring(1);
                                 if (UInt32.TryParse(scopeId, NumberStyles.None, null, out result))
                                     return new IPAddress(numbers, result);
-
+#if MONO
+                                //
+                                // HACK: .NET does not support scopes with literals at all (API is long based)
+                                // For backward Mono compatibility parsing IPv6 addresses like
+                                // fe80::bae8:56ff:fe47:af7e%en0 will loose en0 information
+                                //
+                                return new IPAddress(numbers, 0);
+#endif
                             }
                         }
                     }
@@ -271,12 +280,13 @@ namespace System.Net {
             else
             // The new IPv4 parser is better than the native one, it can parse 0xFFFFFFFF. (It's faster too).
             {
+#if !MONO
                 // App-Compat: The .NET 4.0 parser used Winsock.  When we removed this initialization in 4.5 it 
                 // uncovered bugs in IIS's management APIs where they failed to initialize Winsock themselves.
                 // DDCC says we need to keep this for an in place release, but to remove it in the next SxS release.
                 Socket.InitializeSockets();
                 ///////////////////////////
-
+#endif
                 int end = ipString.Length;
                 long result;
                 unsafe
@@ -473,8 +483,14 @@ namespace System.Net {
 
                     m_ToString = addressString.ToString();
 #else // !FEATURE_PAL
+
+#if MONO
+                    var v6 = new IPv6AddressFormatter (m_Numbers, ScopeId);
+                    m_ToString = v6.ToString ();
+#else
                     // IPv6 addresses not supported for FEATURE_PAL
                     throw new SocketException(SocketError.OperationNotSupported);
+#endif
 #endif // !FEATURE_PAL
                 }
                 else {

+ 1 - 1
mono/metadata/appdomain.c

@@ -81,7 +81,7 @@
  * Changes which are already detected at runtime, like the addition
  * of icalls, do not require an increment.
  */
-#define MONO_CORLIB_VERSION 146
+#define MONO_CORLIB_VERSION 147
 
 typedef struct
 {

+ 1 - 0
mono/metadata/domain-internals.h

@@ -409,6 +409,7 @@ struct _MonoDomain {
 	MonoImage *socket_assembly;
 	MonoClass *sockaddr_class;
 	MonoClassField *sockaddr_data_field;
+	MonoClassField *sockaddr_data_length_field;
 
 	/* Cache function pointers for architectures  */
 	/* that require wrappers */

+ 43 - 19
mono/metadata/socket-io.c

@@ -841,10 +841,16 @@ create_object_from_sockaddr (struct sockaddr *saddr, int sa_size, gint32 *werror
 	
 	/* Locate the SocketAddress data buffer in the object */
 	if (!domain->sockaddr_data_field) {
-		domain->sockaddr_data_field = mono_class_get_field_from_name (domain->sockaddr_class, "data");
+		domain->sockaddr_data_field = mono_class_get_field_from_name (domain->sockaddr_class, "m_Buffer");
 		g_assert (domain->sockaddr_data_field);
 	}
 
+	/* Locate the SocketAddress data buffer length in the object */
+	if (!domain->sockaddr_data_length_field) {
+		domain->sockaddr_data_length_field = mono_class_get_field_from_name (domain->sockaddr_class, "m_Size");
+		g_assert (domain->sockaddr_data_length_field);
+	}
+
 	/* May be the +2 here is too conservative, as sa_len returns
 	 * the length of the entire sockaddr_in/in6, including
 	 * sizeof (unsigned short) of the family */
@@ -871,8 +877,9 @@ create_object_from_sockaddr (struct sockaddr *saddr, int sa_size, gint32 *werror
 		struct sockaddr_in *sa_in = (struct sockaddr_in *)saddr;
 		guint16 port = ntohs (sa_in->sin_port);
 		guint32 address = ntohl (sa_in->sin_addr.s_addr);
+		int buffer_size = 8;
 		
-		if (sa_size < 8) {
+		if (sa_size < buffer_size) {
 			mono_error_set_exception_instance (error, mono_exception_from_name (mono_get_corlib (), "System", "SystemException"));
 			return NULL;
 		}
@@ -885,15 +892,17 @@ create_object_from_sockaddr (struct sockaddr *saddr, int sa_size, gint32 *werror
 		mono_array_set (data, guint8, 7, (address) & 0xff);
 	
 		mono_field_set_value (sockaddr_obj, domain->sockaddr_data_field, data);
+		mono_field_set_value (sockaddr_obj, domain->sockaddr_data_length_field, &buffer_size);
 
 		return sockaddr_obj;
 	} else if (saddr->sa_family == AF_INET6) {
 		struct sockaddr_in6 *sa_in = (struct sockaddr_in6 *)saddr;
 		int i;
+		int buffer_size = 28;
 
 		guint16 port = ntohs (sa_in->sin6_port);
 
-		if (sa_size < 28) {
+		if (sa_size < buffer_size) {
 			mono_error_set_exception_instance (error, mono_exception_from_name (mono_get_corlib (), "System", "SystemException"));
 			return NULL;
 		}
@@ -921,17 +930,20 @@ create_object_from_sockaddr (struct sockaddr *saddr, int sa_size, gint32 *werror
 						(sa_in->sin6_scope_id >> 24) & 0xff);
 
 		mono_field_set_value (sockaddr_obj, domain->sockaddr_data_field, data);
+		mono_field_set_value (sockaddr_obj, domain->sockaddr_data_length_field, &buffer_size);
 
 		return sockaddr_obj;
 	}
 #ifdef HAVE_SYS_UN_H
 	else if (saddr->sa_family == AF_UNIX) {
 		int i;
+		int buffer_size = sa_size + 2;
 
 		for (i = 0; i < sa_size; i++)
 			mono_array_set (data, guint8, i + 2, saddr->sa_data [i]);
 		
 		mono_field_set_value (sockaddr_obj, domain->sockaddr_data_field, data);
+		mono_field_set_value (sockaddr_obj, domain->sockaddr_data_length_field, &buffer_size);
 
 		return sockaddr_obj;
 	}
@@ -1047,16 +1059,29 @@ ves_icall_System_Net_Sockets_Socket_RemoteEndPoint_internal (SOCKET sock, gint32
 static struct sockaddr*
 create_sockaddr_from_object (MonoObject *saddr_obj, socklen_t *sa_size, gint32 *werror, MonoError *error)
 {
-	MonoClassField *field;
+	MonoDomain *domain = mono_domain_get ();
 	MonoArray *data;
 	gint32 family;
 	int len;
 
 	mono_error_init (error);
 
-	/* Dig the SocketAddress data buffer out of the object */
-	field = mono_class_get_field_from_name (saddr_obj->vtable->klass, "data");
-	data = *(MonoArray **)(((char *)saddr_obj) + field->offset);
+	if (!domain->sockaddr_class)
+		domain->sockaddr_class = mono_class_load_from_name (get_socket_assembly (), "System.Net", "SocketAddress");
+
+	/* Locate the SocketAddress data buffer in the object */
+	if (!domain->sockaddr_data_field) {
+		domain->sockaddr_data_field = mono_class_get_field_from_name (domain->sockaddr_class, "m_Buffer");
+		g_assert (domain->sockaddr_data_field);
+	}
+
+	/* Locate the SocketAddress data buffer length in the object */
+	if (!domain->sockaddr_data_length_field) {
+		domain->sockaddr_data_length_field = mono_class_get_field_from_name (domain->sockaddr_class, "m_Size");
+		g_assert (domain->sockaddr_data_length_field);
+	}
+
+	data = *(MonoArray **)(((char *)saddr_obj) + domain->sockaddr_data_field->offset);
 
 	/* The data buffer is laid out as follows:
 	 * byte 0 is the address family low byte
@@ -1067,12 +1092,9 @@ create_sockaddr_from_object (MonoObject *saddr_obj, socklen_t *sa_size, gint32 *
 	 * UNIX:
 	 * 	the rest is the file name
 	 */
-	len = mono_array_length (data);
-	if (len < 2) {
-		mono_error_set_exception_instance (error, mono_exception_from_name (mono_get_corlib (), "System", "SystemException"));
-		return NULL;
-	}
-	
+	len = *(int *)(((char *)saddr_obj) + domain->sockaddr_data_length_field->offset);
+	g_assert (len >= 2);
+
 	family = convert_family ((MonoAddressFamily)(mono_array_get (data, guint8, 0) + (mono_array_get (data, guint8, 1) << 8)));
 	if (family == AF_INET) {
 		struct sockaddr_in *sa;
@@ -2157,19 +2179,20 @@ ipaddress_to_struct_in6_addr (MonoObject *ipaddr)
 	int i;
 
 	field = mono_class_get_field_from_name (ipaddr->vtable->klass, "m_Numbers");
+	g_assert (field);
 	data = *(MonoArray **)(((char *)ipaddr) + field->offset);
 
-/* Solaris has only the 8 bit version. */
-#ifndef s6_addr16
 	for (i = 0; i < 8; i++) {
-		guint16 s = mono_array_get (data, guint16, i);
+		const guint16 s = GUINT16_TO_BE (mono_array_get (data, guint16, i));
+
+/* Solaris/MacOS have only the 8 bit version. */
+#ifndef s6_addr16
 		in6addr.s6_addr[2 * i + 1] = (s >> 8) & 0xff;
 		in6addr.s6_addr[2 * i] = s & 0xff;
-	}
 #else
-	for (i = 0; i < 8; i++)
-		in6addr.s6_addr16[i] = mono_array_get (data, guint16, i);
+		in6addr.s6_addr16[i] = s;
 #endif
+	}
 	return in6addr;
 }
 #endif
@@ -2274,6 +2297,7 @@ ves_icall_System_Net_Sockets_Socket_SetSocketOption_internal (SOCKET sock, gint3
 				 *	Get group address
 				 */
 				field = mono_class_get_field_from_name (obj_val->vtable->klass, "m_Group");
+				g_assert (field);
 				address = *(MonoObject **)(((char *)obj_val) + field->offset);
 				
 				if (address)