ONC+ Developer's Guide

Appendix B RPC Protocol and Language Specification

This appendix specifies a message protocol used in implementing the RPC package. The message protocol is specified with the XDR language. The companion appendix to this one is Appendix C, XDR Protocol Specification.

This appendix covers the following topics:

Protocol Overview

The RPC protocol provides for the following:

Consider a network file service composed of two programs. One program might handle high-level applications such as file-system access control and locking. The other might handle low-level file I/O and have procedures like read and write. A client machine of the network file service would call the procedures associated with the two programs of the service on behalf of some user on the client machine. In the client-server model, a remote procedure call is used to call the service.

RPC Model

The RPC model is similar to the local procedure call model. In the local case, the caller places arguments to a procedure in some well-specified location. The caller then transfers control to the procedure, and eventually regains control. At that point, the results of the procedure are extracted from a well-specified location, and the caller continues execution.

The RPC model is similar, in that one thread of control logically winds through two processes. One is the caller's process, the other is a server's process. Conceptually, the caller process sends a call message to the server process and waits for a reply message. The call message contains the procedure's parameters, among other information. The reply message contains the procedure's results, among other information. After the reply message is received, the results of the procedure are extracted, and the caller's execution is resumed.

On the server side, a process is dormant awaiting the arrival of a call message. When one arrives, the server process extracts the procedure's parameters, computes the results, sends a reply message, and then awaits the next call message.

Note that in this description only one of the two processes is active at any given time. However, the RPC protocol makes no restrictions on the concurrency model implemented. For example, an implementation might choose to have RPC calls be asynchronous, so that the client can do useful work while waiting for the reply from the server. Another possibility is to have the server create a task to process an incoming request so that the server is free to receive other requests.

Transports and Semantics

The RPC protocol is independent of transport protocols. That is, RPC disregards how a message is passed from one process to another. The protocol handles only specification and interpretation of messages.

RPC does not attempt to ensure transport reliability. Therefore, you must supply the application with information about the type of transport protocol used under RPC. If you tell the RPC service that it is running on top of a reliable transport such as TCP, most of the work is already done for the service. On the other hand, if RPC is running on top of an unreliable transport such as UDP, the service must devise its own retransmission and time-out policy. RPC does not provide this service.

Because of transport independence, the RPC protocol does not attach specific semantics to the remote procedures or their execution. Semantics can be inferred from, but should be explicitly specified by, the underlying transport protocol. For example, suppose RPC is running on top of an unreliable transport. If an application retransmits RPC messages after short timeouts receiving no reply, it can infer only that the procedure was executed zero or more times. If the application does receive a reply, it can infer that the procedure was executed at least once.

A server might choose to remember previously granted requests from a client and not regrant them to ensure some degree of execute-at-most-once semantics. A server can do this by using the transaction ID that is packaged with every RPC request. The main use of this transaction ID is by the RPC client for matching replies to requests. However, a client application can choose to reuse its previous transaction ID when retransmitting a request. The server application, checking this fact, can choose to remember this ID after granting a request and not regrant requests with the same ID. The server is not allowed to examine this ID in any other way except as a test for equality.

On the other hand, if using a reliable transport such as TCP, the application can infer from a reply message that the procedure was executed exactly once. If the application receives no reply message, it cannot assume the remote procedure was not executed. Note that even if a connection-oriented protocol like TCP is used, an application still needs timeouts and reconnection to handle server crashes.

Binding and Rendezvous Independence

The act of binding a client to a service is not part of the remote procedure call specification. This important and necessary function is left up to some higher-level software. The software can use RPC itself. See rpcbind Protocol.

Implementers should think of the RPC protocol as the jump-subroutine (JSR) instruction of a network. The loader makes JSR useful, and the loader itself uses JSR to accomplish its task. Likewise, the network makes RPC useful, enabling RPC to accomplish this task.

The RPC protocol provides the fields necessary for a client to identify itself to a service and the reverse. Security and access control mechanisms can be built on top of the message authentication. Several different authentication protocols can be supported. A field in the RPC header specifies the protocol being used. You can find more information on authentication protocols in the section Record-Marking Standard.

Program and Procedure Numbers

The RPC call message has three unsigned fields that uniquely identify the procedure to be called:

Program numbers are administered by a central authority, as described in Program Number Registration.

The first implementation of a program most likely has version number 1. Most new protocols evolve into better, stable, and mature protocols. Therefore, a version field of the call message identifies the version of the protocol that the caller is using. Version numbers make speaking old and new protocols through the same server process possible.

The procedure number identifies the procedure to be called. These numbers are documented in the individual program's protocol specification. For example, a file service's protocol specification might state that its procedure number 5 is read and procedure number 12 is write.

Just as remote program protocols can change over several versions, the RPC message protocol itself can change. Therefore, the call message also has in it the RPC version number, which is always equal to 2 for the version of RPC described here.

The reply message to a request message has enough information to distinguish the following error conditions:

Provisions for authentication of caller to service and the reverse are provided as a part of the RPC protocol. The call message has two authentication fields, the credentials and verifier. The reply message has one authentication field, the response verifier. The RPC protocol specification defines all three fields to be the following opaque type.

enum auth_flavor {
  	AUTH_NONE = 0,
  	AUTH_SYS = 1,
  	AUTH_SHORT = 2,
  	AUTH_DES = 3,
  	/* and more to be defined */
  struct opaque_auth {
   enum         auth_flavor;        /* style of credentials */
  	caddr_t      oa_base;          /* address of more auth stuff */
  	u_int        oa_length;        /* not to exceed MAX_AUTH_BYTES */

An opaque_auth structure is an auth_flavor enumeration followed by bytes that are opaque to the RPC protocol implementation.

The interpretation and semantics of the data contained within the authentication fields are specified by individual, independent authentication protocol specifications. See Record-Marking Standard for definitions of the various authentication protocols.

If authentication parameters are rejected, the response message contains information stating why they are rejected.

Program Number Assignment

Program numbers are distributed in groups of 0x20000000, as shown in the following table.

Table B–1 RPC Program Number Assignment

Program Numbers 


00000000 - 1fffffff 

Defined by host 

20000000 - 3fffffff 

Defined by user 

40000000 - 5fffffff

Transient (reserved for customer-written applications)

60000000 - 7fffffff 


80000000 - 9fffffff 


a0000000 - bfffffff 


c0000000 - dfffffff 


e0000000 - ffffffff 


Sun Microsystems administers the first group of numbers, which should be identical for all customers. If a customer develops an application that might be of general interest, that application should be given an assigned number in the first range.

The second group of numbers is reserved for specific customer applications. This range is intended primarily for debugging new programs.

The third group is reserved for applications that generate program numbers dynamically.

The final groups are reserved for future use, and should not be used.

Program Number Registration

To register a protocol specification, send a request by email to rpc@sun.com, or write to: RPC Administrator, Sun Microsystems, 4150 Network Circle, Santa Clara, CA 95054.

Include a compilable rpcgen .x file describing your protocol. You are given a unique program number in return.

You can find the RPC program numbers and protocol specifications of standard RPC services in the include files in /usr/include/rpcsvc. These services, however, constitute only a small subset of those that have been registered.

Other Uses of the RPC Protocol

The intended use of this protocol is for calling remote procedures. That is, each call message is matched with a response message. However, the protocol itself is a message-passing protocol with which other non-RPC protocols can be implemented. Some of the non-RPC protocols supported by the RPC package are batching and broadcasting.


Batching enables a client to send an arbitrarily large sequence of call messages to a server. Batching typically uses reliable byte-stream protocols like TCP for its transport. In batching, the client never waits for a reply from the server, and the server does not send replies to batch requests. A sequence of batch calls is usually finished by a non-batch RPC call to flush the pipeline with positive acknowledgement. For more information, see Batching.

Broadcast RPC

In broadcast RPC, the client sends a broadcast packet to the network and waits for numerous replies. Broadcast RPC uses connectionless, packet-based protocols like UDP as its transports. Servers that support broadcast protocols only respond when the request is successfully processed, and are silent in the face of errors. Broadcast RPC uses the rpcbind service to achieve its semantics. See Broadcast RPC and rpcbind Protocol for further information.

RPC Message Protocol

This section defines the RPC message protocol in the XDR data description language. The message is defined in a top-down style, as shown in the following code example.

Example B–1 RPC Message Protocol

enum msg_type {
 	CALL = 0,
 	REPLY = 1

 * A reply to a call message can take on two forms: The message was
 * either accepted or rejected.
 enum reply_stat {

 * Given that a call message was accepted, the following is the
 * status of an attempt to call a remote procedure.
enum accept_stat {
 	SUCCESS = 0,       /* RPC executed successfully */
 	PROG_UNAVAIL = 1,  /* remote service hasn't exported prog */
 	PROG_MISMATCH = 2, /* remote service can't support versn # */
 	PROC_UNAVAIL = 3,  /* program can't support proc */
 	GARBAGE_ARGS = 4   /* procedure can't decode params */

 * Reasons a call message was rejected:
enum reject_stat {
 	RPC_MISMATCH = 0,  /* RPC version number != 2 */
 	AUTH_ERROR = 1     /* remote can't authenticate caller */
 * Why authentication failed:
enum auth_stat {
 	AUTH_BADCRED = 1,       /* bad credentials */
 	AUTH_REJECTEDCRED = 2,  /* clnt must do new session */
 	AUTH_BADVERF = 3,       /* bad verifier */
 	AUTH_REJECTEDVERF = 4,  /* verif expired or replayed */
 	AUTH_TOOWEAK = 5        /* rejected for security */

 * The RPC message:
 * All messages start with a transaction identifier, xid, followed
 * by a two-armed discriminated union. The union's discriminant is
 * a msg_type which switches to one of the two types of the
 * message.
 * The xid of a REPLY message always matches that of the
 * initiating CALL message. NB: The xid field is only used for
 * clients matching reply messages with call messages or for servers
 * detecting retransmissions; the service side cannot treat this id as
 * any type of sequence number.
struct rpc_msg {
 	unsigned int xid;
 	union switch (msg_type mtype) {
 		case CALL:
 			call_body cbody;
 		case REPLY:
 			reply_body rbody;
 	} body;

 * Body of an RPC request call:
 * In version 2 of the RPC protocol specification, rpcvers must be
 * equal to 2. The fields prog, vers, and proc specify the remote
 * program, its version number, and the procedure within the
 * remote program to be called. After these fields are two 
 * authentication parameters: cred (authentication credentials) and 
 * verf (authentication verifier). The two authentication parameters
 * are followed by the parameters to the remote procedure, which are
 * specified by the specific program protocol.
struct call_body {
 	unsigned int rpcvers; /* must be equal to two (2) */
 	unsigned int prog;
 	unsigned int vers;
 	unsigned int proc;
 	opaque_auth cred;
 	opaque_auth verf;
 	/* procedure specific parameters start here */

 * Body of a reply to an RPC request:
 * The call message was either accepted or rejected.
union reply_body switch (reply_stat stat) {
 		accepted_reply areply;
 	case MSG_DENIED:
 		rejected_reply rreply;
} reply;

 * Reply to an RPC request that was accepted by the server: there
 * could be an error even though the request was accepted. The
 * first field is an authentication verifier that the server
 * generates in order to validate itself to the caller. It is 
 * followed by a union whose discriminant is an enum accept_stat.
 * The SUCCESS arm of the union is protocol specific. 
 * the union are void. The PROG_MISMATCH arm specifies the lowest
 * and highest version numbers of the remote program supported by
 * the server.
struct accepted_reply {
 	opaque_auth verf;
 	union switch (accept_stat stat) {
 		case SUCCESS:
 			opaque results[0];
 			/* procedure-specific results start here */
 			struct {
 				unsigned int low;
 				unsigned int high;
 			} mismatch_info;
 			 * Void. Cases include PROG_UNAVAIL, PROC_UNAVAIL, and
			    * GARBAGE_ARGS.
 	} reply_data;

 * Reply to an RPC request that was rejected by the server:
 * The request can be rejected for two reasons: either the server
 * is not running a compatible version of the RPC protocol
 * (RPC_MISMATCH), or the server refuses to authenticate the
 * caller AUTH_ERROR). In case of an RPC version mismatch,
 * the server returns the lowest and highest supported RPC
 * version numbers. In case of refused authentication, failure
 * status is returned.
union rejected_reply switch (reject_stat stat) {
 		struct {
 			unsigned int low;
 			unsigned int high;
 		} mismatch_info;
 	case AUTH_ERROR:
 		auth_stat stat;

Record-Marking Standard

When RPC messages are passed on top of a byte-stream transport like TCP, you should try to delimit one message from another to detect and possibly recover from user protocol errors. This is called record marking (RM). One RPC message fits into one RM record.

A record is composed of one or more record fragments. A record fragment is a 4-byte header followed by 0 to (2**31) - 1 bytes of fragment data. The bytes encode an unsigned binary number. As with XDR integers, the byte order is the network byte order.

The header encodes two values:

Authentication Protocols

Authentication parameters are opaque but open-ended to the rest of the RPC protocol. This section defines some flavors of authentication that have already been implemented. Other sites are free to invent new authentication types, with the same rules of flavor number assignment for program number assignment. Sun Microsystems maintains and administers a range of authentication flavors. To have authentication numbers like RPC program numbers allocated or registered to them, contact the Sun RPC Administrator.


Calls are often made in which the caller does not authenticate itself and the server disregards who the caller is. In these cases, the flavor value of the RPC message's credentials, verifier, and response verifier is AUTH_NONE. The flavor value is the “discriminant” of the opaque_auth “union.” The body length is zero when AUTH_NONE authentication flavor is used.


AUTH_SYS This is the same as the authentication flavor previously known as AUTH_UNIX. The caller of a remote procedure might wish to identify itself using traditional UNIX process permissions authentication. The flavor of the opaque_auth of such an RPC call message is AUTH_SYS. The bytes of the body encode the following structure:

struct auth_sysparms {
  	unsigned int stamp;
  	string machinename<255>;
  	uid_t uid;
  	gid_t gid;
  	gid_t gids<10>;

is an arbitrary ID that the caller machine can generate.


is the name of the caller's machine.


is the caller's effective user ID.


is the caller's effective group ID.


is a counted array of groups in which the caller is a member.

The flavor of the verifier accompanying the credentials should be AUTH_NONE.


When using AUTH_SYS authentication, the flavor of the response verifier received in the reply message from the server might be AUTH_NONE or AUTH_SHORT.

If AUTH_SHORT, the bytes of the response verifier's string encode a short_hand_verf structure. This opaque structure can now be passed to the server instead of the original AUTH_SYS credentials.

The server keeps a cache that maps the shorthand opaque structures to the original credentials of the caller. These structures are passed back by way of an AUTH_SHORT style response verifier. The caller can save network bandwidth and server CPU cycles by using the new credentials.

The server can flush the shorthand opaque structure at any time. If a flush occurs, the remote procedure call message is rejected because of an authentication error. The reason for the failure is AUTH_REJECTEDCRED. At this point, the caller might try the original AUTH_SYS style of credentials, as shown in the following figure.

Figure B–1 Authentication Process Map

Text describes graphic.

AUTH_DES Authentication

You might encounter the following situations with AUTH_SYS authentication:

AUTH_DES authentication attempts to fix these two problems.

The first issue is handled by addressing the caller by a simple string of characters instead of by an operating system-specific integer. This string of characters is known as the net name or network name of the caller. The server should not interpret the caller's name in any way other than as the identity of the caller. Thus, net names should be unique for every caller in the naming domain.

Each operating system's implementation of AUTH_DES authentication generates net names for its users that ensure this uniqueness when they call remote servers. Operating systems already distinguish users local to their systems. Extending this mechanism to the network is usually a simple matter.

For example, a user with a user ID of 515 might be assigned the following net name: UNIX.515@sun.com. This net name contains three items that serve to ensure it is unique. Backtracking, only one naming domain is called sun.com in the Internet. Within this domain, only one UNIX user has the user ID 515. However, there might be another user on another operating system, for example VMS, within the same naming domain who, by coincidence, happens to have the same user ID. To ensure that these two users can be distinguished, you add the operating system name. So one user is UNIX.515@sun.com and the other is VMS.515@sun.com.

The first field is actually a naming method rather than an operating system name. It just happens that almost a one-to-one correspondence exists between naming methods and operating systems. If there was a common worldwide naming standard, the first field could be a name from that standard, instead of an operating system name.

AUTH_DES Authentication Verifiers

Unlike AUTH_SYS authentication, AUTH_DES authentication does have a verifier so the server can validate the client's credential, and the reverse. The contents of this verifier are primarily an encrypted timestamp. The server can decrypt this timestamp, and if it is close to its current real time, then the client must have encrypted it correctly. The only way the client could encrypt the timestamp correctly is to know the conversation key of the RPC session. If the client knows the conversation key, it must be the real client.

The conversation key is a DES [5] key that the client generates and notifies the server of in its first RPC call. The conversation key is encrypted using a public-key scheme in this first transaction. The particular public-key scheme used in AUTH_DES authentication is Diffie-Hellman [3] with 192-bit keys. The details of this encryption method are described in Diffie-Hellman Encryption.

The client and the server need the same notion of the current time for the verification to work. If network time synchronization cannot be guaranteed, then the client can synchronize with the server before beginning the conversation. rpcbind provides a procedure, RPCBPROC_GETTIME, which can be used to obtain the current time.

A server can determine if a client timestamp is valid. For any transaction after the first, the server checks for two things:

For the first transaction, the server checks that the timestamp has not expired. As an added check, the client sends an encrypted item in the first transaction known as the window verifier. This verifier must be equal to the window minus 1, or the server rejects the credential.

The client must check the verifier returned from the server to be sure it is legitimate. The server sends back to the client the encrypted timestamp it received from the client, minus one second. If the client gets any result other than this one, the verifier is rejected.

Nicknames and Clock Synchronization

After the first transaction, the server's AUTH_DES authentication subsystem returns in its verifier to the client an integer nickname. The client can use this nickname in its further transactions instead of passing its net name, encrypted DES key, and window every time. The nickname is most likely an index into a table on the server that stores for each client its net name, decrypted DES key, and window. It should however be treated as opaque data by the client.

Though originally synchronized, client and server clocks can get out of sync. If this situation occurs, the client RPC subsystem most likely receives an RPC_AUTHERROR at which point it should resynchronize.

A client can still get the RPC_AUTHERROR error even though it is synchronized with the server. The server's nickname table is a limited size, and it can flush entries as needed. The client should resend its original credential and the server gives the client a new nickname. If a server crashes, the entire nickname table is flushed, and all clients have to resend their original credentials.

DES Authentication Protocol (in XDR language)

Credentials are explained in the following example:

Example B–2 AUTH_DES Authentication Protocol

 * There are two kinds of credentials: one in which the client
 * uses its full network name, and one in which it uses its
 * “nickname” (just an unsigned integer) given to it by the
 * server. The client must use its full name in its first
 * transaction with the server, in which the server returns
 * to the client its nickname. The client may use its nickname
 * in all further transactions with the server. There is no
 * requirement to use the nickname, but it is wise to use it for
 * performance reasons.
enum authdes_namekind {
 * A 64-bit block of encrypted DES data
 typedef opaque des_block[8];
 * Maximum length of a network user's name
const MAXNETNAMELEN = 255;
 * A fullname contains the network name of the client, an
 * encrypted conversation key and the window. The window
 * is actually a lifetime for the credential. If the time
 * indicated in the verifier timestamp plus the window has
 * passed, then the server should expire the request and 
 * not grant it. To insure that requests are not replayed,
 * the server should insist that timestamps be greater
 * than the previous one seen, unless it is the first transaction.
 * In the first transaction, the server checks instead that the
 * window verifier is one less than the window.
struct authdes_fullname {
 	string name<MAXNETNAMELEN>; /* name of client */
 	des_block key;              /* PK encrypted conversation key */
 	unsigned int window;        /* encrypted window */
};                             /* NOTE: PK means "public key" */
 * A credential is either a fullname or a nickname
 		authdes_fullname adc_fullname;
 		unsigned int adc_nickname;
 * A timestamp encodes the time since midnight, January 1, 1970.
struct timestamp {
 	unsigned int seconds;      /* seconds */
 	unsigned int useconds;     /* and microseconds */
 * Verifier: client variety
struct authdes_verf_clnt {
 	timestamp adv_timestamp;   /* encrypted timestamp */
 	unsigned int adv_winverf;  /* encrypted window verifier */
 * Verifier: server variety
 * The server returns (encrypted) the same timestamp the client gave
 * it minus one second. It also tells the client its nickname to be
 * used in future transactions (unencrypted).
struct authdes_verf_svr {
 	timestamp adv_timeverf;    /* encrypted verifier */
 	unsigned int adv_nickname; /* new nickname for clnt */};

Diffie-Hellman Encryption

In this scheme are two constants, PROOT and HEXMODULUS. The particular values chosen for these constants for the DES authentication protocol are:

const PROOT = 3;
const HEXMODULUS =	/* hex */

The way this scheme works is best explained by an example. Suppose there are two people, A and B, who want to send encrypted messages to each other. A and B each generate a random secret key that they do not disclose to anyone. Let these keys be represented as SK(A) and SK(B). They also publish in a public directory their public keys. These keys are computed as follows:


The ** notation is used here to represent exponentiation.

Now, both A and B can arrive at the common key between them, represented here as CK(A,B), without disclosing their secret keys.

A computes:

CK(A, B) = (PK(B) ** SK(A)) mod HEXMODULUS

while B computes:

CK(A, B) = (PK(A) ** SK(B)) mod HEXMODULUS

These two computations can be shown to be equivalent: (PK(B)**SK(A)) mod HEXMODULUS = (PK(A)**SK(B)) mod HEXMODULUS. Drop the mod HEXMODULUS parts and assume modulo arithmetic to simplify the process:

PK(B) ** SK(A) = PK(A) ** SK(B)

Then replace PK(B) by what B computed earlier and likewise for PK(A).

((PROOT ** SK(B)) ** SK(A) = (PROOT ** SK(A)) ** SK(B)

which leads to:

PROOT ** (SK(A) * SK(B)) = PROOT ** (SK(A) * SK(B))

This common key CK(A,B) is not used to encrypt the timestamps used in the protocol. It is used only to encrypt a conversation key that is then used to encrypt the timestamps. This approach uses the common key as little as possible, to prevent a break. Breaking the conversation key is a far less serious compromise, because conversations are comparatively short lived.

The conversation key is encrypted using 56-bit DES keys, yet the common key is 192 bits. To reduce the number of bits, 56 bits are selected from the common key as follows. The middle-most 8 bytes are selected from the common key, and then parity is added to the lower-order bit of each byte, producing a 56-bit key with 8 bits of parity.

AUTH_KERB Authentication

To avoid compiling Kerberos code into the operating system kernel, the kernel used in the S implementation of AUTH_KERB uses a proxy RPC daemon called kerbd. The daemon exports three procedures.

The best way to describe how Kerberos works is to use an example based on a service currently implementing Kerberos: the network file system (NFS). The NFS service on server s is assumed to have the well-known principal name nfs.s. A privileged user on client c is assumed to have the primary name root and an instance c. Note that, unlike AUTH_DES, when the user's ticket-granting ticket has expired, kinit() must be reinvoked. NFS service for Kerberos mounts fail until a new ticket-granting ticket is obtained.

NFS Mount Example

This section follows an NFS mount request from start to finish using AUTH_KERB. Because mount requests are executed as root, the user's identity is root.c.

Client c makes a MOUNTPROC_MOUNT request to the server s to obtain the file handle for the directory to be mounted. The client mount program makes an NFS mount system call, handing the client kernel the file handle, mount flavor, time synchronization address, and the server's well-known name, nfs.s. Next the client kernel contacts the server at the time synchronization host to obtain the client-server time bias.

The client kernel makes the following RPC calls.

  1. KSETKCRED to the local kerbd to obtain the ticket and session key,

  2. NFSPROC_GETATTR to the server's NFS service, using the full name credential and verifier. The server receives the calls and makes the KGETKCRED call to its local kerbd to check the client's ticket.

The server's kerbd and the Kerberos library decrypt the ticket and return, among other data, the principal name and DES session key. The server checks that the ticket is still valid, uses the session key to decrypt the DES-encrypted portions of the credential and verifier, and checks that the verifier is valid.

The possible Kerberos authentication errors returned at this time are:

If no errors are received, the server caches the client's identity and allocates a nickname, which is a small integer, to be returned in the NFS reply. The server then checks if the client is in the same realm as the server. If so, the server calls KGETUCRED to its local kerbd to translate the principal's primary name into UNIX credentials. If the previous name is not translatable, the user is marked anonymous. The server checks these credentials against the file system's export information. Consider these three cases:

  1. If the KGETUCRED call fails and anonymous requests are allowed, the UNIX credentials of the anonymous user are assigned.

  2. If the KGETUCRED call fails and anonymous requests are not allowed, the NFS call fails with the AUTH_TOOWEAK.

  3. If the KGETUCRED call succeeds, the credentials are assigned, and normal protection checking follows, including checking for root permission.

Next, the server sends an NFS reply, including the nickname and server's verifier. The client receives the reply, decrypts and validates the verifier, and stores the nickname for future calls. The client makes a second NFS call to the server, and the calls to the server described previously are repeated. The client kernel makes an NFSPROC_STATVFS call to the server's NFS service, using the nickname credential and verifier described previously. The server receives the call and validates the nickname. If it is out of range, the error AUTH_BADCRED is returned. The server uses the session key just obtained to decrypt the DES-encrypted portions of the verifier and validates the verifier.

The possible Kerberos authentication errors returned at this time are:

If no errors are received, the server uses the nickname to retrieve the caller's UNIX credentials. Then it checks these credentials against the file system's export information, and sends an NFS reply that includes the nickname and the server's verifier. The client receives the reply, decrypts and validates the verifier, and stores the nickname for future calls. Last, the client's NFS mount system call returns, and the request is finished.

KERB Authentication Protocol

The following example of AUTH_KERB has many similarities to the one for AUTH_DES, shown in the following code example. Note the differences.

Example B–3 AUTH_KERB Authentication Protocol

#define AUTH_KERB 4
 * There are two kinds of credentials: one in which the client
 * sends the (previously encrypted)
Kerberos ticket, and one in
 * which it uses its “nickname” (just an unsigned integer) 
 * given to it by the server. The client must use its full name
 * in its first transaction with the server, in which the server
 * returns to the client its nickname. The client may use
 * its nickname in all further transactions with the server
 * (until the ticket expires). There is no requirement to use
 * the nickname, but it is wise to use it for performance reasons.
enum authkerb_namekind {
 * A fullname contains the encrypted service ticket and the
 * window. 	The window is actually a lifetime
 * for the credential. If the time indicated in the verifier
 * timestamp plus the window has passed, then the server should
 * expire the request and not grant it. To insure that requests
 * are not replayed, the server should insist that timestamps be
 * greater than the previous one seen, unless it is the first
 * transaction. In the first transaction, the server checks
 * instead that the window verifier is one less than the window.
struct authkerb_fullname {
 	KTEXT_ST ticket;              /* Kerberos service ticket */
 	unsigned long window;        /* encrypted window */
 * A credential is either a fullname or a nickname
union authkerb_credswitch(authkerb_namekind akc_namekind){
 		authkerb_fullname akc_fullname;
 		unsigned long akc_nickname;
 * A timestamp encodes the time since midnight, January 1, 1970.
struct timestamp {
 	unsigned long seconds;      /* seconds */
 	unsigned long useconds;     /* and microseconds */
 * Verifier: client variety
struct authkerb_verf_clnt {
 	timestamp akv_timestamp;   /* encrypted timestamp */
 	unsigned long akv_winverf;  /* encrypted window verifier */
 * Verifier: server variety
 * The server returns (encrypted) the same timestamp the client
 * gave it minus one second. It also tells the client its
 * nickname to be used
in future transactions (unencrypted).
struct authkerb_verf_svr {
 	timestamp akv_timeverf;    /* encrypted verifier */
 	unsigned long akv_nickname; /* new nickname for clnt */

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 {
 		PINGPROC_NULL(void) = 0;
		 * ping the caller, return the round-trip time
		 * in milliseconds. Return a minus one (-1) if
 		 * operation times-out
 		/* 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.
		/* 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
		struct netbuf

		RPCBPROC_TADDR2UADDR(struct netbuf) = 8;
		} = 3;
		version RPCBVERS4 {
		RPCBPROC_SET(rpcb) = 1;
		RPCBPROC_UNSET(rpcb) = 2;
		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.
		unsigned int
		struct netbuf

		RPCBPROC_TADDR2UADDR(struct netbuf) = 8;

		 * Same as RPCBPROC_GETADDR except that if the given version
		 * number is not available, the address is not returned.

		 * 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).
		 * 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.