Commit 6a9937d2166023c370489d8e6654d01f6ec52f44 is not correct. WebClient.Proxy shoul...
[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 #if NET_2_1
38         sealed
39 #endif
40         public class DnsEndPoint : EndPoint {
41                 string host;
42                 int port;
43                 AddressFamily addressFamily = AddressFamily.Unspecified;
44
45                 public DnsEndPoint (string host, int port)
46                 {
47                         if (host == null)
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");
53
54                         this.host = host;
55                         this.port = port;
56                 }
57
58                 public DnsEndPoint (string host, int port, AddressFamily addressFamily) : this (host, port)
59                 {
60                         switch (addressFamily) {
61                         case AddressFamily.InterNetwork:
62                         case AddressFamily.InterNetworkV6:
63                         case AddressFamily.Unspecified:
64                                 this.addressFamily = addressFamily;
65                                 break;
66                         default:
67                                 // throw for Unknown or any invalid value
68                                 throw new ArgumentException ("addressFamily");
69                         }
70                 }
71
72                 public override bool Equals (object comparand)
73                 {
74                         DnsEndPoint dep = (comparand as DnsEndPoint);
75                         return (comparand != null) && Equals (dep);
76                 }
77
78                 private bool Equals (DnsEndPoint other)
79                 {
80                         if (port != other.port || addressFamily != other.addressFamily|| host != other.host)
81                                 return false;
82                         return true;
83                 }
84
85                 public override int GetHashCode ()
86                 {
87                         return port ^ (int)addressFamily ^ host.GetHashCode ();
88                 }
89
90                 public override string ToString ()
91                 {
92                         return String.Format ("{0}/{1}:{2}", addressFamily, host, port);
93                 }
94
95                 public override AddressFamily AddressFamily {
96                         get { return addressFamily; }
97                 }
98
99                 public string Host {
100                         get { return host; }
101                 }
102
103                 public int Port {
104                         get { return port; }
105                 }
106         }
107 }
108
109 #endif