2 // System.Net.DnsEndPoint
5 // Stephane Delcroix <stephane@delcroix.org>
7 // (c) 2007, 2009 Novell, Inc. (http://www.novell.com)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 using System.Net.Sockets;
35 namespace System.Net {
40 public class DnsEndPoint : EndPoint {
43 AddressFamily addressFamily = AddressFamily.Unspecified;
45 public DnsEndPoint (string host, int port)
48 throw new ArgumentNullException ("host");
49 if (host == String.Empty)
50 throw new ArgumentException ("host parameter contains an empty string");
51 if (port < 0 || port > 0xffff)
52 throw new ArgumentOutOfRangeException ("port is less than 0 or greater than 0xffff");
58 public DnsEndPoint (string host, int port, AddressFamily addressFamily) : this (host, port)
60 switch (addressFamily) {
61 case AddressFamily.InterNetwork:
62 case AddressFamily.InterNetworkV6:
63 case AddressFamily.Unspecified:
64 this.addressFamily = addressFamily;
67 // throw for Unknown or any invalid value
68 throw new ArgumentException ("addressFamily");
72 public override bool Equals (object comparand)
74 DnsEndPoint dep = (comparand as DnsEndPoint);
75 return (comparand != null) && Equals (dep);
78 private bool Equals (DnsEndPoint other)
80 if (port != other.port || addressFamily != other.addressFamily|| host != other.host)
85 public override int GetHashCode ()
87 return port ^ (int)addressFamily ^ host.GetHashCode ();
90 public override string ToString ()
92 return String.Format ("{0}/{1}:{2}", addressFamily, host, port);
95 public override AddressFamily AddressFamily {
96 get { return addressFamily; }