2 .\" Copyright (C) 2009, Sun Microsystems, Inc. All Rights Reserved
3 .\" Copyright 1989 AT&T
4 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License. You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.
5 .\" See the License for the specific language governing permissions and limitations under the License. When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the
6 .\" fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
7 .TH RPCGEN 1 "Dec 16, 2013"
9 rpcgen \- an RPC protocol compiler
13 \fBrpcgen\fR \fIinfile\fR
18 \fBrpcgen\fR [\fB-a\fR] [\fB-A\fR] [\fB-b\fR] [\fB-C\fR] [\fB-D\fR \fIname\fR [= \fIvalue\fR]] [\fB-i\fR \fIsize\fR]
19 [\fB-I\fR [\fB-K\fR \fIseconds\fR]] [\fB-L\fR] [\fB-M\fR] [\fB-N\fR] [\fB- T\fR] [\fB-v\fR]
20 [\fB-Y\fR \fIpathname\fR] \fIinfile\fR
25 \fBrpcgen\fR [\fB-c\fR | \fB-h\fR | \fB-l\fR | \fB-m\fR | \fB-t\fR | \fB-Sc\fR | \fB-Ss\fR | \fB-Sm\fR]
26 [\fB-o\fR \fIoutfile\fR] [\fIinfile\fR]
31 \fBrpcgen\fR [\fB-s\fR \fInettype\fR] [\fB-o\fR \fIoutfile\fR] [\fIinfile\fR]
36 \fBrpcgen\fR [\fB-n\fR \fInetid\fR] [\fB-o\fR \fIoutfile\fR] [\fIinfile\fR]
42 The \fBrpcgen\fR utility is a tool that generates C code to implement an
43 \fBRPC\fR protocol. The input to \fBrpcgen\fR is a language similar to C known
44 as \fBRPC\fR Language (Remote Procedure Call Language).
47 The \fBrpcgen\fR utility is normally used as in the first synopsis where it
48 takes an input file and generates four output files. If the \fIinfile\fR is
49 named \fBproto.x\fR, then \fBrpcgen\fR generates a header in \fBproto.h\fR,
50 \fBXDR\fR routines in \fBproto_xdr.c\fR, server-side stubs in
51 \fBproto_svc.c\fR, and client-side stubs in \fBproto_clnt.c\fR. With the
52 \fB-T\fR option, it also generates the \fBRPC\fR dispatch table in
56 \fBrpcgen\fR can also generate sample client and server files that can be
57 customized to suit a particular application. The \fB-Sc\fR, \fB-Ss\fR, and
58 \fB-Sm\fR options generate sample client, server and makefile, respectively.
59 The \fB-a\fR option generates all files, including sample files. If the infile
60 is \fBproto.x\fR, then the client side sample file is written to
61 \fBproto_client.c\fR, the server side sample file to \fBproto_server.c\fR and
62 the sample makefile to \fBmakefile.proto\fR.
65 The server created can be started both by the port monitors (for example,
66 \fBinetd\fR or \fBlisten\fR) or by itself. When it is started by a port
67 monitor, it creates servers only for the transport for which the file
68 descriptor \fB0\fR was passed. The name of the transport must be specified by
69 setting up the environment variable \fBPM_TRANSPORT\fR. When the server
70 generated by \fBrpcgen\fR is executed, it creates server handles for all the
71 transports specified in the \fBNETPATH\fR environment variable, or if it is
72 unset, it creates server handles for all the visible transports from the
73 \fB/etc/netconfig\fR file. Note: the transports are chosen at run time and not
74 at compile time. When the server is self-started, it backgrounds itself by
75 default. A special define symbol \fBRPC_SVC_FG\fR can be used to run the server
76 process in foreground.
79 The second synopsis provides special features which allow for the creation of
80 more sophisticated \fBRPC\fR servers. These features include support for
81 user-provided \fB#defines\fR and \fBRPC\fR dispatch tables. The entries in the
82 \fBRPC\fR dispatch table contain:
87 pointers to the service routine corresponding to that procedure
93 a pointer to the input and output arguments
99 the size of these routines
103 A server can use the dispatch table to check authorization and then to execute
104 the service routine. A client library can use the dispatch table to deal with
105 the details of storage management and \fBXDR\fR data conversion.
108 The other three synopses shown above are used when one does not want to
109 generate all the output files, but only a particular one. See the EXAMPLES
110 section below for examples of \fBrpcgen\fR usage. When \fBrpcgen\fR is executed
111 with the \fB-s\fR option, it creates servers for that particular class of
112 transports. When executed with the \fB-n\fR option, it creates a server for the
113 transport specified by \fInetid\fR. If \fIinfile\fR is not specified,
114 \fBrpcgen\fR accepts the standard input.
117 All the options mentioned in the second synopsis can be used with the other
118 three synopses, but the changes are made only to the specified output file.
121 The C preprocessor \fBcc\fR \fB-E\fR is run on the input file before it is
122 actually interpreted by \fBrpcgen\fR. For each type of output file,
123 \fBrpcgen\fR defines a special preprocessor symbol for use by the \fBrpcgen\fR
131 defined when compiling into headers
140 defined when compiling into \fBXDR\fR routines
149 defined when compiling into server-side stubs
158 defined when compiling into client-side stubs
167 defined when compiling into \fBRPC\fR dispatch tables
172 Any line beginning with ``\fB%\fR'' is passed directly into the output file,
173 uninterpreted by \fBrpcgen\fR, except that the leading ``\fB%\fR" is stripped
174 off. To specify the path name of the C preprocessor, use the \fB-Y\fR flag.
177 For every data type referred to in \fIinfile\fR, \fBrpcgen\fR assumes that
178 there exists a routine with the string \fBxdr_\fR prepended to the name of the
179 data type. If this routine does not exist in the \fBRPC\fR/\fBXDR\fR library,
180 it must be provided. Providing an undefined data type allows customization of
182 .SS "Server Error Reporting"
185 By default, errors detected by \fBproto_svc.c\fR is reported to standard error
186 and/or the system log.
189 This behavior can be overridden by compiling the file with a definition of
190 \fBRPC_MSGOUT\fR, for example, \fB-DRPC_MSGOUT=mymsgfunc\fR. The function
191 specified is called to report errors. It must conform to the following
192 \fBprintf\fR-like signature:
196 extern void RPC_MSGOUT(const char *fmt, ...);
204 The following options are supported:
211 Generates all files, including sample files.
220 Enables the Automatic \fBMT\fR mode in the server main program. In this mode,
221 the \fBRPC\fR library automatically creates threads to service client requests.
222 This option generates multithread-safe stubs by implicitly turning on the
223 \fB-M\fR option. Server multithreading modes and parameters can be set using
224 the \fBrpc_control\fR(3NSL) call. \fBrpcgen\fR generated code does not change
225 the default values for the Automatic \fBMT\fR mode.
234 Backward compatibility mode. Generates transport-specific \fBRPC\fR code for
235 older versions of the operating system.
244 Compiles into \fBXDR\fR routines.
253 Generates header and stub files which can be used with ANSI C compilers.
254 Headers generated with this flag can also be used with C++ programs.
260 \fB\fB-D\fR\fIname\fR\fB[=\fR\fIvalue\fR\fB]\fR\fR
263 Defines a symbol \fIname\fR. Equivalent to the \fB#define\fR directive in the
264 source. If no \fIvalue\fR is given, \fIvalue\fR is defined as \fB1\fR. This
265 option can be specified more than once.
274 Compiles into \fBC\fR data-definitions (a header). The \fB-T\fR option can be
275 used in conjunction to produce a header which supports \fBRPC\fR dispatch
282 \fB\fB-i\fR \fIsize\fR\fR
285 Size at which to start generating inline code. This option is useful for
286 optimization. The default \fIsize\fR is 5.
295 Compiles support for \fBinetd\fR(1M) in the server side stubs. Such servers can
296 be self-started or can be started by \fBinetd\fR. When the server is
297 self-started, it backgrounds itself by default. A special define symbol
298 \fBRPC_SVC_FG\fR can be used to run the server process in foreground, or the
299 user can simply compile without the \fB-I\fR option.
301 If there are no pending client requests, the \fBinetd\fR servers exit after 120
302 seconds (default). The default can be changed with the \fB-K\fR option. All of
303 the error messages for \fBinetd\fR servers are always logged with
306 \fBNote:\fR This option is supported for backward compatibility only. It should
307 always be used in conjunction with the \fB-b\fR option which generates backward
308 compatibility code. By default (that is, when \fB-b\fR is not specified),
309 \fBrpcgen\fR generates servers that can be invoked through portmonitors.
315 \fB\fB-K\fR \fIseconds\fR\fR
318 By default, services created using \fBrpcgen\fR and invoked through port
319 monitors wait 120 seconds after servicing a request before exiting. That
320 interval can be changed using the \fB-K\fR flag. To create a server that exits
321 immediately upon servicing a request, use \fB-K\fR \fB0\fR. To create a server
322 that never exits, the appropriate argument is \fB-K\fR \fB\(mi1\fR\&.
324 When monitoring for a server, some portmonitors, like \fBlisten\fR(1M),
325 \fBalways\fR spawn a new process in response to a service request. If it is
326 known that a server are used with such a monitor, the server should exit
327 immediately on completion. For such servers, \fBrpcgen\fR should be used with
337 Compiles into client-side stubs.
346 When the servers are started in foreground, uses \fBsyslog\fR(3C) to log the
347 server errors instead of printing them on the standard error.
356 Compiles into server-side stubs, but do not generate a "main" routine. This
357 option is useful for doing callback-routines and for users who need to write
358 their own "main" routine to do initialization.
367 Generates multithread-safe stubs for passing arguments and results between
368 \fBrpcgen\fR-generated code and user written code. This option is useful for
369 users who want to use threads in their code.
378 This option allows procedures to have multiple arguments. It also uses the
379 style of parameter passing that closely resembles C. So, when passing an
380 argument to a remote procedure, you do not have to pass a pointer to the
381 argument, but can pass the argument itself. This behavior is different from the
382 old style of \fBrpcgen\fR-generated code. To maintain backward compatibility,
383 this option is not the default.
389 \fB\fB-n\fR \fInetid\fR\fR
392 Compiles into server-side stubs for the transport specified by \fInetid\fR.
393 There should be an entry for \fInetid\fR in the \fBnetconfig\fR database. This
394 option can be specified more than once, so as to compile a server that serves
401 \fB\fB-o\fR \fIoutfile\fR\fR
404 Specifies the name of the output file. If none is specified, standard output is
405 used (\fB-c\fR, \fB-h\fR, \fB-l\fR, \fB-m\fR, \fB-n\fR, \fB-s\fR, \fB-Sc\fR,
406 \fB-Sm\fR, \fB-Ss\fR, and \fB-t\fR modes only).
412 \fB\fB-s\fR \fInettype\fR\fR
415 Compiles into server-side stubs for all the transports belonging to the class
416 \fInettype\fR. The supported classes are \fBnetpath\fR, \fBvisible\fR,
417 \fBcircuit_n\fR, \fBcircuit_v\fR, \fBdatagram_n\fR, \fBdatagram_v\fR,
418 \fBtcp\fR, and \fBudp\fR (see \fBrpc\fR(3NSL) for the meanings associated with
419 these classes). This option can be specified more than once. \fBNote:\fR The
420 transports are chosen at run time and not at compile time.
429 Generates sample client code that uses remote procedure calls.
438 Generates a sample Makefile which can be used for compiling the application.
447 Generates sample server code that uses remote procedure calls.
456 Compiles into \fBRPC\fR dispatch table.
465 Generates the code to support \fBRPC\fR dispatch tables.
467 The options \fB-c\fR, \fB-h\fR, \fB-l\fR, \fB-m\fR, \fB-s\fR, \fB-Sc\fR,
468 \fB-Sm\fR, \fB-Ss\fR, and \fB-t\fR are used exclusively to generate a
469 particular type of file, while the options \fB-D\fR and \fB-T\fR are global and
470 can be used with the other options.
479 Displays the version number.
485 \fB\fB-Y\fR \fIpathname\fR\fR
488 Gives the name of the directory where \fBrpcgen\fR starts looking for the C
495 The following operand is supported:
507 \fBExample 1 \fRGenerating the output files and dispatch table
515 example% \fBrpcgen -T prot.x\fR
522 generates all the five files: \fBprot.h\fR, \fBprot_clnt.c\fR,
523 \fBprot_svc.c\fR, \fBprot_xdr.c\fR, and \fBprot_tbl.i\fR.
526 \fBExample 2 \fRSending headers to standard output
529 The following example sends the C data-definitions (header) to the standard
535 example% \fBrpcgen -h prot.x\fR
541 \fBExample 3 \fRSending a test version
544 To send the test version of the \fB-DTEST\fR, server side stubs for all the
545 transport belonging to the class \fBdatagram_n\fR to standard output, use:
550 example% \fBrpcgen -s datagram_n -DTEST prot.x\fR
556 \fBExample 4 \fRCreating server side stubs
559 To create the server side stubs for the transport indicated by \fInetid\fR
565 example% \fBrpcgen -n tcp -o prot_svc.c prot.x\fR
577 Successful operation.
592 \fBinetd\fR(1M), \fBlisten\fR(1M), \fBrpc\fR(3NSL), \fBrpc_control\fR(3NSL),
593 \fBrpc_svc_calls\fR(3NSL), \fBsyslog\fR(3C), \fBnetconfig\fR(4),
597 The \fBrpcgen\fR chapter in the \fIONC+ Developer\&'s Guide\fR manual.