CSocketWrench::GetHostFile Method  
 
INT GetHostFile(
  LPTSTR lpszFileName,  
  INT nMaxLength  
);
INT GetHostFile(
  CString& strFileName  
);

The GetHostFile method returns the name of the host file previously set using the SetHostFile method. The host file is used as a database that maps an IP address to one or more hostnames, and is used by the GetHostAddress and GetHostNames method.

Parameters

lpszFileName
Pointer to a string buffer that will contain the host file name. It is recommended that this buffer be at least MAX_PATH characters in size. This parameter may be NULL, in which case the method will return the length of the string, not including the terminating null character.
nMaxLength
The maximum number of characters that may be copied to the string buffer.

Return Value

If the method succeeds, the return value is length of the string. A return value of zero indicates that no host file has been specified or the method was unable to determine the file name. To get extended error information, call GetLastError. If the last error is zero, this indicates that no host file name has been specified for the current thread. If the last error is non-zero, this indicates the reason that the method failed.

Remarks

This method only returns the name of the host file that is cached in memory for the current thread. The contents of the file on the disk may have changed after the file was loaded into memory. To reload the host file or clear the cache, call the SetHostFile method.

If a host file has been specified, it is processed before the default host file when resolving a hostname into an IP address, or an IP address into a hostname. If the host name or address is not found, or no host file has been specified, a nameserver lookup is performed.

The host file returned by this method may be different than the default host file for the local system. To determine the file name for the default host file, use the GetDefaultHostFile method.

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

GetDefaultHostFile, GetHostAddress, GetHostName, SetHostFile