| INT
GetDefaultHostFile(
|
|
|
LPTSTR
lpszFileName, |
|
|
|
|
INT
cchMaxLength |
|
|
| );
|
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 method. 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.
The default hosts file is stored in
C:\Windows\system32\drivers\etc\hosts and may or may not exist on a
given system. Note that there is no extension for this file.
Parameters
- lpszFileName
- Pointer to a null-terminated 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.
- cchMaxLength
- 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 the default host file
could not be determined for the current platform. To get extended
error information, call GetLastError.
Remarks
This method only returns the default location of the host file
and does not determine if the file actually exists. It is not
required that a host file be present on the system.
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
Client: Requires Windows Vista, Windows XP or Windows
2000 Professional.
Server: Requires Windows Server 2008, Windows Server 2003 or
Windows 2000 Server.
Header: Include cstools6.h.
Library: Use csdnsav6.lib.
Unicode: Implemented as Unicode and ANSI versions.
See Also
GetHostAddress, GetHostFile, GetHostName, SetHostFile
|