IP Helper API (iphlpapi)

Overview

The IP Helper API provides a set of functions and data structures that enable applications to retrieve and modify network configuration settings on Windows operating systems. It includes capabilities for enumerating adapters, interfaces, IP addresses, routing tables, and more.

Functions

FunctionDescription
GetAdaptersInfoRetrieves adapter information for the local computer.
GetIfTableRetrieves a table of interface entries.
GetBestInterfaceDetermines the interface best suited for a destination IP address.
GetIpAddrTableRetrieves the IP address table.
GetNetworkParamsRetrieves network parameters such as DNS servers and domain name.
InitializeWinsockInitializes the Windows Sockets library.
ResolveIPResolves a host name to an IP address.

Structures

  • IP_ADAPTER_INFO
  • MIB_IFTABLE
  • MIB_IPADDRTABLE
  • FIXED_INFO
  • IP_ADAPTER_UNICAST_ADDRESS

Constants

#define MAX_ADAPTER_NAME_LENGTH 256
#define MAX_ADAPTER_DESCRIPTION_LENGTH 128
#define ERROR_BUFFER_OVERFLOW 111
#define ERROR_SUCCESS 0

Code Samples

Enumerate Network Adapters (C++)

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

int main() {
    DWORD size = 0;
    GetAdaptersInfo(nullptr, &size);
    IP_ADAPTER_INFO *info = (IP_ADAPTER_INFO*)malloc(size);
    if (GetAdaptersInfo(info, &size) == NO_ERROR) {
        for (IP_ADAPTER_INFO *p = info; p; p = p->Next) {
            wprintf(L"Adapter: %S\n", p->AdapterName);
            wprintf(L"Description: %S\n", p->Description);
            wprintf(L"IP: %s\n", p->IpAddressList.IpAddress.String);
        }
    }
    free(info);
    return 0;
}