pmap_set Subroutine

Important: The subroutine is exported from both the libc and the libnsl libraries.

pmap_set Subroutine Exported from the libc Library

Purpose

Maps a remote procedure call to a port.

Library

C Library (libc.a)

Syntax

#include <rpc/rpc.h>

pmap_set (prognum, versnum, protocol, port)
u_long  prognum,  versnum,  protocol;
u_short  port;

Description

The pmap_set subroutine acts as a user interface to the portmap daemon to map the program number, version number, and protocol of a remote procedure call to a port on the machine portmap daemon.

Note: The pmap_set subroutine is called by the svc_register subroutine.

Parameters

Item Description
prognum Specifies the program number of the remote program.
versnum Specifies the version number of the remote program.
protocol Specifies the transport protocol that the service recognizes. The values for this parameter can be IPPROTO_UDP or IPPROTO_TCP.
port Specifies the port on the machine's portmap daemon.

Return Values

Upon successful completion, this routine returns a value of 1. If unsuccessful, it returns a value of 0.

pmap_set Subroutine Exported from the libnsl Library

Purpose

Creates a mapping of the triplet (the program, version, and protocol) to a port.

Library

Network Services Library (libnsl.a)

Syntax

#include <rpc/rpc.h>
bool_t pmap_set (prognum, versnum, protocol, port)
rpcprog_t prognum;
rpcvers_t versnum;
rpcprot_t protocol;
u_short port;

Description

The pmap_set subroutine acts as a user interface to the portmap daemon to map the program number, version number, and protocol of a remote procedure call to a port on the machine portmap daemon. The pmap_set subroutine is called by the svc_register subroutine.

Note: The subroutine only fails if the port is bound.

Parameters

Item Description
prognum Specifies the program number of the remote program.
versnum Specifies the version number of the remote program.
protocol Specifies the transport protocol that the service recognizes. The values for this parameter can be IPPROTO_UDP or IPPROTO_TCP.
port Specifies the port on the portmap daemon of the machine.

Return Values

Item Description
1 successful
0 unsuccessful

Examples

#include <rpc/rpc.h>
u_short get_free_port(void)
{
  /* Code to obtain a free port */
}

int main()
{
  u_short   port    = 0;
  rpcprog_t PROGNUM = 0x3ffffff0L;
  rpcvers_t PROGVER = 0x1L;

  /* Obtain a free port */
  port = get_free_port();
  
  /* Set the mapping between triplet [PROGNUM,PROGVER,PROTOCOL] and port */
  if (pmap_set(PROGNUM, PROGVER, IPPROTO_TCP, port) == 0)
  {
    printf("pmap_set() failed");
    exit(1);
  }

  return 0;
}