DuplicateAddressDetectionState Enumeration
Specifies the current state of an IP address.
Assembly: System (in System.dll)
| Member name | Description | |
|---|---|---|
| Invalid | The address is not valid. A nonvalid address is expired and no longer assigned to an interface; applications should not send data packets to it. | |
| Tentative | The duplicate address detection procedure's evaluation of the address has not completed successfully. Applications should not use the address because it is not yet valid and packets sent to it are discarded. | |
| Duplicate | The address is not unique. This address should not be assigned to the network interface. | |
| Deprecated | The address is valid, but it is nearing its lease lifetime and should not be used by applications. | |
| Preferred | The address is valid and its use is unrestricted. |
To help ensure that all interfaces on a network have a unique address, the interface host is responsible for running a "duplicate address detection" algorithm on unicast addresses. The purpose of this algorithm is to attempt to prevent non-unique addresses on the network. This process is defined in IETF RFC 1971.
This enumeration is used by the UnicastIPAddressInformation and MulticastIPAddressInformation classes. Instances of this class are returned when you retrieve the unicast address information for a NetworkInterface object.
The following code example determines unicast address information.
Public Shared Sub DisplayUnicastAddresses() Console.WriteLine("Unicast Addresses") Dim adapters As NetworkInterface() = NetworkInterface.GetAllNetworkInterfaces() Dim adapter As NetworkInterface For Each adapter In adapters Dim adapterProperties As IPInterfaceProperties = adapter.GetIPProperties() Dim uniCast As UnicastIPAddressInformationCollection = adapterProperties.UnicastAddresses If uniCast.Count > 0 Then Console.WriteLine(adapter.Description) Dim lifeTimeFormat As String = "dddd, MMMM dd, yyyy hh:mm:ss tt" Dim uni As UnicastIPAddressInformation For Each uni In uniCast Dim [when] As DateTime Console.WriteLine(" Unicast Address ......................... : {0}", uni.Address) Console.WriteLine(" Prefix Origin ........................ : {0}", uni.PrefixOrigin) Console.WriteLine(" Suffix Origin ........................ : {0}", uni.SuffixOrigin) Console.WriteLine(" Duplicate Address Detection .......... : {0}", uni.DuplicateAddressDetectionState) ' Format the lifetimes as Sunday, February 16, 2003 11:33:44 PM ' if en-us is the current culture. ' Calculate the date and time at the end of the lifetimes. [when] = DateTime.UtcNow + TimeSpan.FromSeconds(uni.AddressValidLifetime) [when] = [when].ToLocalTime() Console.WriteLine(" Valid Life Time ...................... : {0}", [when].ToString(lifeTimeFormat, System.Globalization.CultureInfo.CurrentCulture)) [when] = DateTime.UtcNow + TimeSpan.FromSeconds(uni.AddressPreferredLifetime) [when] = [when].ToLocalTime() Console.WriteLine(" Preferred life time .................. : {0}", [when].ToString(lifeTimeFormat, System.Globalization.CultureInfo.CurrentCulture)) [when] = DateTime.UtcNow + TimeSpan.FromSeconds(uni.DhcpLeaseLifetime) [when] = [when].ToLocalTime() Console.WriteLine(" DHCP Leased Life Time ................ : {0}", [when].ToString(lifeTimeFormat, System.Globalization.CultureInfo.CurrentCulture)) Next uni Console.WriteLine() End If Next adapter End Sub 'DisplayUnicastAddresses
void DisplayUnicastAddresses()
{
Console::WriteLine(S"Unicast Addresses");
NetworkInterface* adapters[] = NetworkInterface::GetAllNetworkInterfaces();
System::Collections::IEnumerator* myEnum17 = adapters->GetEnumerator();
while (myEnum17->MoveNext())
{
NetworkInterface* adapter = __try_cast<NetworkInterface*>(myEnum17->Current);
IPInterfaceProperties* adapterProperties = adapter->GetIPInterfaceProperties();
IPUnicastAddressInformationCollection* uniCast = adapterProperties->UnicastAddresses;
if (uniCast->Count >0)
{
Console::WriteLine(adapter->Description);
String* lifeTimeFormat = S"dddd, MMMM dd, yyyy hh:mm:ss tt";
System::Collections::IEnumerator* myEnum18 = uniCast->GetEnumerator();
while (myEnum18->MoveNext())
{
IPUnicastAddressInformation* uni = __try_cast<IPUnicastAddressInformation*>(myEnum18->Current);
DateTime when;
Console::WriteLine(S" Unicast Address ......................... : {0}", uni->Address);
Console::WriteLine(S" Prefix Origin ........................ : {0}", __box(uni->PrefixOrigin));
Console::WriteLine(S" Suffix Origin ........................ : {0}", __box(uni->SuffixOrigin));
Console::WriteLine(S" Duplicate Address Detection .......... : {0}", __box(uni->DuplicateAddressDetectionState));
// Format the lifetimes as Sunday, February 16, 2003 11:33:44 PM
// if en-us is the current culture.
// Calculate the date and time at the end of the lifetimes.
when = DateTime::UtcNow + TimeSpan::FromSeconds((double)uni->AddressValidLifetime);
when = when.ToLocalTime();
Console::WriteLine(S" Valid Life Time ...................... : {0}",
when.ToString(lifeTimeFormat,System::Globalization::CultureInfo::CurrentCulture)
);
when = DateTime::UtcNow + TimeSpan::FromSeconds((double)uni->AddressPreferredLifetime);
when = when.ToLocalTime();
Console::WriteLine(S" Preferred life time .................. : {0}",
when.ToString(lifeTimeFormat,System::Globalization::CultureInfo::CurrentCulture)
);
when = DateTime::UtcNow + TimeSpan::FromSeconds((double)uni->DhcpLeaseLifetime);
when = when.ToLocalTime();
Console::WriteLine(S" DHCP Leased Life Time ................ : {0}",
when.ToString(lifeTimeFormat,System::Globalization::CultureInfo::CurrentCulture)
);
}
Console::WriteLine();
}
}
}
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.