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.
31 #if NET_2_1 || NET_4_0
33 using System.Net.Sockets;
35 namespace System.Net {
37 public sealed class DnsEndPoint : EndPoint {
40 AddressFamily addressFamily = AddressFamily.Unspecified;
42 public DnsEndPoint (string host, int port)
45 throw new ArgumentNullException ("host");
46 if (host == String.Empty)
47 throw new ArgumentException ("host parameter contains an empty string");
48 if (port < 0 || port > 0xffff)
49 throw new ArgumentOutOfRangeException ("port is less than 0 or greater than 0xffff");
55 public DnsEndPoint (string host, int port, AddressFamily addressFamily) : this (host, port)
57 switch (addressFamily) {
58 case AddressFamily.InterNetwork:
59 case AddressFamily.InterNetworkV6:
60 case AddressFamily.Unspecified:
61 this.addressFamily = addressFamily;
64 // throw for Unknown or any invalid value
65 throw new ArgumentException ("addressFamily");
69 public override bool Equals (object other)
71 if (other is DnsEndPoint)
72 return Equals (other as DnsEndPoint);
76 private bool Equals (DnsEndPoint other)
78 if (port != other.port || addressFamily != other.addressFamily|| host != other.host)
83 public override int GetHashCode ()
85 return port ^ (int)addressFamily ^ host.GetHashCode ();
88 public override string ToString ()
90 return String.Format ("{0}/{1}:{2}", addressFamily, host, port);
93 public override AddressFamily AddressFamily {
94 get { return addressFamily; }