svc_register Subroutine

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

svc_register Subroutine Exported from the libc Library

Purpose

Maps a remote procedure.

Library

C Library (libc.a)

Syntax

#include <rpc/rpc.h>

svc_register (xprt, prognum, versnum, dispatch, protocol)
SVCXPRT * xprt;
u_long  prognum,  versnum;
void (* dispatch) ();
int  protocol;

Description

The svc_register subroutine maps a remote procedure with a service dispatch procedure pointed to by the dispatch parameter. If the protocol parameter has a value of 0, the service is not registered with the portmap daemon. If the protocol parameter does not have a value of 0 (or if it is IPPROTO_UDP or IPPROTO_TCP), the remote procedure triple (prognum, versnum, and protocol parameters) is mapped to the xprt->xp_port port.

The dispatch procedure takes the following form:

dispatch (request, xprt)
struct svc_req *request;
SVCXPRT *xprt;

Parameters

Item Description
xprt Points to a Remote Procedure Call (RPC) service transport handle.
prognum Specifies the program number of the remote program.
versnum Specifies the version number of the remote program.
dispatch Points to the service dispatch procedure.
protocol Specifies the data transport used by the service.

Return Values

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

svc_register Subroutine Exported from the libnsl Library

Purpose

Associates the program and version number with the dispatch subroutine.

Library

Network Services Library (libnsl.a)

Syntax

#include <rpc/rpc.h>
bool_t svc_register (xprt, prognum, versnum, dispatch, protocol)
SVCXPRT *xprt;
rpcprog_t prognum;
rpcvers_t versnum;
void (* dispatch)();
int protocol;

Description

The svc_register subroutine maps a program and version to a service dispatch procedure pointed to by the dispatch parameter. If the value of the protocol parameter is 0, the service is not registered with the portmap daemon. If the value of the protocol parameter is not 0 (or it is IPPROTO_UDP or IPPROTO_TCP), the remote procedure triplet (the program, the version, and the protocol) is mapped to the xprt->xp_port port.

The svc_register subroutine is obsolete. Use the svc_reg subroutine instead.

The dispatch procedure has the following form:

dispatch (request, xprt)
struct svc_req *request;
SVCXPRT *xprt;

Parameters

Item Description
xprt Points to a Remote Procedure Call (RPC) service transport handle.
prognum Specifies the program number of the remote program.
versnum Specifies the version number of the remote program.
dispatch Points to the service dispatch procedure.
protocol Specifies the data transport used by the service.

Return Values

Item Description
1 successful
0 unsuccessful

Examples

#include <rpc/rpc.h>

static void dispatch(rqstp, transp) /* remote procedure */
struct svc_req *rqstp;
SVCXPRT *transp;
{
  /* Dispatch Routine Code */
}

int main()
{
  SVCXPRT *svc = NULL;
  uint_t sendsz, recvsz; 
  int protocol = IPPROTO_TCP;

  /* Set send and recieve buffer sizes to 0 so that they are set to default values
   * when svctcp_create() is called         
   */
  sendsz = 0;
  recvsz = 0;

  /* Create service handle for tcp transport */
  svc = (SVCXPRT *) svctcp_create(RPC_ANYSOCK, sendsz, recvsz);
  if (svc == NULL) {
    fprintf(stderr, "\nsvcudp_create failed\n");
    exit(1);
  }

  if(svc_register(svc, prognum, versnum, dispatch, protocol)==0);
  {
    fprintf(stderr,"svc_register() failed");
    exit(1);
  }

  /* Accept the client requests */
  svc_run();

  return 0;
}