CSocketWrench::EnumNetworkAddresses Method  
 
INT EnumNetworkAddresses(
  INT nAddressFamily,  
  LPINTERNET_ADDRESS lpAddressList,  
  INT nMaxAddresses  
);
INT EnumNetworkAddresses(
  LPINTERNET_ADDRESS lpAddressList,  
  INT nMaxAddresses  
);

The EnumNetworkAddresses method returns the list of network addresses that are configured for the local host.

Parameters

nAddressFamily
An integer which identifies the type of IP address that should be returned by this method. It may be one of the following values:
Constant Description
INET_ADDRESS_ANY Return both IPv4 or IPv6 addresses assigned to the local host, depending on how the system is configured and which network interfaces are enabled. This option is only recommended for applications that require support for IPv6 connections.
INET_ADDRESS_IPV4 Return only the IPv4 addresses assigned to the local host. The first four bytes of the ipNumber array are significant and contains the IP address. The remaining bytes are not significant and an application should not depend on them having any particular value, including zero.
INET_ADDRESS_IPV6 Return only the IPv6 addresses assigned to the local host. All bytes in the ipNumber array are significant. This option is only recommended for those applications that require support for IPv6 connections.
lpAddressList
A pointer to an array of INTERNET_ADDRESS structures that will contain the IP address of each local network interface. This parameter may be NULL, in which case the method will only return the number of available addresses.
nMaxAddresses
Maximum number of addresses to be returned. If the lpAddressList parameter is NULL, this value must be zero.

Return Value

If the method succeeds, the return value is the number of network addresses that are configured for the local host. If the method fails, the return value is INET_ERROR. To get extended error information, call the GetLastError method.

Remarks

If the nAddressFamily parameter is specified as INET_ADDRESS_ANY, the application must be prepared to accept IPv6 addresses returned by this method. On Windows Vista and later versions of the operating system, IPv6 support is enabled and the local network adapter will have IPv6 addresses assigned to them by default. For legacy applications that only recognize IPv4 addresses, the nAddressFamily parameter should always be specified as INET_ADDRESS_IPV4 to ensure that only IPv4 addresses are returned.

This method will ignore addresses that are bound to a disabled interface, as well as those addresses bound to a virtual loopback interface. For example, although the loopback address 127.0.0.1 is a valid network address, it will not be included in list of addresses returned by this method.

The first IPv4 or IPv6 address returned by this method is typically the address assigned to the primary network adapter on the local system. However, your application should not depend on addresses being returned in any particular order. If the system has virtualization software installed, this method may also include the IP addresses assigned to any virtualized network adapters installed by that software.

Requirements

Minimum Desktop Platform: Windows 7 (Service Pack 1)
Minimum Server Platform: Windows Server 2008 R2 (Service Pack 1)
Header: Include cswsock10.h
Import Library: cswskv10.lib

See Also

GetAdapterAddress, GetHostAddress, GetLocalAddress