IP Helper API

Windows API Reference

Function

GetAdaptersAddresses

Retrieves the adapter address information for the local computer.

Syntax

ULONG WINAPI GetAdaptersAddresses(
  _In_  ULONG                Family,
  _In_  DWORD                Flags,
  _In_  PVOID                pReserved,
  _Inout_ PIP_ADAPTER_ADDRESSES pAdapterAddresses,
  _Inout_ PULONG               pOutBufLen
);
        
Parameters
Family [in] ULONG
The family of addresses to retrieve. This parameter can be one of the following values:
  • AF_UNSPEC
  • AF_INET
  • AF_INET6
Flags [in] DWORD
Flags that specify how to retrieve adapter addresses. This parameter can be a combination of the following values:
  • GAA_FLAG_INCLUDE_PREFIX
  • GAA_FLAG_SKIP_UNICAST
  • GAA_FLAG_SKIP_ANYCAST
  • GAA_FLAG_SKIP_MULTICAST
  • GAA_FLAG_INCLUDE_DNS_SETTINGS
  • GAA_FLAG_INCLUDE_GATEWAYS
  • GAA_FLAG_INCLUDE_ALL_INTERFACES
pReserved [in] PVOID
Reserved for future use. This parameter must be NULL.
pAdapterAddresses [in, out] PIP_ADAPTER_ADDRESSES
A pointer to a buffer that receives a linked list of IP_ADAPTER_ADDRESSES structures. Each structure describes an adapter. If this buffer is not large enough, the function returns ERROR_BUFFER_OVERFLOW and sets the pOutBufLen parameter to the required buffer size.
pOutBufLen [in, out] PULONG
On input, this parameter specifies the size, in bytes, of the buffer pointed to by pAdapterAddresses. On output, if the buffer is not large enough, this parameter receives the required buffer size in bytes.
Return Value

If the function succeeds, the return value is ERROR_SUCCESS.

If the buffer pointed to by pAdapterAddresses is not large enough to contain all the adapter address structures, the return value is ERROR_BUFFER_OVERFLOW.

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

Remarks

The GetAdaptersAddresses function is used to retrieve adapter configuration information, including IP addresses, MAC addresses, gateway information, and DNS settings.

The function returns a linked list of IP_ADAPTER_ADDRESSES structures. You need to iterate through this list to access information for each adapter.

It's important to handle the case where the buffer is too small by checking the return value and resizing the buffer accordingly.

Tip: For IPv4, use AF_INET. For IPv6, use AF_INET6. Use AF_UNSPEC to retrieve both IPv4 and IPv6 addresses.
Requirements
Minimum supported client Windows Vista [desktop apps only]
Minimum supported server Windows Server 2008 [desktop apps only]
Header iphlpapi.h
Library Iphlpapi.lib
DLL Iphlpapi.dll
See Also