rpcgen

an RPC protocol compiler

Syntax:

rpcgen infile

rpcgen -a|-c|-h|-l|-m|-Sc|-Ss [-o outfile] [infile]
       [-C] [-D macro[=value]] [-L] [-K secs]

rpcgen -s transport [-o outfile] [infile]


Options:

-a
Generate all the files including sample code.
-C
Generate ANSI C code.
-c
Compile into XDR routines.
-D macro[=value]
Define a macro. If no value is given, value will default to 1.
-h
Compile into C data definitions (a header file).
-K secs
Idle timeout. Terminate after secs seconds of idleness. The default is 120 seconds. -K 0 means exit immediately upon servicing a request (useful if the server is started by inetd). -K -1 disables idle timer.
-L
Use syslog() for error reporting.
-l
(``el'') Compile into client-side stubs.
-m
Compile into server-side stubs, but don't generate a main routine. You should find this useful for doing callback routines or for when you need to write your own main routine to do initialization.
-o outfile
Use this output file. If you don't specify a file, rpcgen uses the standard output (-c, -h, -l, -m, -Sc, -Ss, and -s modes only).
-s transport
Compile into server-side stubs, using this transport. The compiler supports the transports udp and tcp (default is udp). You can invoke this option more than once to compile a server that serves multiple transports.
-Sc
Generate client side sample code.
-Ss
Generate server side sample code.
infile
Use this input file. If you don't specify an input file in the -c, -h, -l, -m, and -s modes, rpcgen uses the standard input.

Description:

The rpcgen compiler generates C code to implement an RPC protocol. The input rpcgen takes is a C-like language known as Remote Procedure Call Language. For more information about this language, we recommend Power Programming with RPC.

You normally use rpcgen in its first form, where it takes an input file and generates four output files. For example, if you specify an infile called proto.x, then rpcgen will generate:

You use the other syntax forms when you want to generate only one of these output files.

The C compiler is used to preprocess all input files before they're actually interpreted by rpcgen, so all the preprocessor directives are legal within an rpcgen input file. For each type of output file, rpcgen defines a special symbol for your use:

rpcgen defines this symbol: When compiling into:
RPC_HDR Header files
RPC_XDR XDR routines
RPC_SVC Server-side stubs
RPC_CLNT Client-side stubs

In addition, rpcgen does some preprocessing of its own. It will leave any line beginning with a % uninterpreted and pass the line directly into the output file.

You can customize some of your XDR routines by leaving associated data types undefined. For every data type you leave undefined, rpcgen assumes a routine exists whose name starts with xdr_ and ends with the name of the undefined type.

Caveats:

The compiler doesn't support nesting. You can achieve the same effect, however, by declaring structures at top level and using their names inside other structures.

When you use program definitions, name clashes can occur since the apparent scoping doesn't really apply. You can avoid most of these clashes by assigning unique names to programs, versions, procedures, and types.

See also:

John Bloomer, Power Programming with RPC, O'Reilly & Associates (ISBN 0-937175-77-3)