CDnsClient::GetServiceName Method  
 
INT GetServiceName(
  INT nServicePort,  
  INT nServiceType,  
  LPTSTR lpszServiceName,  
  INT nMaxLength  
);
INT GetServiceName(
  INT nServicePort,  
  INT nServiceType,  
  CString& strServiceName  
);

The GetServiceName method returns the service name assigned to the specified port number.

Parameters

nServicePort
An integer which specifies the port number. This value must be a valid port number in the range of 1 through 65535.
nServiceType
An integer which specifies the protocol associated with the service. This may be one of the following values:
Value Description
DNS_SERVICE_ANY Match the first service entry for the specified port number regardless of the protocol used.
DNS_SERVICE_TCP Match a service entry for the specified port number which uses the TCP protocol.
DNS_SERVICE_UDP Match a service entry for the specified port number which uses the UDP protocol.
lpszServiceName
A null-terminated string buffer which will contain the name of the service assigned to the port number when the method returns. This parameter cannot be NULL and the buffer must be large enough to store the complete service name, including the terminating null character. An alternative version of this method accepts a CString object.
nMaxLength
An integer which specifies the maximum number of characters which can be copied into 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. If the method fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

Port numbers can be assigned human readable service names to make them easier to reference. This method will return the name assigned to the specified port number. If the port number does not have an assigned name, this method will return zero and the last error code will be set to ST_ERROR_INVALID_SERVICE_NAME.

Most applications should use DNS_SERVICE_ANY to return the service name assigned to a port number. Services typically use the same name and port number regardless of the protocol used to establish a connection with them. However, specifying a protocol can enable your application to determine if the service supports the protocol. For example, calling this method with port number 21 and DNS_SERVICE_UDP would result in an error because FTP only supports TCP connections.

Service names are assigned by the Internet Assigned Numbers Authority (IANA) and the database of recognized service names can be returned by calling the GetDefaultServicesFile method. 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