JavaScript is required to for searching.
Skip Navigation Links
Exit Print View
ONC+ Developer's Guide     Oracle Solaris 11 Express 11/10
search filter icon
search icon

Document Information


1.  Introduction to ONC+ Technologies

2.  Introduction to TI-RPC

3.  rpcgen Programming Guide

4.  Programmer's Interface to RPC

Simplified Interface

Client Side of Simplified Interface

Server Side of the Simplified Interface

Hand-Coded Registration Routine

Passing Arbitrary Data Types

Standard Interfaces

Top-Level Interface

Client Side of the Top-Level Interface

Intermediate-Level Interface

Client Side of the Intermediate-Level Interface

Server Side of the Intermediate-Level Interface

Expert-Level Interface

Client Side of the Expert-Level Interface

Server Side of the Expert-Level Interface

Bottom-Level Interface

Client Side of the Bottom-Level Interface

Server Side of the Bottom-Level Interface

Server Caching

Low-Level Data Structures

Testing Programs Using Low-Level Raw RPC

Connection-Oriented Transports

Memory Allocation With XDR

5.  Advanced RPC Programming Techniques

6.  Porting From TS-RPC to TI-RPC

7.  Multithreaded RPC Programming

8.  Extensions to the Sun RPC Library

9.  NIS+ Programming Guide

A.  XDR Technical Note

B.  RPC Protocol and Language Specification

C.  XDR Protocol Specification

D.  RPC Code Examples

E.  portmap Utility

F.  Writing a Port Monitor With the Service Access Facility (SAF)



Memory Allocation With XDR

XDR routines normally serialize and deserialize data. XDR routines often automatically allocate memory and free automatically allocated memory. The convention is to use a NULL pointer to an array or structure to indicate that an XDR function must allocate memory when deserializing. The next example, xdr_chararr1(), processes a fixed array of bytes with length SIZE and cannot allocate memory if needed:

xdr_chararr1(xdrsp, chararr)
   XDR *xdrsp;
   char chararr[];
   char *p;
   int len;

   p = chararr;
   len = SIZE;
   return (xdr_bytes(xdrsp, &p, &len, SIZE));

If space has already been allocated in chararr, it can be called from a server as follows.

char chararr[SIZE];
svc_getargs(transp, xdr_chararr1, chararr);

Any structure through which data is passed to XDR or RPC routines must be allocated so that its base address is at an architecture-dependent boundary. An XDR routine that does the allocation must be written so that it can:

In the following example, the second argument is a NULL pointer, meaning that memory should be allocated to hold the data being deserialized.

xdr_chararr2(xdrsp, chararrp)
   XDR *xdrsp;
   char **chararrp;

   int len;

   len = SIZE;
   return (xdr_bytes(xdrsp, charrarrp, &len, SIZE));

The corresponding RPC call is:

char *arrptr;
arrptr = NULL;
svc_getargs(transp, xdr_chararr2, &arrptr);
 * Use the result here
svc_freeargs(transp, xdr_chararr2, &arrptr);

After use, free the character array through svc_freeargs(). svc_freeargs() does nothing if passed a NULL pointer as its second argument.

To summarize: