GetNetworkParams

IP Helper API

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

NameTypeDescription
pFixedInfoPFIXED_INFOPointer to a FIXED_INFO structure that receives the network configuration data.
pOutBufLenPULONGPointer 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

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;
}

See Also