// // 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 uint address; public const uint InaddrAny = 0; public const uint InaddrBroadcast = 0xffffffff; public const uint InaddrLoopback = 0x7f000001; public const uint InaddrNone = 0xffffffff; // // Constructor from a 32-bit constant. // public IPAddress (uint 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 // public static string ToString (uint 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; } } }