|
BOOL ValidateHostName( |
|
LPCTSTR lpszHostName, |
|
|
LPTSTR lpszAddress, |
|
|
INT nMaxLength |
|
); |
BOOL ValidateHostName( |
|
LPCTSTR lpszHostName, |
|
|
CString& strAddress |
|
); |
The ValidateHostName method determines if the specified
host name is valid and returns its IP address.
Parameters
- lpszHostName
- A pointer to a null terminated string which specifies the host
name. The method will fail If this parameter is NULL or an empty
string.
- lpszAddress
- A pointer to a string buffer which will contain the IP address
of the host. If specified, this string must be large enough to store
the complete IP address, including the terminating null character.
If this parameter is NULL or the nMaxLength parameter is zero, it
will be ignored and the IP address will not be returned. An
alternate version of this method accepts a reference to a CString
object if MFC or ATL is used with the project.
- nMaxLength
- An integer value that specifies the maximum number of characters
which can be copied into the lpszAddress string buffer. The
buffer must be large enough to store the complete address. Because
this method can return either an IPv4 or IPv6 address, it is
recommended the minimum length for the buffer to be 46 characters.
If this parameter is zero, the lpszAddress parameter will be
ignored.
Return Value
If the method succeeds, the host name is valid and the return value
will be non-zero. If the method fails, the host name could not be resolved
to an IP address and the return value will be zero. To get extended error
information, call the GetLastError method.
Remarks
The ValidateHostName method provides a convenient way
to determine if a host name is valid by attempting to resolve the name
into an IP address. If the Unicode version of this method is used, any non-ASCII
characters in the host name will be automatically encoded into a
compatible format and then resolved to an IP address. If you are
unsure if an internationalized domain name will be specified as the
host name, it is recommended you use the Unicode version.
If the lpszHostName parameter specifies a valid IPv4 or
IPv6 address string instead of a host name, this method will return
a copy of that IP address in the buffer provided by the caller. This
allows the method to be used in cases where a user may input either
a host name or IP address.
If you wish to validate a complete FTP URL instead of a host name,
use the ValidateUrl method.
Requirements
Minimum Desktop Platform: Windows 7 Service Pack 1
Minimum Server Platform: Windows Server 2008 R2 Service Pack 1
Header File: cstools11.h
Import Library: csftpv11.lib
Unicode: Implemented as Unicode and ANSI versions
See Also
ConnectUrl,
ValidateUrl
|
|