[System]: Add missing System.Net.SecurityProtocolType enum values.
[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
32 using System.Net.Sockets;
33
34 namespace System.Net { 
35
36 #if NET_2_1
37         sealed
38 #endif
39         public class DnsEndPoint : EndPoint {
40                 string host;
41                 int port;
42                 AddressFamily addressFamily = AddressFamily.Unspecified;
43
44                 public DnsEndPoint (string host, int port)
45                 {
46                         if (host == null)
47                                 throw new ArgumentNullException ("host");
48                         if (host == String.Empty)
49                                 throw new ArgumentException ("host parameter contains an empty string");
50                         if (port < 0 || port > 0xffff)
51                                 throw new ArgumentOutOfRangeException ("port is less than 0 or greater than 0xffff");
52
53                         this.host = host;
54                         this.port = port;
55                 }
56
57                 public DnsEndPoint (string host, int port, AddressFamily addressFamily) : this (host, port)
58                 {
59                         switch (addressFamily) {
60                         case AddressFamily.InterNetwork:
61                         case AddressFamily.InterNetworkV6:
62                         case AddressFamily.Unspecified:
63                                 this.addressFamily = addressFamily;
64                                 break;
65                         default:
66                                 // throw for Unknown or any invalid value
67                                 throw new ArgumentException ("addressFamily");
68                         }
69                 }
70
71                 public override bool Equals (object comparand)
72                 {
73                         DnsEndPoint dep = (comparand as DnsEndPoint);
74                         return (comparand != null) && Equals (dep);
75                 }
76
77                 private bool Equals (DnsEndPoint other)
78                 {
79                         if (port != other.port || addressFamily != other.addressFamily|| host != other.host)
80                                 return false;
81                         return true;
82                 }
83
84                 public override int GetHashCode ()
85                 {
86                         return port ^ (int)addressFamily ^ host.GetHashCode ();
87                 }
88
89                 public override string ToString ()
90                 {
91                         return String.Format ("{0}/{1}:{2}", addressFamily, host, port);
92                 }
93
94                 public override AddressFamily AddressFamily {
95                         get { return addressFamily; }
96                 }
97
98                 public string Host {
99                         get { return host; }
100                 }
101
102                 public int Port {
103                         get { return port; }
104                 }
105         }
106 }
107