GetAdaptersInfo
Retrieves adapter information for the local computer. This function is superseded by GetAdaptersAddresses, but it remains supported for compatibility.
Syntax
DWORD GetAdaptersInfo(
PIP_ADAPTER_INFO pAdapterInfo,
PULONG pOutBufLen
);
Parameters
| Parameter | Type | Description |
|---|---|---|
| pAdapterInfo | PIP_ADAPTER_INFO | Pointer to a buffer that receives an array of IP_ADAPTER_INFO structures. If the function fails because the buffer is too small, this parameter is ignored. |
| pOutBufLen | PULONG | On input, the size of the buffer pointed to by pAdapterInfo, in bytes. On output, receives the required size when the buffer is insufficient. |
Return Value
The function returns ERROR_SUCCESS (0) if the call succeeds. On failure it returns a Windows error code, such as ERROR_BUFFER_OVERFLOW (111) when the supplied buffer is too small.
Remarks
- The
IP_ADAPTER_INFOstructure contains fields likeAdapterName,Description,IpAddressList, andGatewayList. - To retrieve the full list, first call the function with
pAdapterInfoset toNULLto obtain the required buffer size. - For IPv6 and more detailed information, use GetAdaptersAddresses.
Example
#include <windows.h>
#include <iphlpapi.h>
#pragma comment(lib, "iphlpapi.lib")
int main() {
ULONG buflen = 0;
GetAdaptersInfo(NULL, &buflen); // Get required size
PIP_ADAPTER_INFO adapter = (PIP_ADAPTER_INFO)malloc(buflen);
if (adapter == NULL) return 1;
DWORD rc = GetAdaptersInfo(adapter, &buflen);
if (rc == ERROR_SUCCESS) {
PIP_ADAPTER_INFO cur = adapter;
while (cur) {
wprintf(L"Adapter: %S\n", cur->Description);
wprintf(L"IP Address: %s\n", cur->IpAddressList.IpAddress.String);
cur = cur->Next;
}
}
free(adapter);
return 0;
}