CDnsClient::GetDefaultServicesFile Method  
 
INT GetDefaultServicesFile(
  LPTSTR lpszFileName,  
  INT nMaxLength  
);
INT GetDefaultServicesFile(
  CString& strFileName  
);

The GetDefaultServicesFile method returns the fully qualified path name of the services file on the local system. The services file is used as a database that maps a port number to a service name, and is used by the GetServiceName and GetServicePort 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:

name port/protocol [alias ...]

For example, one typical entry maps the service name "http" to port 80, the standard port for the Hypertext Transfer Protocol. This would be entered as:

http 80/tcp www www-http

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 path to the default services file. It is recommended that this buffer be at least MAX_PATH characters in size. This parameter may be NULL, in which case the function 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 method 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 services file could not be determined for the current platform. To get extended error information, call GetLastError.

Remarks

This method returns the location of the services 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.

Requirements

Minimum Desktop Platform: Windows 7 Service Pack 1
Minimum Server Platform: Windows Server 2008 R2 Service Pack 1
Header File: cstools12.h
Import Library: csdnsv12.lib
Unicode: Implemented as Unicode and ANSI versions

See Also