Specifications

Page 8 Remote Procedure Call Programming Guide
then you would call callrpc() as
callrpc(hostname, PROGNUM, VERSNUM, PROCNUM,
xdr_simple, &simple ...);
where xdr_simple() is written as:
#include <rpc/rpc.h>
xdr_simple(xdrsp, simplep)
XDR *xdrsp;
struct simple *simplep;
{
if (!xdr_int(xdrsp, &simplep->a))
return (0);
if (!xdr_short(xdrsp, &simplep->b))
return (0);
return (1);
}
An XDR routine returns nonzero (true in the sense of C) if it completes successfully, and zero otherwise. A
complete description of XDR is in the XDR Protocol Specification section of this manual, only few imple-
mentation examples are given here.
In addition to the built-in primitives, there are also the prefabricated building blocks:
xdr_array() xdr_bytes() xdr_reference()
xdr_vector() xdr_union() xdr_pointer()
xdr_string() xdr_opaque()
To send a variable array of integers, you might package them up as a structure like this
struct varintarr {
int *data;
int arrlnth;
} arr;
and make an RPC call such as
callrpc(hostname, PROGNUM, VERSNUM, PROCNUM,
xdr_varintarr, &arr...);
with xdr_varintarr() defined as:
xdr_varintarr(xdrsp, arrp)
XDR *xdrsp;
struct varintarr *arrp;
{
return (xdr_array(xdrsp, &arrp->data, &arrp->arrlnth,
MAXLEN, sizeof(int), xdr_int));
}
This routine takes as parameters the XDR handle, a pointer to the array, a pointer to the size of the array,
the maximum allowable array size, the size of each array element, and an XDR routine for handling each
array element.