Fix bug #311: On LinkedList.Clear, detach each node instead of dropping them en masse.
[mono.git] / mcs / class / System / System.Net / DnsEndPoint.cs
1 //
2 // System.Net.DnsEndPoint
3 //
4 // Authors:
5 //      Stephane Delcroix  <stephane@delcroix.org>
6 //
7 // (c) 2007, 2009 Novell, Inc. (http://www.novell.com)
8 //
9
10 //
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:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
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.
29 //
30
31 #if NET_2_1 || NET_4_0
32
33 using System.Net.Sockets;
34
35 namespace System.Net { 
36
37         public sealed class DnsEndPoint : EndPoint {
38                 string host;
39                 int port;
40                 AddressFamily addressFamily = AddressFamily.Unspecified;
41
42                 public DnsEndPoint (string host, int port)
43                 {
44                         if (host == null)
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");
50
51                         this.host = host;
52                         this.port = port;
53                 }
54
55                 public DnsEndPoint (string host, int port, AddressFamily addressFamily) : this (host, port)
56                 {
57                         switch (addressFamily) {
58                         case AddressFamily.InterNetwork:
59                         case AddressFamily.InterNetworkV6:
60                         case AddressFamily.Unspecified:
61                                 this.addressFamily = addressFamily;
62                                 break;
63                         default:
64                                 // throw for Unknown or any invalid value
65                                 throw new ArgumentException ("addressFamily");
66                         }
67                 }
68
69                 public override bool Equals (object comparand)
70                 {
71                         DnsEndPoint dep = (comparand as DnsEndPoint);
72                         return (comparand != null) && Equals (dep);
73                 }
74
75                 private bool Equals (DnsEndPoint other)
76                 {
77                         if (port != other.port || addressFamily != other.addressFamily|| host != other.host)
78                                 return false;
79                         return true;
80                 }
81
82                 public override int GetHashCode ()
83                 {
84                         return port ^ (int)addressFamily ^ host.GetHashCode ();
85                 }
86
87                 public override string ToString ()
88                 {
89                         return String.Format ("{0}/{1}:{2}", addressFamily, host, port);
90                 }
91
92                 public override AddressFamily AddressFamily {
93                         get { return addressFamily; }
94                 }
95
96                 public string Host {
97                         get { return host; }
98                 }
99
100                 public int Port {
101                         get { return port; }
102                 }
103         }
104 }
105
106 #endif