Purpose
Requests the port number on which a service waits.
Library
C Library (libc.a)
Syntax
#include <rpc/rpc.h>
  u_short pmap_getport (addr, prognum, versnum, protocol)
struct sockaddr_in * addr;
u_long  prognum,  versnum,  protocol;
Description
The pmap_getport subroutine acts as a user interface to the portmap daemon in order to return the port number on which a service waits.
Parameters
| Item | Description | 
|---|---|
| addr | Points to the Internet Protocol (IP) address of the host where the remote program supporting the waiting service resides. | 
| prognum | Specifies the program number of the remote program. | 
| versnum | Specifies the version number of the remote program. | 
| protocol | Specifies the transport protocol the service recognizes. | 
Return Values
Upon successful completion, the pmap_getport subroutine returns the port number of the requested program; otherwise, if the mapping does not exist or the Remote Procedure Call (RPC) system could not contact the remote portmap daemon, this subroutine returns a value of 0. If the remote portmap daemon could not be contacted, the rpc_createerr subroutine contains the RPC status.
Purpose
Requests the port number on which a service waits.
Library
Network Services Library (libnsl.a)
Syntax
#include <rpc/rpc.h>
 u_short pmap_getport (addr, prognum, versnum, protocol)
struct sockaddr_in * addr;
rpcprog_t prognum;
rpcvers_t versnum;
rpcprot_t protocol;
Description
The pmap_getport subroutine acts as a user interface to the portmap daemon in order to return the port number on which a service waits.
Parameters
| Item | Description | 
|---|---|
| addr | Points to the Internet Protocol (IP) address of the host where the remote program supporting the waiting service resides. | 
| prognum | Specifies the program number of the remote program. | 
| versnum | Specifies the version number of the remote program. | 
| protocol | Specifies the transport protocol the service recognizes, which can be IPPROTO_TCP or IPPROTO_UDP. | 
Return Values
Upon successful completion, the pmap_getport subroutine returns the port number of the requested program; otherwise, if the mapping does not exist or the Remote Procedure Call (RPC) system could not contact the remote portmap daemon, this subroutine returns a value of 0. If the remote portmap daemon could not be contacted, the rpc_createerr subroutine contains the RPC status.
Examples
#include <rpc/rpc.h>
int main()
{
  struct sockaddr_in addr;
  u_short   port    = 0;
  rpcprog_t PROGNUM = 0x3ffffff0L;
  rpcvers_t PROGVER = 0x1L;
  struct hostent *hp;
  char hostname[255]; /* Remote host name */
  /* Get the information of host */
  hp = (struct hostent *) gethostbyname(hostname);
  if (hp == NULL) {
    printf("host information for %s not found\n", hostname);
    exit(1);
  }
  /* Retrieve the address of host */
  addr.sin_family = hp->h_addrtype;
  memcpy(&addr.sin_addr.s_addr, hp->h_addr_list[0], hp->h_length);
  
  port = pmap_getport(&addr, PROGNUM, PROGVER, IPPROTO_TCP);
  if(port==0)
  {
    printf("pmap_getport() failed");
    exit(1);
  }
    
  return 0;
}