IP_ADAPTER_ADDRESSES Structure
The IP_ADAPTER_ADDRESSES
structure contains information about an adapter on the local computer. It is used with the GetAdaptersAddresses
function to retrieve comprehensive details about network interfaces.
Header
#include <iphlpapi.h>
Library
Iphlpapi.lib
Syntax
typedef struct _IP_ADAPTER_ADDRESSES {
ULONG Length;
DWORD IfIndex;
struct _IP_ADAPTER_ADDRESSES *Next;
PWCHAR AdapterName;
PWCHAR Description;
UINT PhysicalAddressLength;
BYTE PhysicalAddress[8];
UINT Flags;
DWORD Mtu;
DWORD IfType;
IF_OPER_STATUS OperStatus;
DWORD Ipv6IfIndex;
DWORD ZoneIndices[16];
PIP_ADAPTER_PREFIX FirstPrefix;
// ... (additional members omitted for brevity)
} IP_ADAPTER_ADDRESSES, *PIP_ADAPTER_ADDRESSES;
Members
Member | Type | Description |
---|---|---|
Length | ULONG | Size of the structure, in bytes. |
IfIndex | DWORD | Interface index used to identify the adapter. |
Next | struct _IP_ADAPTER_ADDRESSES* | Pointer to the next adapter in the list. |
AdapterName | PWCHAR | Network adapter name (e.g., Ethernet0). |
Description | PWCHAR | Human‑readable description of the adapter. |
PhysicalAddressLength | UINT | Length, in bytes, of the physical address. |
PhysicalAddress | BYTE[8] | MAC address of the adapter. |
Flags | UINT | Adapter flags (e.g., IP_ADAPTER_IPV4_ENABLED). |
Mtu | DWORD | Maximum Transmission Unit size. |
IfType | DWORD | Network interface type (e.g., IF_TYPE_ETHERNET_CSMACD). |
OperStatus | IF_OPER_STATUS | Operational status of the interface. |
Ipv6IfIndex | DWORD | IPv6 interface index. |
ZoneIndices | DWORD[16] | Per‑zone IPv6 interface indices. |
FirstPrefix | PIP_ADAPTER_PREFIX | Pointer to the list of IPv4/IPv6 prefixes. |
Example
The following C example retrieves all adapters and prints basic information.
#include <stdio.h>
#include <windows.h>
#include <iphlpapi.h>
#pragma comment(lib, "iphlpapi.lib")
int main() {
ULONG outBufLen = 15000;
PIP_ADAPTER_ADDRESSES pAddresses = NULL;
DWORD dwRetVal = 0;
pAddresses = (IP_ADAPTER_ADDRESSES *) malloc(outBufLen);
if (pAddresses == NULL) {
printf("Memory allocation failed.\n");
return 1;
}
dwRetVal = GetAdaptersAddresses(AF_UNSPEC, GAA_FLAG_INCLUDE_PREFIX,
NULL, pAddresses, &outBufLen);
if (dwRetVal == NO_ERROR) {
PIP_ADAPTER_ADDRESSES pCurr = pAddresses;
while (pCurr) {
printf("\nAdapter Name: %ws\n", pCurr->AdapterName);
printf("Description : %ws\n", pCurr->Description);
printf("IfIndex : %u\n", pCurr->IfIndex);
printf("OperStatus : %u\n", pCurr->OperStatus);
pCurr = pCurr->Next;
}
} else {
printf("GetAdaptersAddresses failed with error: %u\n", dwRetVal);
}
if (pAddresses) free(pAddresses);
return 0;
}