svc_reg Subroutine

Purpose

Associates the program number and version number with a service-dispatch subroutine.

Library

Network Services Library (libnsl.a)

Syntax

#include <rpc/rpc.h>
int svc_reg( xprt, prog, vers, dispatch, nconf)
const SVCXPRT *xprt;
const rpcprog_t prog;
const rpcvers_t vers;
void (*dispatch)(struct svc_req *, SVCXPRT *);
const struct netconfig *nconf;

Description

The svc_reg subroutine is an expert-level API for transport-independent remote procedure calls (TI_PRC). This subroutine registers the program number and version with the RPC service package on the transport that is specified by the nconf parameter. This subroutine associates the program number and version number with a service-dispatch subroutine. If you set the nconf parameter to a null value, the service is not registered with the rpcbind service. Otherwise, the service is registered with the rpcbind service.

Parameters

Item Description
xprt Specifies an RPC service handle.
prog Specifies the program number.
vers Specifies the version number.
dispatch Specifies the subroutine that is called when a service request arrives.
nconf Defines a netconfig structure that specifies the type of transport.

Return Values

Item Description
1 successful
0 unsuccessful

Examples

In the following example, before the svc_reg subroutine is called, an RPC service handle must be created with the svc_dg_create, svc_vc_create, svc_fd_create subroutines and so on.

#include <stdlib.h>
#include <rpc/rpc.h>
#include <netconfig.h>

#define PROG 0x3fffffffL
#define VERS 0x1L

static void sample_dispatch();

main()
{
  
  SVCXPRT *svc_handle;
  struct netconfig *nconf;

  /* Get transport type */
  nconf = getnetconfigent("tcp");
  if(nconf == NULL)
  {
    fprintf(stderr,"\nError in getnetconfigent!\n");
    exit(EXIT_FAILURE);
  }

  /* Create RPC service handle */
  svc_handle = svc_tli_create(RPC_ANYFD, nconf, NULL, 0, 0);
  if(svc_handle == (SVCXPRT *)NULL)
  {
    fprintf(stdout,"Error in svc_tli_create!");
    exit(EXIT_FAILURE);
  }  

  
  /* Register dispatch routine for prog and vers with RPCBIND service */

  if(svc_reg(svc_handle, PROG, VERS, sample_dispatch,nconf) == 0)
  {
    fprintf(stdout,"Error in svc_reg!");
    exit(EXIT_FAILURE);
  }
  
  svc_run();
  return 0;
} 

/* following is the sample dispatch routine*/
static void sample_dispatch(struct svc_req *request, SVCXPRT *xprt)
{

  /*   dispatch routine code  */

}