Specifications

Remote Procedure Call Programming Guide Page 9
If the size of the array is known in advance, one can use xdr_vector(), which serializes fixed-length arrays.
int intarr[SIZE];
xdr_intarr(xdrsp, intarr)
XDR *xdrsp;
int intarr[];
{
int i;
return (xdr_vector(xdrsp, intarr, SIZE, sizeof(int),
xdr_int));
}
XDR always converts quantities to 4-byte multiples when serializing. Thus, if either of the examples above
involved characters instead of integers, each character would occupy 32 bits. That is the reason for the
XDR routine xdr_bytes() which is like xdr_array() except that it packs characters; xdr_bytes() has four
parameters, similar to the first four parameters of xdr_array(). For null-terminated strings, there is also the
xdr_string() routine, which is the same as xdr_bytes() without the length parameter. On serializing it gets
the string length from strlen(), and on deserializing it creates a null-terminated string.
Here is a final example that calls the previously written xdr_simple() as well as the built-in functions
xdr_string() and xdr_reference(), which chases pointers:
struct finalexample {
char *string;
struct simple *simplep;
} finalexample;
xdr_finalexample(xdrsp, finalp)
XDR *xdrsp;
struct finalexample *finalp;
{
if (!xdr_string(xdrsp, &finalp->string, MAXSTRLEN))
return (0);
if (!xdr_reference(xdrsp, &finalp->simplep,
sizeof(struct simple), xdr_simple);
return (0);
return (1);
}
Note that we could as easily call xdr_simple() here instead of xdr_reference().
3. Lowest Layer of RPC
In the examples given so far, RPC takes care of many details automatically for you. In this section, we’ll
show you how you can change the defaults by using lower layers of the RPC library. It is assumed that you
are familiar with sockets and the system calls for dealing with them.
There are several occasions when you may need to use lower layers of RPC. First, you may need to use
TCP, since the higher layer uses UDP, which restricts RPC calls to 8K bytes of data. Using TCP permits
calls to send long streams of data. For an example, see the TCP section below. Second, you may want to
allocate and free memory while serializing or deserializing with XDR routines. There is no call at the
higher level to let you free memory explicitly. For more explanation, see the Memory Allocation with XDR
section below. Third, you may need to perform authentication on either the client or server side, by supply-
ing credentials or verifying them. See the explanation in the Authentication section below.