2007-08-29 Atsushi Enomoto <atsushi@ximian.com>
[mono.git] / mcs / class / System / System.Net.NetworkInformation / IPInterfaceProperties.cs
1 //
2 // System.Net.NetworkInformation.IPInterfaceProperties
3 //
4 // Authors:
5 //      Gonzalo Paniagua Javier (gonzalo@novell.com)
6 //      Atsushi Enomoto (atsushi@ximian.com)
7 //
8 // Copyright (c) 2006-2007 Novell, Inc. (http://www.novell.com)
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
17 // 
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 // 
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 //
29 #if NET_2_0
30 namespace System.Net.NetworkInformation {
31         public abstract class IPInterfaceProperties {
32                 protected IPInterfaceProperties ()
33                 {
34                 }
35
36                 public abstract IPv4InterfaceProperties GetIPv4Properties ();
37                 public abstract IPv6InterfaceProperties GetIPv6Properties ();
38
39                 public abstract IPAddressInformationCollection AnycastAddresses { get; }
40                 public abstract IPAddressCollection DhcpServerAddresses { get; }
41                 public abstract IPAddressCollection DnsAddresses { get; }
42                 public abstract string DnsSuffix { get; }
43                 public abstract GatewayIPAddressInformationCollection GatewayAddresses { get; }
44                 public abstract bool IsDnsEnabled { get; }
45                 public abstract bool IsDynamicDnsEnabled { get; }
46                 public abstract MulticastIPAddressInformationCollection MulticastAddresses { get; }
47                 public abstract UnicastIPAddressInformationCollection UnicastAddresses { get; }
48                 public abstract IPAddressCollection WinsServersAddresses { get; }
49         }
50
51         class Win32IPInterfaceProperties2 : IPInterfaceProperties
52         {
53                 readonly Win32_IP_ADAPTER_ADDRESSES addr;
54                 readonly Win32_MIB_IFROW mib4, mib6;
55
56                 public Win32IPInterfaceProperties2 (Win32_IP_ADAPTER_ADDRESSES addr, Win32_MIB_IFROW mib4, Win32_MIB_IFROW mib6)
57                 {
58                         this.addr = addr;
59                         this.mib4 = mib4;
60                         this.mib6 = mib6;
61                 }
62
63                 public override IPv4InterfaceProperties GetIPv4Properties ()
64                 {
65                         Win32_IP_ADAPTER_INFO v4info = Win32NetworkInterface2.GetAdapterInfoByIndex (mib4.Index);
66                         return v4info != null ? new Win32IPv4InterfaceProperties (v4info, mib4) : null;
67                 }
68
69                 public override IPv6InterfaceProperties GetIPv6Properties ()
70                 {
71                         Win32_IP_ADAPTER_INFO v6info = Win32NetworkInterface2.GetAdapterInfoByIndex (mib6.Index);
72                         return v6info != null ? new Win32IPv6InterfaceProperties (mib6) : null;
73                 }
74
75                 public override IPAddressInformationCollection AnycastAddresses {
76                         get { return IPAddressInformationImplCollection.FromAnycast (addr.FirstAnycastAddress); }
77                 }
78
79                 public override IPAddressCollection DhcpServerAddresses {
80                         get {
81                                 Win32_IP_ADAPTER_INFO v4info = Win32NetworkInterface2.GetAdapterInfoByIndex (mib4.Index);
82                                 // FIXME: should ipv6 DhcpServer be considered?
83                                 return v4info != null ? new Win32IPAddressCollection (v4info.DhcpServer) : Win32IPAddressCollection.Empty;
84                         }
85                 }
86
87                 public override IPAddressCollection DnsAddresses {
88                         get { return Win32IPAddressCollection.FromDnsServer (addr.FirstDnsServerAddress); }
89                 }
90
91                 public override string DnsSuffix {
92                         get { return addr.DnsSuffix; }
93                 }
94
95                 public override GatewayIPAddressInformationCollection GatewayAddresses {
96                         get {
97                                 Win32_IP_ADAPTER_INFO v4info = Win32NetworkInterface2.GetAdapterInfoByIndex (mib4.Index);
98                                 // FIXME: should ipv6 DhcpServer be considered?
99                                 return v4info != null ? new Win32GatewayIPAddressInformationCollection (v4info.GatewayList) : Win32GatewayIPAddressInformationCollection.Empty;
100                         }
101                 }
102
103                 public override bool IsDnsEnabled {
104                         get { return Win32NetworkInterface2.FixedInfo.EnableDns != 0; }
105                 }
106
107                 public override bool IsDynamicDnsEnabled {
108                         get { return addr.DdnsEnabled; }
109                 }
110
111                 public override MulticastIPAddressInformationCollection MulticastAddresses {
112                         get { return Win32MulticastIPAddressInformationCollection.FromMulticast (addr.FirstMulticastAddress); }
113                 }
114
115                 public override UnicastIPAddressInformationCollection UnicastAddresses {
116                         get { return Win32UnicastIPAddressInformationCollection.FromUnicast (addr.FirstUnicastAddress); }
117                 }
118
119                 public override IPAddressCollection WinsServersAddresses {
120                         get {
121                                 Win32_IP_ADAPTER_INFO v4info = Win32NetworkInterface2.GetAdapterInfoByIndex (mib4.Index);
122                                 // FIXME: should ipv6 DhcpServer be considered?
123                                 return v4info != null ? new Win32IPAddressCollection (v4info.PrimaryWinsServer, v4info.SecondaryWinsServer) : Win32IPAddressCollection.Empty;
124                         }
125                 }
126
127         }
128 }
129 #endif
130