Overview
The IP Helper (IP Helper API) provides a set of functions that enable applications to retrieve and modify network configuration settings, query interface and routing information, and manage network interfaces on Windows operating systems.
Common Functions
| Function | Header | Description |
|---|---|---|
GetAdaptersInfo | iphlpapi.h | Retrieves adapter information. |
GetIfTable | iphlpapi.h | Gets a table of network interfaces. |
GetIpAddrTable | iphlpapi.h | Retrieves IPv4 address table. |
GetIpForwardTable | iphlpapi.h | Retrieves IPv4 routing table. |
NotifyIpInterfaceChange | iphlpapi.h | Registers for notification of interface changes. |
SetIfEntry | iphlpapi.h | Modifies a network interface. |
For a full list, see the Functions page.
Sample Code
Retrieve IPv4 address table and display each entry:
#include <windows.h>
#include <iphlpapi.h>
#include <stdio.h>
#pragma comment(lib, "iphlpapi.lib")
int main() {
PMIB_IPADDRTABLE pIPAddrTable;
DWORD dwSize = 0;
DWORD dwRetVal = 0;
pIPAddrTable = (MIB_IPADDRTABLE *) malloc(sizeof (MIB_IPADDRTABLE));
if (pIPAddrTable) {
dwSize = sizeof (MIB_IPADDRTABLE);
if (GetIpAddrTable(pIPAddrTable, &dwSize, 0) == ERROR_INSUFFICIENT_BUFFER) {
free(pIPAddrTable);
pIPAddrTable = (MIB_IPADDRTABLE *) malloc(dwSize);
}
if (pIPAddrTable == NULL) {
printf("Memory allocation error\\n");
return 1;
}
}
if ((dwRetVal = GetIpAddrTable(pIPAddrTable, &dwSize, 0)) == NO_ERROR) {
printf("IPv4 Address Table:\\n");
for (int i = 0; i < (int)pIPAddrTable->dwNumEntries; i++) {
MIB_IPADDRROW row = pIPAddrTable->table[i];
struct in_addr IpAddr;
IpAddr.S_un.S_addr = (u_long) row.dwAddr;
printf("Index:%d Addr:%s Mask:%s\\n",
row.dwIndex,
inet_ntoa(IpAddr),
inet_ntoa(*(struct in_addr *)&row.dwMask));
}
} else {
printf("GetIpAddrTable failed with error: %d\\n", dwRetVal);
}
if (pIPAddrTable) free(pIPAddrTable);
return 0;
}
Full examples are available on the Code Samples page.