|
INT GetHostAddress( |
|
LPCTSTR lpszHostName, |
|
|
INT nAddressFamily, |
|
|
LPTSTR lpszHostAddress, |
|
|
INT nMaxLength |
|
); |
INT GetHostAddress( |
|
LPCTSTR lpszHostName, |
|
|
LPTSTR lpszHostAddress, |
|
|
INT nMaxLength |
|
); |
INT GetHostAddress( |
|
LPCTSTR lpszHostName, |
|
|
INT nAddressFamily, |
|
|
CString& strHostAddress |
|
); |
INT GetHostAddress( |
|
LPCTSTR lpszHostName, |
|
|
CString& strHostAddress |
|
); |
The GetHostAddress method resolves the specified host name,
storing the IP address in the provided buffer.
Parameters
- 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.
- nAddressFamily
- An integer value which specifies the type of address that
should be returned. A value of DNS_ADDRESS_IPV4 specifies that the IPv4
address for the host should be returned. A value of DNS_ADDRESS_IPV6
specifies that the IPv6 address for the host should be returned. A
value of DNS_ADDRESS_ANY specifies that if the host only has an IPv6
address, that value should be returned, otherwise return the IPv4
address for the host. There are alternate versions of this method
which omits the address family, in which case it will default to
returning the IPv4 address for the host.
- lpszHostAddress
- Pointer to the buffer that will contain the IP address, stored
as a string in dot notation. This buffer should be at least 48 characters
in length. The format of the address is determined by the address family
specified.
- nMaxLength
- The maximum length of the string buffer. The maximum length of
the buffer must include the terminating null character.
Return Value
If the method succeeds, the return value is the number of
characters copied into the host address buffer. If the method fails,
the return value is DNS_ERROR. To get extended error information,
call GetLastError.
Remarks
The GetHostAddress method 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 DNS_ADDRESS_IPV4 to prevent the possibility
of an IPv6 address being returned.
If the nAddressFamily parameter is specified as DNS_ADDRESS_ANY,
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
GetAddressFamily method.
Requirements
Minimum Desktop Platform: Windows 7 (Service Pack 1)
Minimum Server Platform: Windows Server 2008 R2 (Service Pack 1)
Header File: cstools10.h
Import Library: csdnsv10.lib
Unicode: Implemented as Unicode and ANSI versions.
See Also
EnumHostAliases,
GetAddressFamily
GetHostName,
GetRecord
|
|