Note

Access to this page requires authorization. You can try signing in or .

Access to this page requires authorization. You can try .

MIB_UNICASTIPADDRESS_TABLE structure (netioapi.h)

The MIB_UNICASTIPADDRESS_TABLE structure contains a table of unicast IP address entries.

Syntax

typedef struct _MIB_UNICASTIPADDRESS_TABLE {
 ULONG NumEntries;
 MIB_UNICASTIPADDRESS_ROW Table[ANY_SIZE];
} MIB_UNICASTIPADDRESS_TABLE, *PMIB_UNICASTIPADDRESS_TABLE;

Members

NumEntries

A value that specifies the number of unicast IP address entries in the array.

Table[ANY_SIZE]

An array of MIB_UNICASTIPADDRESS_ROW structures containing unicast IP address entries.

Remarks

The MIB_UNICASTIPADDRESS_TABLE structure is defined on Windows Vista and later.

The GetUnicastIpAddressTable function enumerates the unicast IP addresses on a local system and returns this information in an MIB_UNICASTIPADDRESS_TABLE structure.

The MIB_UNICASTIPADDRESS_TABLE structure may contain padding for alignment between the NumEntries member and the first MIB_UNICASTIPADDRESS_ROW array entry in the Table member. Padding for alignment may also be present between the MIB_UNICASTIPADDRESS_ROW array entries in the Table member. Any access to a MIB_UNICASTIPADDRESS_ROW array entry should assume padding may exist.

Examples

The following example retrieves a unicast IP address table and prints some values from each of the retrieved MIB_UNICASTIPADDRESS_ROW structures.


#ifndef UNICODE
#define UNICODE
#endif

#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif

#include <Windows.h.>
#include <winsock2.h>
#include <ws2tcpip.h>
#include <ws2ipdef.h>
#include <iphlpapi.h>
#include <stdio.h>
#include <stdlib.h>

// Need to link with Iphlpapi.lib and Ws2_32.lib
#pragma comment (lib, "iphlpapi.lib")
#pragma comment (lib, "Ws2_32.lib")

int __cdecl wmain()
{

 // Declare and initialize variables

 unsigned int i;

 DWORD Result = 0;

 WCHAR Ipv4String[16] = { 0 };
 WCHAR Ipv6String[46] = { 0 };

 PMIB_UNICASTIPADDRESS_TABLE pipTable = NULL;

 Result = GetUnicastIpAddressTable(AF_UNSPEC, &pipTable);
 if (Result != NO_ERROR) {
 wprintf(L"GetUnicastIpAddressTable returned error: %ld\n", Result);
 exit(1);
 }
 // Print some variables from the rows in the table
 wprintf(L"Number of table entries: %d\n\n", pipTable->NumEntries);

 for (i = 0; i < pipTable->NumEntries; i++) {
 wprintf(L"AddressFamily[%d]:\t\t ", i);

 switch (pipTable->Table[i].Address.si_family) {
 case AF_INET:
 wprintf(L"IPv4\n");
 if (InetNtopW
 (AF_INET, &pipTable->Table[i].Address.Ipv4.sin_addr, Ipv4String,
 16) != NULL)
 wprintf(L"IPv4 Address:\t\t\t %ws\n", Ipv4String);
 break;
 case AF_INET6:
 wprintf(L"IPv6\n");
 if (InetNtopW
 (AF_INET6, &pipTable->Table[i].Address.Ipv6.sin6_addr,
 Ipv6String, 46) != NULL)
 wprintf(L"IPv6 Address:\t\t\t %ws\n", Ipv6String);
 break;
 default:
 wprintf(L"Other: %d\n", pipTable->Table[i].Address.si_family);
 break;
 }

 wprintf(L"Interface LUID NetLuidIndex[%d]: %lu\n",
 i, pipTable->Table[i].InterfaceLuid.Info.NetLuidIndex);
 wprintf(L"Interface LUID IfType[%d]:\t ", i);
 switch (pipTable->Table[i].InterfaceLuid.Info.IfType) {
 case IF_TYPE_OTHER:
 wprintf(L"Other\n");
 break;
 case IF_TYPE_ETHERNET_CSMACD:
 wprintf(L"Ethernet\n");
 break;
 case IF_TYPE_ISO88025_TOKENRING:
 wprintf(L"Token ring\n");
 break;
 case IF_TYPE_PPP:
 wprintf(L"PPP\n");
 break;
 case IF_TYPE_SOFTWARE_LOOPBACK:
 wprintf(L"Software loopback\n");
 break;
 case IF_TYPE_ATM:
 wprintf(L"ATM\n");
 break;
 case IF_TYPE_IEEE80211:
 wprintf(L"802.11 wireless\n");
 break;
 case IF_TYPE_TUNNEL:
 wprintf(L"Tunnel encapsulation\n");
 break;
 case IF_TYPE_IEEE1394:
 wprintf(L"IEEE 1394 (Firewire)\n");
 break;
 default:
 wprintf(L"Unknown: %d\n",
 pipTable->Table[i].InterfaceLuid.Info.IfType);
 break;
 }

 wprintf(L"Interface Index[%d]:\t\t %lu\n",
 i, pipTable->Table[i].InterfaceIndex);

 wprintf(L"Prefix Origin[%d]:\t\t ", i);
 switch (pipTable->Table[i].PrefixOrigin) {
 case IpPrefixOriginOther:
 wprintf(L"IpPrefixOriginOther\n");
 break;
 case IpPrefixOriginManual:
 wprintf(L"IpPrefixOriginManual\n");
 break;
 case IpPrefixOriginWellKnown:
 wprintf(L"IpPrefixOriginWellKnown\n");
 break;
 case IpPrefixOriginDhcp:
 wprintf(L"IpPrefixOriginDhcp\n");
 break;
 case IpPrefixOriginRouterAdvertisement:
 wprintf(L"IpPrefixOriginRouterAdvertisement\n");
 break;
 case IpPrefixOriginUnchanged:
 wprintf(L"IpPrefixOriginUnchanged\n");
 break;
 default:
 wprintf(L"Unknown: %d\n", pipTable->Table[i].PrefixOrigin);
 break;
 }

 wprintf(L"Suffix Origin[%d]:\t\t ", i);
 switch (pipTable->Table[i].SuffixOrigin) {
 case IpSuffixOriginOther:
 wprintf(L"IpSuffixOriginOther\n");
 break;
 case IpSuffixOriginManual:
 wprintf(L"IpSuffixOriginManual\n");
 break;
 case IpSuffixOriginWellKnown:
 wprintf(L"IpSuffixOriginWellKnown\n");
 break;
 case IpSuffixOriginDhcp:
 wprintf(L"IpSuffixOriginDhcp\n");
 break;
 case IpSuffixOriginLinkLayerAddress:
 wprintf(L"IpSuffixOriginLinkLayerAddress\n");
 break;
 case IpSuffixOriginRandom:
 wprintf(L"IpSuffixOriginRandom\n");
 break;
 case IpSuffixOriginUnchanged:
 wprintf(L"IpSuffixOriginUnchanged\n");
 break;
 default:
 wprintf(L"Unknown: %d\n", pipTable->Table[i].SuffixOrigin);
 break;
 }

 wprintf(L"Valid Lifetime[%d]:\t\t 0x%x (%u)\n", i,
 pipTable->Table[i].ValidLifetime,
 pipTable->Table[i].ValidLifetime);

 wprintf(L"Preferred Lifetime[%d]:\t\t 0x%x (%u)\n", i,
 pipTable->Table[i].PreferredLifetime,
 pipTable->Table[i].PreferredLifetime);

 wprintf(L"OnLink PrefixLength[%d]:\t\t %lu\n", i,
 pipTable->Table[i].OnLinkPrefixLength);

 wprintf(L"Skip As Source[%d]:\t\t ", i);
 if (pipTable->Table[i].SkipAsSource)
 wprintf(L"Yes\n");
 else
 wprintf(L"No\n");

 wprintf(L"Dad State[%d]:\t\t\t ", i);
 switch (pipTable->Table[i].DadState) {
 case IpDadStateInvalid:
 wprintf(L"IpDadStateInvalid\n");
 break;
 case IpDadStateTentative:
 wprintf(L"IpDadStateTentative\n");
 break;
 case IpDadStateDuplicate:
 wprintf(L"IpDadStateDuplicate\n");
 break;
 case IpDadStateDeprecated:
 wprintf(L"IpDadStateDeprecated\n");
 break;
 case IpDadStatePreferred:
 wprintf(L"IpDadStatePreferred\n");
 break;
 default:
 wprintf(L"Unknown: %d\n", pipTable->Table[i].DadState);
 break;
 }

 wprintf(L"\n");
 }

 if (pipTable != NULL) {
 FreeMibTable(pipTable);
 pipTable = NULL;
 }

 exit(0);
}


Requirements

Requirement Value
Minimum supported client Windows Vista [desktop apps only]
Minimum supported server Windows Server 2008 [desktop apps only]
Header netioapi.h (include Iphlpapi.h)

See also

GetUnicastIpAddressTable

MIB_UNICASTIPADDRESS_ROW


Feedback

Was this page helpful?

Additional resources