Retrieving Information Using GetNetworkParams

The GetNetworkParams function fills a pointer to a FIXED_INFO structure with data about the current network settings.

Aa366351.wedge(en-us,VS.85).gifTo use GetNetworkParams

  1. 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;
    
    
    
  2. 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);
    
    
    
  3. 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");
            }
        }
    
    
    
  4. 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);
            }
        }        
    
    
    
  5. 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");
    
    
    
  6. 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

 

 

Community Additions

ADD
Show:
© 2014 Microsoft