svc_getargs Macro

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

svc_getargs Macro Exported from the libc Library

Purpose

Decodes the arguments of a Remote Procedure Call (RPC) request.

Library

C Library (libc.a)

Syntax

#include <rpc/rpc.h>

svc_getargs ( xprt,  inproc,  in)
SVCXPRT *xprt;
xdrproc_t inproc;
char *in;

Description

The svc_getargs macro decodes the arguments of an RPC request associated with the RPC service transport handle.

Parameters

Item Description
xprt Points to the RPC service transport handle.
inproc Specifies the eXternal Data Representation (XDR) routine that decodes the arguments.
in Specifies the address where the arguments are placed.

Return Values

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

svc_getargs Macro Exported from the libnsl Library

Purpose

Decodes the arguments of a Remote Procedure Call (RPC) request.

Library

Network Services Library (libnsl.a)

Syntax

#include <rpc/rpc.h>
svc_getargs (xprt, inproc, in)
SVCXPRT *xprt;
xdrproc_t inproc;
caddr_t in;

Description

The svc_getargs macro decodes the encoded arguments of an RPC request associated with the RPC service transport handle. The arguments can then be passed to the service procedure for further processing.

Parameters

Item Description
xprt Points to the RPC service transport handle.
inproc Specifies the eXternal Data Representation (XDR) routine that decodes the arguments.
in Specifies the address where the arguments are placed.

Return Values

Item Description
TRUE successful
FALSE unsuccessful

Examples

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

#define PROG 0x3fffffffL
#define VERS 0x1L

static void sample_dispatch();
  
main()
{
  char *nettype = "tcp";
  int no_of_handles;
 
  /* Create RPC service handle and register with RPCBIND service */

  if((no_of_handles = svc_create(sample_dispatch, PROG, VERS,nettype)) == 0)
  {
    fprintf(stdout,"Error in svc_create!");
    exit(EXIT_FAILURE);
  }
  
  svc_run();
  return 0;
} 

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

  /* decode argument from client using xdr_int() */
  if (svc_getargs(xprt, (xdrproc_t)xdr_int,(caddr_t)&args) == FALSE) 
  {  
    svcerr_decode(xprt);
    fprintf(stdout,"Error in svc_getargs!");
    return;
  }
  /* call service procedure */
   
  /* free allocated  data */
  if (svc_freeargs(xprt, (xdrproc_t)xdr_int,(caddr_t)&args) == FALSE) 
  {  
    fprintf(stdout,"Error in svc_freeargs!");
    return;
  }

  /* send reply to client */ 
  if(!svc_sendreply(xprt,(xdrproc_t)xdr_int,(caddr_t)&result))
  {
    fprintf(stdout,"Error in svc_sendreply!");
    svcerr_systemerr(xprt);
  }
}