Overview
The GetNetworkParams function retrieves the current network configuration information for the local computer.
It is part of the IP Helper API and is documented for Windows Desktop development.
Syntax
ULONG GetNetworkParams(
PFIXED_INFO pFixedInfo,
PULONG pOutBufLen
);
Parameters
| Name | Type | Description |
|---|---|---|
| pFixedInfo | PFIXED_INFO | Pointer to a FIXED_INFO structure that receives the network configuration data. |
| pOutBufLen | PULONG | Pointer to a variable that specifies the size of the buffer pointed to by pFixedInfo. On return it receives the actual size needed. |
Return Value
Returns NO_ERROR (0) on success. On failure, the function returns a Windows error code such as ERROR_BUFFER_OVERFLOW if the supplied buffer is too small.
Remarks
- The caller must allocate a buffer large enough to hold the
FIXED_INFOstructure and any associated strings. - If
ERROR_BUFFER_OVERFLOWis returned, thepOutBufLenvariable contains the required buffer size. - Call
GetNetworkParamsafter the network configuration changes to obtain updated information.
Example
#include <windows.h>
#include <iphlpapi.h>
#include <stdio.h>
#pragma comment(lib, "iphlpapi.lib")
int main() {
DWORD dwSize = 0;
GetNetworkParams(NULL, &dwSize); // Get required size
FIXED_INFO *pFixedInfo = (FIXED_INFO *)malloc(dwSize);
if (pFixedInfo == NULL) {
printf("Memory allocation failed.\n");
return 1;
}
DWORD dwRetVal = GetNetworkParams(pFixedInfo, &dwSize);
if (dwRetVal == NO_ERROR) {
printf("Host Name: %s\n", pFixedInfo->HostName);
printf("Domain Name: %s\n", pFixedInfo->DomainName);
printf("DNS Servers:\n");
IP_ADDR_STRING *pDns = &pFixedInfo->DnsServerList;
while (pDns) {
printf(" %s\n", pDns->IpAddress.String);
pDns = pDns->Next;
}
} else {
printf("GetNetworkParams failed with error %d\n", dwRetVal);
}
free(pFixedInfo);
return 0;
}