Network Management API Reference

This section details the Windows APIs for managing network configurations, connections, and status. Leverage these functions to build robust network-aware applications.

Core Network Interfaces

GetNetworkAdapterInfo

Retrieves detailed information about network adapters installed on the system.

Parameters

  • adapterGuid: GUID - The unique identifier of the network adapter.
  • infoBuffer: PAdapterInfo - A pointer to a structure that will receive the adapter information.

Returns

  • DWORD: Returns ERROR_SUCCESS on success, or an appropriate error code otherwise.

Example


// C++ Example
DWORD status = GetNetworkAdapterInfo(someGuid, &adapterInfo);
if (status == ERROR_SUCCESS) {
    // Process adapterInfo
}
                    

SetNetworkAdapterStatus

Enables or disables a network adapter.

Parameters

  • adapterGuid: GUID - The unique identifier of the network adapter.
  • enable: BOOL - TRUE to enable, FALSE to disable.

Returns

  • DWORD: Returns ERROR_SUCCESS on success.

IP Configuration

GetIpAddressConfiguration

Retrieves the current IP address, subnet mask, and default gateway for a given network interface.

Parameters

  • interfaceIndex: NET_IFINDEX - The index of the network interface.
  • ipConfig: PIP_ADAPTER_ADDRESSES - A pointer to a structure that receives the IP configuration details.

Returns

  • DWORD: Returns NO_ERROR on success.

SetIpAddressConfiguration

Configures the IP address, subnet mask, and default gateway for a network interface.

Parameters

  • interfaceIndex: NET_IFINDEX - The index of the network interface.
  • ipAddress: const WCHAR* - The desired IP address.
  • subnetMask: const WCHAR* - The desired subnet mask.
  • defaultGateway: const WCHAR* - The desired default gateway.

Returns

  • DWORD: Returns NO_ERROR on success.

Exceptions

  • ERROR_INVALID_PARAMETER: If any input parameter is invalid.
  • ERROR_ACCESS_DENIED: If the caller does not have sufficient privileges.

Connectivity and Diagnostics

PingHost

Sends ICMP echo requests to a specified host to check network connectivity and latency.

Parameters

  • hostName: const char* - The hostname or IP address to ping.
  • timeoutMilliseconds: DWORD - The timeout in milliseconds for each echo request.
  • responseDetails: PingResponse* - A pointer to a structure that will receive the ping response details.

Returns

  • BOOL: TRUE if at least one reply was received, FALSE otherwise.

Example


// C# Example (via P/Invoke)
string host = "www.example.com";
PingResponse response;
bool success = PingHost(host, 5000, out response);
if (success) {
    Console.WriteLine($"Ping successful! Latency: {response.AverageRTT} ms");
} else {
    Console.WriteLine("Ping failed.");
}