JavaScript is required to for searching.
Skip Navigation Links
Exit Print View
ONC+ Developer's Guide     Oracle Solaris 11.1 Information Library
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

5.  Advanced RPC Programming Techniques

6.  Porting From TS-RPC to TI-RPC

7.  Multithreaded RPC Programming

8.  Extensions to the Oracle Solaris RPC Library

A.  XDR Technical Note

B.  RPC Protocol and Language Specification

Protocol Overview

RPC Model

Transports and Semantics

Binding and Rendezvous Independence

Program and Procedure Numbers

Program Number Assignment

Program Number Registration

Other Uses of the RPC Protocol


Broadcast RPC

RPC Message Protocol

Record-Marking Standard

Authentication Protocols




AUTH_DES Authentication

AUTH_DES Authentication Verifiers

Nicknames and Clock Synchronization

DES Authentication Protocol (in XDR language)

Diffie-Hellman Encryption

AUTH_KERB Authentication

NFS Mount Example

KERB Authentication Protocol

RPC Language Specification

Example Service Described in the RPC Language

RPCL Syntax

RPCL Enumerations

RPCL Constants

RPCL Type Definitions

RPCL Declarations

RPCL Simple Declarations

RPCL Fixed-Length Array Declarations

RPCL Variable-Length Array Declarations

RPCL Pointer Declarations

RPCL Structures

RPCL Unions

RPCL Programs

RPCL Special Cases

RPCL C-style Mode

RPCL Booleans

RPCL Strings

RPCL Opaque Data

RPCL Voids

rpcbind Protocol

rpcbind Operation

C.  XDR Protocol Specification

D.  RPC Code Examples

E.  portmap Utility



RPC Language Specification

Just as the XDR data types needed to be described in a formal language, the procedures that operate on these XDR data types in a formal language needed to be described. The RPC Language, an extension to the XDR language, serves this purpose. The following example is used to describe the essence of the language.

Example Service Described in the RPC Language

The following code example shows the specification of a simple ping program.

Example B-4 ping Service Using RPC Language

 * Simple ping program
program PING_PROG {
     version PING_VERS_PINGBACK {
         PINGPROC_NULL(void) = 0;
         * ping the caller, return the round-trip time
         * in milliseconds. Return a minus one (-1) if
          * operation times-out
         PINGPROC_PINGBACK(void) = 1;
         /* void - above is an argument to the call */
     } = 2;
 * Original version
     version PING_VERS_ORIG {
         PINGPROC_NULL(void) = 0;
     } = 1;
} = 200000;    
const PING_VERS = 2; /* latest version */

The first version described is PING_VERS_PINGBACK with two procedures, PINGPROC_NULL and PINGPROC_PINGBACK.

PINGPROC_NULL takes no arguments and returns no results, but it is useful for such things as computing round-trip times from the client to the server and back again. By convention, procedure 0 of any RPC program should have the same semantics, and never require authentication.

The second procedure returns the amount of time in microseconds that the operation used.

The next version, PING_VERS_ORIG, is the original version of the protocol and does not contain the PINGPROC_PINGBACK procedure. It is useful for compatibility with old client programs.

RPCL Syntax

The RPC language (RPCL) is similar to C. This section describes the syntax of the RPC language, and includes examples. It also shows how RPC and XDR type definitions are compiled into C type definitions in the output header file.

An RPC language file consists of a series of definitions.

      definition; definition-list 

The file recognizes six types of definitions:


Definitions are not the same as declarations. No space is allocated by a definition, only the type definition of a single or series of data elements. This behavior means that variables still must be declared.

The RPC language is identical to the XDR language, except for the added definitions described in the following table.

Table B-2 RPC Language Definitions

program program-ident {version-list} = value

version; version-list

version version-ident {procedure-list} = value

procedure; procedure-list

type-ident procedure-ident (type-ident) = value

In the RPC language:

RPCL Enumerations

RPC/XDR enumerations have a similar syntax to C enumerations.

   "enum" enum-ident "{"
     enum-value "," enum-value-list
     enum-value-ident "=" value   

Here is an example of an XDR enum and the C enum to which it gets compiled.

enum colortype {               enum colortype {
     RED = 0,                       RED = 0,
     GREEN = 1,       -->           GREEN = 1,
     BLUE = 2                       BLUE = 2,
};                             };
                               typedef enum colortype colortype;

RPCL Constants

You can use XDR symbolic constants wherever an integer constant is used. A typical use might be in array size specifications:

   const const-ident = integer 

The following example defines a constant, DOZEN, as equal to 12.

const DOZEN = 12; --> #define DOZEN 12 

RPCL Type Definitions

XDR typedefs have the same syntax as C typedefs.

      typedef declaration 

This example defines an fname_type used for declaring file-name strings that have a maximum length of 255 characters.

typedef string fname_type<255>; --> typedef char *fname_type;

RPCL Declarations

XDR has four kinds of declarations. These declarations must be a part of a struct or a typedef. They cannot stand alone.


RPCL Simple Declarations

Simple declarations are just like simple C declarations.

   type-ident variable-ident 


   colortype color; --> colortype color;

RPCL Fixed-Length Array Declarations

Fixed-length array declarations are just like C array declarations.

      type-ident variable-ident [value] 


colortype palette[8]; --> colortype palette[8];

Many programmers confuse variable declarations with type declarations. Note that rpcgen does not support variable declarations. The following example is a program that does not compile.

int data[10];
program P {
   version V {
      int PROC(data) = 1;
     } = 1;
} = 0x200000;

The previous example does not compile because of the variable declaration:

int data[10]

Instead use:

typedef int data[10];


struct data {int dummy [10]};

RPCL Variable-Length Array Declarations

Variable-length array declarations have no explicit syntax in C. The XDR language does have a syntax, using angle brackets:

      type-ident variable-ident <value>
      type-ident variable-ident < > 

The maximum size is specified between the angle brackets. You can omit the size, indicating that the array can be of any size.

int heights<12>; /* at most 12 items */
int widths<>; /* any number of items */

Because variable-length arrays have no explicit syntax in C, these declarations are compiled into struct declarations. An example is the heights declaration compiled into the following struct.

struct {
   u_int heights_len;               /* # of items in array */
     int *heights_val;                /* pointer to array */
} heights;

The number of items in the array is stored in the _len component and the pointer to the array is stored in the _val component. The first part of each component name is the same as the name of the declared XDR variable, heights.

RPCL Pointer Declarations

Pointer declarations are made in XDR exactly as they are in C. Address pointers are not really sent over the network. Instead, XDR pointers are useful for sending recursive data types such as lists and trees. The type is called optional-data, not pointer, in XDR language.

     type-ident *variable-ident 


listitem *next; --> listitem *next;

RPCL Structures

An RPC/XDR struct is declared almost exactly like its C counterpart. It looks like the following.

     struct struct-ident "{"
     declaration ";"
     declaration ";" declaration-list

The following XDR structure is an example of a 2–D coordinate and the C structure that it compiles into.

struct coord {                 struct coord {
     int x;            -->           int x;
     int y;                          int y;
};                             };
                               typedef struct coord coord;

The output is identical to the input, except for the added typedef at the end of the output. This typedef enables you to use coord instead of struct coord when declaring items.

RPCL Unions

XDR unions are discriminated unions, and do not look like C unions. They are more similar to Pascal variant records.

    "union" union-ident "switch" "("simple declaration")" "{"
     "case" value ":" declaration ";"
     "case" value ":" declaration ";" case-list
     "default" ":" declaration ";" 

The following example is of a type returned as the result of a “read data” operation: if no error occurs, return a block of data. Otherwise, don't return anything.

union read_result switch (int errno) {
     case 0:
         opaque data[1024];

This union compiles into the following:

struct read_result {
     int errno;
     union {
         char data[1024];
     } read_result_u;
typedef struct read_result read_result;

Notice that the union component of the output struct has the same name as the type name, except for the trailing _u.

RPCL Programs

You declare RPC programs using the following syntax:

     "program" program-ident "{"
     "}" "=" value;
     version ";"
     version ";" version-list
     "version" version-ident "{"
     "}" "=" value;
     procedure ";"
     procedure ";" procedure-list
     type-ident procedure-ident "(" type-ident ")" "=" value;     

When the -N option is specified, rpcgen also recognizes the following syntax.

     type-ident procedure-ident "(" type-ident-list ")" "=" value;
     type-ident "," type-ident-list 


 * time.x: Get or set the time. Time is represented as seconds
 * since 0:00, January 1, 1970.
program TIMEPROG {
   version TIMEVERS {
      unsigned int TIMEGET(void) = 1;
         void TIMESET(unsigned) = 2;
     } = 1;
} = 0x20000044;

Note that the void argument type means that no argument is passed.

The following file compiles into these #define statements in the output header file.

#define TIMEPROG 0x20000044
#define TIMEVERS 1
#define TIMEGET 1
#define TIMESET 2

RPCL Special Cases

Several exceptions to the RPC language rules follow.

RPCL C-style Mode

The features of the C-style mode of rpcgen have implications for the passing of void arguments. No arguments need be passed if their value is void.

RPCL Booleans

C has no built-in Boolean type. However, the RPC library uses a Boolean type called bool_t that is either TRUE or FALSE. Parameters declared as type bool in XDR language are compiled into bool_t in the output header file.


bool married; --> bool_t married;

RPCL Strings

The C language has no built-in string type, but instead uses the null-terminated char * convention. In C, strings are usually treated as null-terminated single-dimensional arrays.

In XDR language, strings are declared using the string keyword, and compiled into type char * in the output header file. The maximum size contained in the angle brackets specifies the maximum number of characters allowed in the strings, not counting the NULL character. You can omit the maximum size, indicating a string of arbitrary length.


string name<32>;   --> char *name;
string longname<>; --> char *longname;

NULL strings cannot be passed; however, a zero-length string (that is, just the terminator or NULL byte) can be passed.

RPCL Opaque Data

Opaque data is used in XDR to describe untyped data, that is, sequences of arbitrary bytes. You can declare opaque data either as a fixed-length or variable-length array.


opaque diskblock[512]; --> char diskblock[512];
opaque filedata<1024>; --> struct {
                             u_int filedata_len;
                             char *filedata_val;
                         } filedata;

RPCL Voids

In a void declaration, the variable is not named. The declaration is just void and nothing else. Void declarations can only occur in two places: union definitions and program definitions as the argument or result of a remote procedure; for example, no arguments are passed.

rpcbind Protocol

rpcbind maps RPC program and version numbers to universal addresses, thus making dynamic binding of remote programs possible.

rpcbind is bound to a well-known address of each supported transport, and other programs register their dynamically allocated transport addresses with it. rpcbind then makes those addresses publicly available. Universal addresses are string representations of the transport-dependent address. They are defined by the addressing authority of the given transport.

rpcbind also aids in broadcast RPC. RPC programs have different addresses on different machines, so direct broadcasts to all these programs are not possible. rpcbind, however, has a well-known address. So, to broadcast to a given program, the client sends its message to the rpcbind process on the machine it chooses to reach. rpcbind picks up the broadcast and calls the local service specified by the client. When rpcbind gets a reply from the local service, it passes the reply on to the client.

The following code example shows the rpcbind Protocol Specification in RPC Language.

Example B-5 rpcbind Protocol Specification in RPC Language

 * rpcb_prot.x
 * RPCBIND protocol in rpc language
 * A mapping of (program, version, network ID) to universal
struct rpcb {
    rpcproc_t r_prog;           /* program number */
    rpcvers_t r_vers;           /* version number */
    string r_netid<>;               /* network id */
    string r_addr<>;                /* universal address */
    string r_owner<>;               /* owner of this service */ };
/* A list of mappings */
struct rpcblist {
    rpcb rpcb_map;
    struct rpcblist *rpcb_next;
/* Arguments of remote calls */
struct rpcb_rmtcallargs {
    rpcprog_t prog;             /* program number */
    rpcvers_t vers;             /* version number */
    rpcproc_t proc;             /* procedure number */
    opaque args<>;                  /* argument */
/* Results of the remote call */
struct rpcb_rmtcallres {
    string addr<>;                  /* remote universal address */
    opaque results<>;               /* result */
 * rpcb_entry contains a merged address of a service on a
 * transport, plus associated netconfig information. A list of
 * rpcb_entrys is returned by RPCBPROC_GETADDRLIST. See
 * for values used in r_nc_* fields.
struct rpcb_entry {
    string          r_maddr<>;      /* merged address of service */
    string          r_nc_netid<>;   /* netid field */
    unsigned int   r_nc_semantics; /* semantics of transport */
    string          r_nc_protofmly<>; /* protocol family */
    string          r_nc_proto<>;   /* protocol name */
/* A list of addresses supported by a service. */
struct rpcb_entry_list {
    rpcb_entry rpcb_entry_map;
    struct rpcb_entry_list *rpcb_entry_next;
typedef rpcb_entry_list *rpcb_entry_list_ptr;
/* rpcbind statistics */
const rpcb_highproc_2 = RPCBPROC_CALLIT;
const rpcb_highproc_3 = RPCBPROC_TADDR2UADDR;
const rpcb_highproc_4 = RPCBPROC_GETSTAT;
const RPCBSTAT_HIGHPROC = 13;  /* # of procs in rpcbind V4 plus
one */
const RPCBVERS_STAT = 3;  /* provide only for rpcbind V2, V3 and
V4 */
const RPCBVERS_4_STAT = 2;
const RPCBVERS_3_STAT = 1;
const RPCBVERS_2_STAT = 0;
/* Link list of all the stats about getport and getaddr */
struct rpcbs_addrlist {
    rpcprog_t prog;
    rpcvers_t vers;
    int success;
    int failure;
    string netid<>;
    struct rpcbs_addrlist *next;
/* Link list of all the stats about rmtcall */
struct rpcbs_rmtcalllist {
    rpcprog_t prog;
    rpcvers_t vers;
    rpcproc_t proc;
    int success;
    int failure;
    int indirect;   /* whether callit or indirect */
    string netid<>;
    struct rpcbs_rmtcalllist *next;
typedef int rpcbs_proc[RPCBSTAT_HIGHPROC];
typedef rpcbs_addrlist *rpcbs_addrlist_ptr;
typedef rpcbs_rmtcalllist *rpcbs_rmtcalllist_ptr;
struct rpcb_stat {
    rpcbs_proc              info;
    int                     setinfo;
    int                     unsetinfo;
    rpcbs_addrlist_ptr      addrinfo;
    rpcbs_rmtcalllist_ptr   rmtinfo;
 * One rpcb_stat structure is returned for each version of rpcbind
 * being monitored.
typedef rpcb_stat rpcb_stat_byvers[RPCBVERS_STAT];
/* rpcbind procedures */
program RPCBPROG {
    version RPCBVERS {
        RPCBPROC_NULL(void) = 0;
         * Registers the tuple [r_prog, r_vers, r_addr, r_owner,
         * r_netid]. The rpcbind server accepts requests for this
         * procedure on only the loopback transport for security
         * reasons. Returns TRUE if successful, FALSE on failure.
        RPCBPROC_SET(rpcb) = 1;
         * Unregisters the tuple [r_prog, r_vers, r_owner, r_netid].
         * If vers is zero, all versions are
unregistered. The rpcbind
         * server accepts requests for this procedure on only the
         * loopback transport for security reasons.  Returns TRUE if
         * successful, FALSE on failure.
        RPCBPROC_UNSET(rpcb) = 2;
         * Returns the universal address where the triple [r_prog,
         * r_vers, r_netid] is registered.  If r_addr specified,
         * return a universal address merged on r_addr. Ignores
         * r_owner. Returns FALSE on failure.
        RPCBPROC_GETADDR(rpcb) = 3;
        /* Returns a list of all mappings. */
        RPCBPROC_DUMP(void) = 4;
         * Calls the procedure on the remote machine.  If it is not
         * registered, this procedure IS quiet; that is, it DOES NOT
         * return error information.
        RPCBPROC_CALLIT(rpcb_rmtcallargs) = 5;
         * Returns the time on the rpcbind server's system.
        unsigned int
        RPCBPROC_GETTIME(void) = 6;
        struct netbuf
        RPCBPROC_UADDR2TADDR(string) = 7;

        RPCBPROC_TADDR2UADDR(struct netbuf) = 8;
        } = 3;
        version RPCBVERS4 {
        RPCBPROC_SET(rpcb) = 1;
        RPCBPROC_UNSET(rpcb) = 2;
        RPCBPROC_GETADDR(rpcb) = 3;
        RPCBPROC_DUMP(void) = 4;
         * NOTE: RPCBPROC_BCAST has the same functionality as CALLIT;
         * the new name is
intended to indicate that this procedure
         * should be used for broadcast RPC, and RPCBPROC_INDIRECT
         * should be used for indirect calls.
        RPCBPROC_BCAST(rpcb_rmtcallargs) = RPCBPROC_CALLIT;
        unsigned int
        RPCBPROC_GETTIME(void) = 6;
        struct netbuf
        RPCBPROC_UADDR2TADDR(string) = 7;

        RPCBPROC_TADDR2UADDR(struct netbuf) = 8;

         * Same as RPCBPROC_GETADDR except that if the given version
         * number is not available, the address is not returned.
        RPCBPROC_GETVERSADDR(rpcb) = 9;

         * Calls the procedure on the remote machine.  If it is not
         * registered, this procedure IS NOT quiet; that is, it DOES
         * return error information.
        RPCBPROC_INDIRECT(rpcb_rmtcallargs) = 10;
         * Same as RPCBPROC_GETADDR except that it returns a list of
         * addresses registered for the combination (prog, vers).
        RPCBPROC_GETADDRLIST(rpcb) = 11;
         * Returns statistics about the rpcbind server's activity.
        RPCBPROC_GETSTAT(void) = 12;
    } = 4;
} = 100000;

rpcbind Operation

rpcbind is contacted by way of an assigned address specific to the transport being used. For TCP/IP and UDP/IP, for example, it is port number 111. Each transport has such an assigned well-known address. This section describes a description of each of the procedures supported by rpcbind.


This procedure does no work. By convention, procedure zero of any program takes no parameters and returns no results.


When a program first becomes available on a machine, it registers itself with the rpcbind program running on the same machine. The program passes its program number prog, version number vers, network identifier netid, and the universal address uaddr; on which it awaits service requests.

The procedure returns a Boolean response with the value TRUE if the procedure successfully established the mapping and FALSE otherwise. The procedure refuses to establish a mapping if one already exists for the ordered set (prog, vers, netid).

Neither netid nor uaddr can be NULL, and that netid should be a valid network identifier on the machine making the call.


When a program becomes unavailable, it should unregister itself with the rpcbind program on the same machine.

The parameters and results have meanings identical to those of RPCBPROC_SET. The mapping of the (prog, vers, netid) tuple with uaddr is deleted.

If netid is NULL, all mappings specified by the ordered set (prog, vers, *) and the corresponding universal addresses are deleted. Only the owner of the service or the superuser is allowed to unset a service.


Given a program number prog, version number vers, and network identifier netid, this procedure returns the universal address on which the program is awaiting call requests.

The netid field of the argument is ignored and the netid is inferred from the netid of the transport on which the request came in.


This procedure lists all entries in rpcbind's database.

The procedure takes no parameters and returns a list of program, version, netid, and universal addresses. Call this procedure using a stream rather than a datagram transport to avoid the return of a large amount of data.


This procedure enables a caller to call another remote procedure on the same machine without knowing the remote procedure's universal address. RPCBPROC_CALLIT support broadcasts to arbitrary remote programs through rpcbind's universal address.

The parameters prog, vers, proc, and the args_ptr are the program number, version number, procedure number, and parameters of the remote procedure.

This procedure sends a response only if the procedure was successfully executed, and is silent (no response) otherwise.

The procedure returns the remote program's universal address, and the results of the remote procedure.


This procedure returns the local time on its own machine in seconds since midnight of January 1, 1970.


This procedure converts universal addresses to transport (netbuf) addresses. RPCBPROC_UADDR2TADDR is equivalent to uaddr2taddr(). See the netdir(3NSL) man page. Only processes that cannot link to the name-to-address library modules should use RPCBPROC_UADDR2TADDR.


This procedure converts transport (netbuf) addresses to universal addresses. RPCBPROC_TADDR2UADDR is equivalent to taddr2uaddr(). See the netdir(3NSL) man page. Only processes that cannot link to the name-to-address library modules should use RPCBPROC_TADDR2UADDR.

Version 4 rpcbind

Version 4 of the rpcbind protocol includes all of the previous procedures, and adds several others.


This procedure is identical to the version 3 RPCBPROC_CALLIT procedure. The new name indicates that the procedure should be used for broadcast RPCs only. RPCBPROC_INDIRECT, defined in the following text, should be used for indirect RPC calls.


This procedure is similar to RPCBPROC_GETADDR. The difference is that the r_vers field of the rpcb structure can be used to specify the version of interest. If that version is not registered, no address is returned.


This procedure is similar to RPCBPROC_CALLIT. Instead of being silent about errors, such as the program not being registered on the system, this procedure returns an indication of the error. Do not use this procedure for broadcast RPC. Use it with indirect RPC calls only.


This procedure returns a list of addresses for the given rpcb entry. The client might be able to use the results to determine alternate transports that it can use to communicate with the server.


This procedure returns statistics on the activity of the rpcbind server. The information lists the number and kind of requests the server has received.

All procedures except RPCBPROC_SET and RPCBPROC_UNSET can be called by clients running on a machine other than a machine on which rpcbind is running. rpcbind accepts only RPCPROC_SET and RPCPROC_UNSET requests on the loopback transport.