MSDN Community

Network Management

Posted by TechGuru on Sep 10, 2025

The Network Management section of the Win32 API provides developers with a set of functions to configure, monitor, and control network interfaces, routes, and protocols on a Windows system. This article covers the most commonly used functions, structures, and best practices.

Key Functions

  • GetIfTable – Retrieves a list of network interfaces.
  • GetAdaptersAddresses – Provides detailed information about each adapter.
  • AddIPAddress – Assigns a new IP address to a specific interface.
  • DeleteIPAddress – Removes an IP address from an interface.
  • SetIfEntry – Modifies the operational state of an interface.

Example: Enumerating Network Interfaces

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

int main() {
    DWORD size = 0;
    GetIfTable(NULL, &size, FALSE); // get required size
    MIB_IFTABLE *iftable = (MIB_IFTABLE*)malloc(size);
    if (GetIfTable(iftable, &size, FALSE) == NO_ERROR) {
        for (DWORD i = 0; i < iftable->dwNumEntries; ++i) {
            MIB_IFROW *row = &iftable->table[i];
            wprintf(L"%s (Index: %lu) - %lu bytes sent\\n",
                row->wszName, row->dwIndex, row->dwOutOctets);
        }
    }
    free(iftable);
    return 0;
}

This snippet demonstrates how to retrieve and display basic information about each network interface using GetIfTable.

Best Practices

  • Always check the return value of API calls for ERROR_INSUFFICIENT_BUFFER and allocate the necessary memory.
  • Prefer GetAdaptersAddresses over older functions for IPv6 compatibility.
  • When modifying interface state, ensure you have administrative privileges.
  • Use the SetIfEntry function carefully, as disabling an adapter can affect system connectivity.

Further Reading

Comments (2)

JaneDoe
Very helpful example! I used this to build a network monitor for my app.
MikeSmith
Remember to free the memory allocated for GetAdaptersAddresses as well.