CInternetServer::GetHostAddress Method  
 
INT GetHostAddress(
  LPCTSTR lpszHostName,  
  INT nAddressFamily,  
  LPINTERNET_ADDRESS lpAddress  
);
INT GetHostAddress(
  LPCTSTR lpszHostName,  
  LPINTERNET_ADDRESS lpAddress  
);

The InetGetHostAddress method resolves the specified host name into an IP address in binary format.

Parameters

lpszHostName
A pointer to the name of the host to resolve; this may be a fully-qualified domain name or an IP address. This method recognizes the format for both IPv4 and IPv6 format addresses.
nAddressFamily
An integer which identifies the type of IP address to return. It may be one of the following values:
Constant Description
INET_ADDRESS_UNKNOWN Return the IP address for the specified host in either IPv4 or IPv6 format, depending on how the host name can be resolved. By default, a preference will be given for returning an IPv4 address. However, if the host only has an IPv6 address, that value will be returned.
INET_ADDRESS_IPV4 Specifies that the address should be returned in IPv4 format. 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 Specifies that the address should be returned in IPv6 format. All bytes in the ipNumber array are significant. Note that it is possible for an IPv6 address to actually represent an IPv4 address. This is indicated by the first 10 bytes of the address being zero.
lpAddress
A pointer to an INTERNET_ADDRESS structure that will contain the IP address of the specified host.

Return Value

If the method succeeds, the return value is zero. If the function fails, the return value is INET_ERROR. To get extended error information, call InetGetLastError.

Remarks

This method can also be used to convert an address in dot notation to a binary format. If the method must perform a DNS lookup to resolve the hostname, the calling thread will block. To ensure future compatibility with IPv6 networks, it is important that the application does not make any assumptions about the format of the address. If the function returns successfully, the ipFamily member of the INTERNET_ADDRESS structure should always be checked to determine the type of address.

The nAddressFamily parameter is used to specify a preference for the type of address returned, however it is possible that a host may not have an IPv4 or IPv6 address record, in which case this function will fail. Although IPv4 is still the most common address used at this time, an application should not assume that because a given host name does not have an IPv4 address, that the host name is invalid.

If the nAddressFamily parameter is specified as INET_ADDRESS_UNKNOWN, the application must be prepared to handle IPv6 addresses because it is possible for a host name to have an IPv6 address assigned to it and no IPv4 address. For legacy applications that only recognize IPv4 addresses, the nAddressFamily member should always be specified as INET_ADDRESS_IPV4 to ensure that only IPv4 addresses are returned.

To determine if the local system has an IPv6 TCP/IP stack installed and configured on the local system, use the IsProtocolAvailable method. If an IPv6 stack is not installed, this method will fail if the lpszHostName parameter specifies an host that only has an IPv6 (AAAA) DNS record.

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
Unicode: Implemented as Unicode and ANSI versions.

See Also

GetClientAddress, GetHostName, GetLocalAddress, GetLocalName, IsProtocolAvailable, INTERNET_ADDRESS