2 // System.Net.NetworkInformation.UnicastIPAddressInformation
5 // Gonzalo Paniagua Javier (gonzalo@novell.com)
6 // Atsushi Enomoto (atsushi@ximian.com)
7 // Eric Butler (eric@extremeboredom.net)
9 // Copyright (c) 2006-2007 Novell, Inc. (http://www.novell.com)
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:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
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.
32 using System
.Runtime
.InteropServices
;
34 namespace System
.Net
.NetworkInformation
{
35 public abstract class UnicastIPAddressInformation
: IPAddressInformation
{
36 protected UnicastIPAddressInformation ()
40 public abstract long AddressPreferredLifetime { get; }
41 public abstract long AddressValidLifetime { get; }
42 public abstract long DhcpLeaseLifetime { get; }
43 public abstract DuplicateAddressDetectionState DuplicateAddressDetectionState { get; }
44 public abstract IPAddress IPv4Mask { get; }
45 public abstract PrefixOrigin PrefixOrigin { get; }
46 public abstract SuffixOrigin SuffixOrigin { get; }
49 class Win32UnicastIPAddressInformation
: UnicastIPAddressInformation
52 Win32_IP_ADAPTER_UNICAST_ADDRESS info
;
54 public Win32UnicastIPAddressInformation (int ifIndex
, Win32_IP_ADAPTER_UNICAST_ADDRESS info
)
56 this.if_index
= ifIndex
;
60 public override IPAddress Address
{
61 get { return info.Address.GetIPAddress (); }
64 public override bool IsDnsEligible
{
65 get { return info.LengthFlags.IsDnsEligible; }
68 public override bool IsTransient
{
69 get { return info.LengthFlags.IsTransient; }
72 // UnicastIPAddressInformation members
74 public override long AddressPreferredLifetime
{
75 get { return info.PreferredLifetime; }
78 public override long AddressValidLifetime
{
79 get { return info.ValidLifetime; }
82 public override long DhcpLeaseLifetime
{
83 get { return info.LeaseLifetime; }
86 public override DuplicateAddressDetectionState DuplicateAddressDetectionState
{
87 get { return info.DadState; }
90 public override IPAddress IPv4Mask
{
92 Win32_IP_ADAPTER_INFO ai
= Win32NetworkInterface2
.GetAdapterInfoByIndex (if_index
);
94 throw new Exception ("huh? " + if_index
);
95 if (this.Address
== null)
97 string expected
= this.Address
.ToString ();
99 Win32_IP_ADDR_STRING p
= ai
.IpAddressList
;
101 if (p
.IpAddress
== expected
)
102 return IPAddress
.Parse (p
.IpMask
);
103 if (p
.Next
== IntPtr
.Zero
)
105 p
= (Win32_IP_ADDR_STRING
) Marshal
.PtrToStructure (p
.Next
, typeof (Win32_IP_ADDR_STRING
));
108 // Or whatever it should be...
114 public override PrefixOrigin PrefixOrigin
{
115 get { return info.PrefixOrigin; }
118 public override SuffixOrigin SuffixOrigin
{
119 get { return info.SuffixOrigin; }
123 class LinuxUnicastIPAddressInformation
: UnicastIPAddressInformation
127 public LinuxUnicastIPAddressInformation (IPAddress address
)
129 this.address
= address
;
132 public override IPAddress Address
{
133 get { return address; }
136 public override bool IsDnsEligible
{
138 byte[] addressBytes
= address
.GetAddressBytes ();
139 return !(addressBytes
[0] == 169 && addressBytes
[1] == 254);
143 [MonoTODO("Always returns false")]
144 public override bool IsTransient
{
145 get { return false; }
148 // UnicastIPAddressInformation members
150 public override long AddressPreferredLifetime
{
151 get { throw new NotImplementedException (); }
154 public override long AddressValidLifetime
{
155 get { throw new NotImplementedException (); }
158 public override long DhcpLeaseLifetime
{
159 get { throw new NotImplementedException (); }
162 public override DuplicateAddressDetectionState DuplicateAddressDetectionState
{
163 get { throw new NotImplementedException (); }
166 public override IPAddress IPv4Mask
{
167 get { throw new NotImplementedException (); }
170 public override PrefixOrigin PrefixOrigin
{
171 get { throw new NotImplementedException (); }
174 public override SuffixOrigin SuffixOrigin
{
175 get { throw new NotImplementedException (); }