Microsoft Docs – IP Helper API

IP Helper API (IPHLPAI) Overview

The IP Helper API provides a set of functions that enable you to retrieve and modify network configuration settings for the local computer. It works across IPv4 and IPv6, and provides support for network interfaces, routing tables, ARP cache, and more.

Key Functions

FunctionDescriptionHeader
GetAdaptersInfo Retrieves adapter information for IPv4. iphlpapi.h
GetAdaptersAddresses Retrieves adapter information for IPv4 and IPv6. iphlpapi.h
GetIfTable Gets a table of interfaces and their operational status. iphlpapi.h
CreateUnicastIpAddressEntry Creates a new unicast IP address on an interface. iphlpapi.h
DeleteUnicastIpAddressEntry Removes a unicast IP address from an interface. iphlpapi.h

Primary Structures

  • IP_ADAPTER_INFO – Adapter information for IPv4.
  • IP_ADAPTER_ADDRESSES – Detailed adapter data (IPv4/IPv6).
  • MIB_IFTABLE – Interface table.
  • SOCKADDR_IN – IPv4 socket address.
  • SOCKADDR_IN6 – IPv6 socket address.

Important Constants

#define MAX_ADAPTER_NAME_LENGTH 256
#define MAX_ADAPTER_DESCRIPTION_LENGTH 128
#define ERROR_BUFFER_OVERFLOW 111
#define AF_UNSPEC   0
#define AF_INET     2
#define AF_INET6    23

Sample Usage – Enumerating Network Adapters (C++)

This snippet demonstrates how to retrieve the list of network adapters using GetAdaptersAddresses.

#include <windows.h>
#include <iphlpapi.h>
#pragma comment(lib, "iphlpapi.lib")

int main()
{
    DWORD dwSize = 0;
    GetAdaptersAddresses(AF_UNSPEC, 0, nullptr, nullptr, &dwSize);
    std::vector<BYTE> buffer(dwSize);
    PIP_ADAPTER_ADDRESSES pAdapters = reinterpret_cast<PIP_ADAPTER_ADDRESSES>(buffer.data());

    if (GetAdaptersAddresses(AF_UNSPEC, 0, nullptr, pAdapters, &dwSize) == NO_ERROR)
    {
        for (PIP_ADAPTER_ADDRESSES cur = pAdapters; cur; cur = cur->Next)
        {
            wprintf(L"Adapter: %s\n", cur->FriendlyName);
            for (PIP_ADAPTER_UNICAST_ADDRESS ua = cur->FirstUnicastAddress; ua; ua = ua->Next)
            {
                wchar_t address[INET6_ADDRSTRLEN];
                DWORD len = sizeof(address);
                WSAAddressToString(ua->Address.lpSockaddr, (DWORD)ua->Address.iSockaddrLength,
                                   nullptr, address, &len);
                wprintf(L"  IP: %s\n", address);
            }
        }
    }
    else
    {
        wprintf(L"Failed to get adapter information.\n");
    }
    return 0;
}

Note: Make sure to link against iphlpapi.lib and enable Unicode character set.