windows-embedded-compact

How to get netmask and default gateway of adapters in WEC2013


The function GetAdaptersInfo allows to retrieve the address information including netmask and default gateway for all adapters.

This function is deprecated since Windows Embedded Compact 7. The "Functionality To Use Instead" list the function GetAdaptersAddresses as a replacement. But this function doesn't report netmask and default gateway.

How can I get the netmask and the default gateway of the network adapters?


Solution

  • GetAdaptersAddresses returns a linked list of IP_ADAPTER_ADDRESSES structs.

    Within each IP_ADAPTER_ADDRESSES, the FirstUnitcastAddress field points to a list of IP_ADAPTER_UNICAST_ADDRESSES structs.

    Within each IP_ADAPTER_UNICAST_ADDRESSES there is a field called OnLinkPrefixLength, which specifies the netmask as the length, in bits, of the network part of the IP address. Note that this field is not documented for WEC2013 (it is for desktop Windows, though).

    To convert OnLinkPrefixLength to a ULONG mask, use ConvertLengthToIpv4Mask.

    Gateway addresses are provided through the FirstGatewayAddress field in each IP_ADAPTER_ADDRESSES struct.