CDnsClient::GetServicePort Method  
 
INT GetServicePort(
  LPCTSTR lpszServiceName,  
  INT nServiceType  
);

The GetServicePort method returns the port number assigned to the specified service.

Parameters

lpszServiceName
A null-terminated string which specifies the service name. Service names are not case sensitive.
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.

Return Value

If the method succeeds, the return value is the port number assigned to the service name. If the method fails, the return value is DNS_ERROR. To get extended error information, call DnsGetLastError.

Remarks

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

Most applications should use DNS_SERVICE_ANY to return the port number assigned to a service. 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 the service name "ftp" 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