2 // System.Net.NetworkInformation.IPInterfaceProperties
5 // Gonzalo Paniagua Javier (gonzalo@novell.com)
6 // Atsushi Enomoto (atsushi@ximian.com)
8 // Copyright (c) 2006-2007 Novell, Inc. (http://www.novell.com)
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:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
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.
30 namespace System.Net.NetworkInformation {
31 public abstract class IPInterfaceProperties {
32 protected IPInterfaceProperties ()
36 public abstract IPv4InterfaceProperties GetIPv4Properties ();
37 public abstract IPv6InterfaceProperties GetIPv6Properties ();
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; }
51 class Win32IPInterfaceProperties2 : IPInterfaceProperties
53 readonly Win32_IP_ADAPTER_ADDRESSES addr;
54 readonly Win32_MIB_IFROW mib4, mib6;
56 public Win32IPInterfaceProperties2 (Win32_IP_ADAPTER_ADDRESSES addr, Win32_MIB_IFROW mib4, Win32_MIB_IFROW mib6)
63 public override IPv4InterfaceProperties GetIPv4Properties ()
65 Win32_IP_ADAPTER_INFO v4info = Win32NetworkInterface2.GetAdapterInfoByIndex (mib4.Index);
66 return v4info != null ? new Win32IPv4InterfaceProperties (v4info, mib4) : null;
69 public override IPv6InterfaceProperties GetIPv6Properties ()
71 Win32_IP_ADAPTER_INFO v6info = Win32NetworkInterface2.GetAdapterInfoByIndex (mib6.Index);
72 return v6info != null ? new Win32IPv6InterfaceProperties (mib6) : null;
75 public override IPAddressInformationCollection AnycastAddresses {
76 get { return IPAddressInformationImplCollection.FromAnycast (addr.FirstAnycastAddress); }
79 public override IPAddressCollection DhcpServerAddresses {
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;
87 public override IPAddressCollection DnsAddresses {
88 get { return Win32IPAddressCollection.FromDnsServer (addr.FirstDnsServerAddress); }
91 public override string DnsSuffix {
92 get { return addr.DnsSuffix; }
95 public override GatewayIPAddressInformationCollection GatewayAddresses {
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;
103 public override bool IsDnsEnabled {
104 get { return Win32NetworkInterface2.FixedInfo.EnableDns != 0; }
107 public override bool IsDynamicDnsEnabled {
108 get { return addr.DdnsEnabled; }
111 public override MulticastIPAddressInformationCollection MulticastAddresses {
112 get { return Win32MulticastIPAddressInformationCollection.FromMulticast (addr.FirstMulticastAddress); }
115 public override UnicastIPAddressInformationCollection UnicastAddresses {
116 get { return Win32UnicastIPAddressInformationCollection.FromUnicast (addr.FirstUnicastAddress); }
119 public override IPAddressCollection WinsServersAddresses {
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;