GetAdapterAddresses Function

Retrieves the adapter addresses for all network interfaces on the local computer.

Syntax

_Inout_ PIP_ADAPTER_ADDRESSES AdapterAddresses,
_Inout_ ULONG SizePointer,
_In_ ULONG Flags

For Windows Vista and later, the function signature is:

_Inout_ PIP_ADAPTER_ADDRESSES AdapterAddresses,
_Inout_ ULONG SizePointer,
_In_ ULONG Flags

Parameters

Parameter Description
AdapterAddresses

On input, a pointer to a buffer that is large enough to receive the adapter address structures. On output, a pointer to the first IP_ADAPTER_ADDRESSES structure in the linked list of adapter addresses.

If this parameter is NULL on input, the function returns the required buffer size in the SizePointer parameter.

SizePointer

On input, a pointer to a ULONG variable that specifies the size, in bytes, of the buffer pointed to by the AdapterAddresses parameter.

On output, if the function succeeds and AdapterAddresses is not NULL, this parameter receives the number of bytes actually copied to the buffer pointed to by AdapterAddresses. If the buffer is not large enough to hold the adapter data, this parameter receives the required buffer size in bytes. If AdapterAddresses is NULL on input, this parameter receives the required buffer size in bytes.

Flags

A set of flags that specify how adapter addresses are retrieved. This parameter can be one or more of the following values:

  • GAA_FLAG_INCLUDE_PREFIX: Include prefix information for unicast and anycast addresses.
  • GAA_FLAG_SKIP_DNS_REGISTERED: Skip DNS registered addresses.
  • GAA_FLAG_SKIP_UNOPTIMIZED: Skip unoptimized addresses.
  • GAA_FLAG_SKIP_FRIENDLY_NAME: Skip friendly names.

Remarks

This function is used to retrieve information about network interfaces. The information is returned as a linked list of IP_ADAPTER_ADDRESSES structures. Each structure in the list represents a network interface on the local computer.

The adapter addresses retrieved include IPv4 and IPv6 addresses, MAC addresses, and gateway information.

When calling this function, you should first call it with AdapterAddresses set to NULL and SizePointer set to 0. This will return the required buffer size in the SizePointer parameter. You then allocate a buffer of that size and call the function again with the allocated buffer.

Important: For Windows Vista and later, it is recommended to use the GetAdaptersAddresses function rather than the older GetAdaptersInfo function. GetAdaptersAddresses provides more comprehensive information and supports IPv6 addresses.

Return Value

If the function succeeds, the return value is ERROR_SUCCESS. If the buffer pointed to by the AdapterAddresses parameter is not large enough to hold the adapter data, the return value is ERROR_BUFFER_OVERFLOW and the required buffer size is returned in the SizePointer parameter.

If the function fails, the return value can be one of the following error codes:

Return Code Description
ERROR_INVALID_PARAMETER One or more parameters are invalid.
ERROR_NOT_SUPPORTED The requested operation is not supported.
ERROR_NO_DATA No adapter addresses were found.

Requirements

Header Iphlpapi.h
Library Iphlpapi.lib
DLL Iphlpapi.dll
Minimum supported client Windows Vista [desktop apps only]
Minimum supported server Windows Server 2008 [desktop apps only]

See Also