Network Management
This section provides an overview of the Windows APIs for managing network configurations, querying network adapter information, and interacting with network services.
Network Addressing APIs
Understanding and manipulating network addresses is fundamental to network programming. Windows provides a rich set of APIs to handle IP addresses, MAC addresses, and other network-related address information.
IP Address Management
These APIs allow you to retrieve and set IP addresses on network interfaces, manage routing tables, and perform IP address resolution.
Key Functions and Structures:
| API Name / Structure | Description |
|---|---|
GetAdaptersInfo |
Retrieves information about the network adapters installed on the local computer. |
GetAdaptersAddresses |
Retrieves the adapter addresses for the local computer. |
IpAddrTable |
Contains information about the IP address table. |
SendARP |
This function retrieves the Media Access Control (MAC) address associated with an IP address. |
CreateIpForwardEntry |
Adds a new entry to the IP routing table. |
DeleteIpForwardEntry |
Removes an entry from the IP routing table. |
Example Usage (Conceptual C++):
#include <winsock2.h>
#include <iphlpapi.h>
#pragma comment(lib, "iphlpapi.lib")
// ...
ULONG ulOutBufLen = sizeof(IP_ADAPTER_INFO);
PIP_ADAPTER_INFO pAdapterInfo = NULL;
if (GetAdaptersInfo(pAdapterInfo, &ulOutBufLen) == ERROR_BUFFER_OVERFLOW) {
pAdapterInfo = (IP_ADAPTER_INFO*)malloc(ulOutBufLen);
if (pAdapterInfo == NULL) {
// Handle memory allocation error
return 1;
}
}
if (GetAdaptersInfo(pAdapterInfo, &ulOutBufLen) == NO_ERROR) {
PIP_ADAPTER_INFO pAdapter = pAdapterInfo;
while (pAdapter) {
wprintf(L"Adapter Name: %s\n", pAdapter->AdapterName);
wprintf(L" IP Address: %s\n", pAdapter->IpAddressList.IpAddress.String);
wprintf(L" Subnet Mask: %s\n", pAdapter->IpAddressList.IpMask.String);
wprintf(L" Default Gateway: %s\n", pAdapter->GatewayList.IpAddress.String);
pAdapter = pAdapter->Next;
}
}
if (pAdapterInfo) {
free(pAdapterInfo);
}
MAC Address Resolution
The Address Resolution Protocol (ARP) maps IP addresses to MAC addresses on a local network. The Windows Sockets API provides functions to query and manipulate the ARP cache.
Key Functions:
| API Name | Description |
|---|---|
SendARP |
Retrieves the Media Access Control (MAC) address associated with an IP address. |
Network Interface Information
Accessing detailed information about network interfaces, such as their status, properties, and capabilities, is crucial for dynamic network configuration and diagnostics.
Key Structures:
| Structure Name | Description |
|---|---|
IP_INTERFACE_INFO |
Contains information about IP interfaces on the local computer. |
MIB_IFTABLE |
Contains information about the network interfaces on the local computer. |
Related Topics
Note: For advanced network programming and management, consider using the Windows Filtering Platform (WFP) or the Network List Manager APIs.