The GetNetworkParams function fills a pointer to a FIXED_INFO structure with data about the current network settings.
To use GetNetworkParams
-
Declare a pointer to a FIXED_INFO object called pFixedInfo, and a ULONG object called ulOutBufLen. These variables are passed as parameters to the GetNetworkParams function. Also create a DWORD variable dwRetVal (used for error checking).
FIXED_INFO *pFixedInfo; IP_ADDR_STRING *pIPAddr; ULONG ulOutBufLen; DWORD dwRetVal; -
Allocate memory for the structures.
[!Note]
The size of ulOutBufLen is not sufficient to hold the information. See the next step.pFixedInfo = (FIXED_INFO *) malloc(sizeof (FIXED_INFO)); ulOutBufLen = sizeof (FIXED_INFO); -
Make an initial call to GetNetworkParams to get the size required for the ulOutBufLen variable.
[!Note]
This function function will fail, and is used to ensure that the ulOutBufLen variable specifies a size sufficient for holding all the data returned to pFixedInfo. This is a common programming model for data structures and functions of this type.if (GetNetworkParams(pFixedInfo, &ulOutBufLen) == ERROR_BUFFER_OVERFLOW) { free(pFixedInfo); pFixedInfo = (FIXED_INFO *) malloc(ulOutBufLen); if (pFixedInfo == NULL) { printf("Error allocating memory needed to call GetNetworkParams\n"); } } -
Make a second call to GetNetworkParams using general error checking and returning its value to the DWORD variable dwRetVal; used for more advanced error checking.
if (dwRetVal = GetNetworkParams(pFixedInfo, &ulOutBufLen) != NO_ERROR) { printf("GetNetworkParams failed with error %d\n", dwRetVal); if (pFixedInfo) { free(pFixedInfo); } } -
If the call was successful, access the data from the pFixedInfo data structure.
printf("\tHost Name: %s\n", pFixedInfo->HostName); printf("\tDomain Name: %s\n", pFixedInfo->DomainName); printf("\tDNS Servers:\n"); printf("\t\t%s\n", pFixedInfo->DnsServerList.IpAddress.String); pIPAddr = pFixedInfo->DnsServerList.Next; while (pIPAddr) { printf("\t\t%s\n", pIPAddr->IpAddress.String); pIPAddr = pIPAddr->Next; } printf("\tNode Type: "); switch (pFixedInfo->NodeType) { case 1: printf("%s\n", "Broadcast"); break; case 2: printf("%s\n", "Peer to peer"); break; case 4: printf("%s\n", "Mixed"); break; case 8: printf("%s\n", "Hybrid"); break; default: printf("\n"); } printf("\tNetBIOS Scope ID: %s\n", pFixedInfo->ScopeId); if (pFixedInfo->EnableRouting) printf("\tIP Routing Enabled: Yes\n"); else printf("\tIP Routing Enabled: No\n"); if (pFixedInfo->EnableProxy) printf("\tWINS Proxy Enabled: Yes\n"); else printf("\tWINS Proxy Enabled: No\n"); if (pFixedInfo->EnableDns) printf("\tNetBIOS Resolution Uses DNS: Yes\n"); else printf("\tNetBIOS Resolution Uses DNS: No\n"); -
Free any memory allocated for the pFixedInfo structure.
if (pFixedInfo) { free(pFixedInfo); pFixedInfo = NULL; }
Next Step: Managing Network Adapters Using GetAdaptersInfo
Previous Step: Creating a Basic IP Helper Application
Source: Microsoft Learn / Windows Win32 documentation by Microsoft and contributors. Documentation licensed CC BY 4.0. Code samples are covered by the MIT License. Converted from Markdown, with links normalized and embedded media omitted.
