rpc_reg Subroutine

Purpose

Registers program number, version number, and procedure with the remote procedure call (RPC) service package.

Library

Network Services Library (libnsl.a)

Syntax

#include <rpc/rpc.h>
bool_t rpc_reg( prog, vers, proc, proc_name, iproc, oproc, nettype);
const rpcprog_t prog;
const rpcvers_t vers;
const rpcproc_t proc;
char *(*proc_name)(char *); 
const xdrproc_t iproc;      
const xdrproc_t oproc;
const char *nettype;

Description

The rpc_reg subroutine is a simplified-level API for transport-independent RPC that specify the transport type. Applications using this level do not need to explicitly create handles. The rpc_reg subroutine registers a program, a procedure, and a version with the RPC service package on all available transports that are specified by the nettype parameter. If you set the nettype parameter to a null value, the rpc_reg subroutine searches transports in NETPATH environment variable from left to right. If the value of the NETPATH environment variable is also null or unset, the rpc_reg subroutine searches in netconfig database from top to bottom. Whenever a service request from a client arrives, the program number, version number, and procedure number are mapped with registered services and respective procedure is called with appropriate parameters. The rpc_reg subroutine uses eXternal Data Representation (XDR) functions to encode and decode the parameters. The rpc_reg subroutine can register an individual procedure that can be a part of a large RPC service. A single procedure cannot be unregistered, but you can unregister the whole RPC service using the svc_unreg subroutine.

Parameters

Item Description
prog Specifies the program number.
vers Specifies the version number.
proc Specifies the procedure number.
proc_name Points to a registered procedure, which returns a pointer to a static result. The parameter to the procedure is a pointer to the decoded procedure argument.
iproc Specifies the XDR function to decode the parameters of the procedure.
oproc Specifies the XDR function to encode the result of the procedure.
nettype Defines a class of transports that can be used for a particular application.

Return Values

Item Description
0 successful
-1 unsuccessful

Examples

In the following example, after the successful run of the rpc_reg subroutine, a service with PROG and VERS is registered with RPC service package on the tcp transport.

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

#define PROG 0x3fffffffL
#define VERS 0x1L
#define PROC 0x1L

char * sample_proc(char *);

main()
{
  char *nettype;

  /* Specify transport type */
  nettype = "tcp";  
         
  /* unregister the previous RPC service */ 
  svc_unreg(PROG,VERS);
          
  /* Register a single procedure at a time using rpc_reg() */
  if(rpc_reg(PROG,VERS,PROC,sample_proc,xdr_char,xdr_char,nettype) == -1)
  {
     fprintf(stderr,"\nError in rpc_reg!\n");
     svc_unreg(PROG,VERS);
     exit(EXIT_FAILURE);
  }

  /* Server waits for client's request to arrive */
  svc_run();

  return 0;
}          

 
char * sample_proc(char *ptr) 
{

  /* code for sample_proc procedure */

}