INT GetDefaultHostFile( |
|
LPTSTR lpszFileName, |
|
|
INT nMaxLength |
|
); |
INT GetDefaultHostFile( |
|
CString& strFileName |
|
); |
The GetDefaultHostFile method returns the fully qualified
path name of the host file on the local system. 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 GetHostName methods.
The file is a plain text file, with each line in the file specifying
a record, and each field separated by spaces or tabs. The format of
the file must be as follows:
ipaddress hostname [hostalias ...]
For example, one typical entry maps the name "localhost"
to the local loopback IP address. This would be entered as:
127.0.0.1 localhost
The hash character (#) may be used to specify a comment in the
file, and all characters after it are ignored up to the end of the
line. Blank lines are ignored, as are any lines which do not follow
the required format.
Parameters
- lpszFileName
- Pointer to a string buffer that will contain
the fully qualified file name to the default host file. 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
byte. An alternative version of this method accepts a
CString object.
- nMaxLength
- The maximum number of characters that may be copied to the
string buffer.
Return Value
If the function succeeds, the return value is the number of
characters copied into the string buffer, not including the
terminating null character.
A return value of zero indicates that the default host file could not
be determined for the current platform. To get extended error
information, call GetLastError.
Remarks
This method returns the location of the host file and does not
determine if the file actually exists. The default location for this
file is in a protected area of the Windows operating system and can
only be modified by a process with administrative privileges.
The default host file is processed before performing a nameserver
lookup when resolving a hostname into an IP address, or an IP address
into a hostname. To specify an alternate local host file, use the
SetHostFile 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: csdnsv11.lib
Unicode: Implemented as Unicode and ANSI versions
See Also
GetDefaultServicesFile,
GetHostAddress,
GetHostFile,
GetHostName,
SetHostFile
|