GetNetworkParams function (iphlpapi)

Retrieves network configuration parameters for the local computer.

Syntax

#include <iphlpapi.h> DWORD GetNetworkParams( FIXED_INFO *pFixedInfo, ULONG *pOutBufLen );

Parameters

NameDescription
pFixedInfoPointer to a FIXED_INFO structure that receives the network parameters. The caller must allocate a buffer of size *pOutBufLen. If the buffer is too small, the function fails with ERROR_BUFFER_OVERFLOW and *pOutBufLen is set to the required size.
pOutBufLenPointer to a variable that on input contains the size of the buffer pointed to by pFixedInfo. On output, receives the required size if the supplied buffer is insufficient.

Return value

If the function succeeds, the return value is NO_ERROR. If the function fails, the return value is a Windows error code such as ERROR_BUFFER_OVERFLOW, ERROR_INVALID_PARAMETER, etc.

Remarks

The information returned includes the host name, domain name, DNS server list, WINS server list, node type, routing enabled flag, and other default network settings. The data is cached by the system; to obtain the most current values, call the function after a system configuration change or after a reboot.

Example

#include <windows.h> #include <iphlpapi.h> #include <stdio.h> #pragma comment(lib, "iphlpapi.lib") int main() { FIXED_INFO *pFixedInfo = NULL; ULONG outBufLen = 0; DWORD dwRetVal = GetNetworkParams(pFixedInfo, &outBufLen); if (dwRetVal == ERROR_BUFFER_OVERFLOW) { pFixedInfo = (FIXED_INFO *)malloc(outBufLen); if (pFixedInfo == NULL) { printf("Memory allocation failed.\n"); return 1; } dwRetVal = GetNetworkParams(pFixedInfo, &outBufLen); } 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 *dns = &pFixedInfo->DnsServerList; while (dns) { printf(" %s\n", dns->IpAddress.String); dns = dns->Next; } } else { printf("GetNetworkParams failed with error %lu\n", dwRetVal); } if (pFixedInfo) free(pFixedInfo); return 0; }

The example prints the local computer’s host name, domain name, and DNS server addresses.

See also