// // System.Net.IPAddress.cs // // Author: // Miguel de Icaza (miguel@ximian.com) // // (C) Ximian, Inc. http://www.ximian.com // namespace System.Net { /// /// Encapsulates an IP Address. /// public class IPAddress { public long Address; public static readonly IPAddress Any; public static readonly IPAddress Broadcast; public static readonly IPAddress Loopback; public static readonly IPAddress None; public const uint InaddrAny = 0; public const uint InaddrBroadcast = 0xffffffff; public const uint InaddrLoopback = 0x7f000001; public const uint InaddrNone = 0xffffffff; static IPAddress () { Any.Address = InaddrAny; Broadcast.Address = InaddrBroadcast; Loopback.Address = InaddrLoopback; None.Address = InaddrNone; } /// /// Constructor from a 32-bit constant. /// public IPAddress (long address) { this.Address = address; } /// /// Constructor from a dotted quad notation. /// public IPAddress (string ip) { string[] ips = ip.Split (new char[] {'.'}); int i; uint a = 0; for (i = 0; i < ips.Length; i++) a = (a << 8) | (UInt16.Parse(ips [i])); Address = a; } /// /// Used to tell whether an address is a loopback. /// /// Address to compare /// public static bool IsLoopback (IPAddress addr) { return addr.Address == InaddrLoopback; } /// /// Overrides System.Object.ToString to return /// this object rendered in a quad-dotted notation /// public override string ToString () { return ToString (Address); } /// /// Returns this object rendered in a quad-dotted notation /// static string ToString (long addr) { return (addr >> 24).ToString () + "." + ((addr >> 16) & 0xff).ToString () + "." + ((addr >> 8) & 0xff).ToString () + "." + (addr & 0xff).ToString (); } /// /// Whether both objects are equal. /// public override bool Equals (object other) { if (other is System.Net.IPAddress){ return Address == ((System.Net.IPAddress) other).Address; } return false; } public override int GetHashCode () { return (int)Address; } [MonoTODO] public static short HostToNetworkOrder (short host) { return host; } [MonoTODO] public static int HostToNetworkOrder (int host) { return host; } [MonoTODO] public static long HostToNetworkOrder (long host) { return host; } [MonoTODO] public static short NetworkToHostOrder (short host) { return host; } [MonoTODO] public static int NetworkToHostOrder (int host) { return host; } [MonoTODO] public static long NetworkToHostOrder (long host) { return host; } } }