DnsGetHostAddress Function  
 
INT WINAPI DnsGetHostAddress(
  HCLIENT hClient,  
  INT nAddressFamily,  
  LPCTSTR lpszHostName,  
  LPTSTR lpszHostAddress,  
  INT nMaxLength  
);

The DnsGetHostAddress function resolves the specified host name, storing the IP address in the provided buffer.

Parameters

hClient
Handle to the client session.
nAddressFamily
An integer value which specifies the type of address that should be returned. A value of AF_INET specifies that the IPv4 address for the host should be returned. A value of AF_INET6 specifies that the IPv6 address for the host should be returned. A value of AF_UNSPEC specifies that if the host only has an IPv6 address, that value should be returned, otherwise return the IPv4 address for the host.
lpszHostName
Pointer to the string that contains the hostname to be resolved. If a fully qualified domain name is not provided, the default local domain will be used.
lpszHostAddress
Pointer to the buffer that will contain the IP address, stored as a null-terminated string in dot notation. This buffer should be at least 40 characters in length to accommodate both IPv4 and IPv6 addresses.
nMaxLength
The maximum length of the string buffer.

Return Value

If the function succeeds, the return value is the number of characters copied into the host address buffer. If the function fails, the return value is DNS_ERROR. To get extended error information, call DnsGetLastError.

Remarks

The DnsGetHostAddress function may return an address in either IPv4 or IPv6 format, depending on the address family that is specified and what records exist for the host. If your application does not support the IPv6 address format, you must specify the nAddressFamily parameter as AF_INET to prevent the possibility of an IPv6 address being returned.

If the nAddressFamily parameter is specified as AF_UNSPEC, this function will first check for an IPv4 address record for the host. If it exists, it will return that address. If the host does not have an IPv4 address, it will then check for an IPv6 address record and return that address. This gives preference to IPv4 addresses, but your application should never depend on this behavior. In the future, this function may change to give preference to IPv6 addresses.

To determine what format an address is in, use the DnsGetAddressFamily function.

Requirements

Client: Requires Windows 7, Windows Vista or Windows XP.
Server: Requires Windows Server 2008 or Windows Server 2003.
Header: Include cstools7.h.
Library: Use csdnsav7.lib.
Unicode: Implemented as Unicode and ANSI versions.

See Also

DnsEnumHostAliases, DnsGetAddressFamily, DnsGetHostName, DnsGetMailExchange, DnsGetRecord