xref: /netbsd-src/usr.bin/rpcgen/rpcgen.1 (revision e5548b402ae4c44fb816de42c7bba9581ce23ef5)
1.\"	$NetBSD: rpcgen.1,v 1.19 2004/05/12 18:49:30 wiz Exp $
2.\" from: @(#)rpcgen.new.1	1.1 90/11/09 TIRPC 1.0; from 40.10 of 10/10/89
3.\" Copyright (c) 1988,1990 Sun Microsystems, Inc. - All Rights Reserved.
4.Dd May 12, 2004
5.Dt RPCGEN 1
6.Sh NAME
7.Nm rpcgen
8.Nd Remote Procedure Call (RPC) protocol compiler
9.Sh SYNOPSIS
10.Nm
11.Ar infile
12.Nm
13.Op Fl A
14.Op Fl a
15.Op Fl b
16.Op Fl C
17.Op Fl D Ar name Op =value
18.Op Fl I
19.Op Fl i Ar size
20.Op Fl K Ar secs
21.Op Fl L
22.Op Fl M
23.Op Fl N
24.Op Fl T
25.Op Fl v
26.Op Fl Y Ar pathname
27.Ar infile
28.Nm
29.Fl c Li |
30.Fl h Li |
31.Fl l Li |
32.Fl m Li |
33.Fl t Li |
34.Fl S\&c Li |
35.Fl S\&s
36.\" .Fl S\&m
37.Op Fl o Ar outfile
38.Op Ar infile
39.Nm
40.Op Fl s Ar nettype
41.Op Fl o Ar outfile
42.Op Ar infile
43.Nm
44.Op Fl n Ar netid
45.Op Fl o Ar outfile
46.Op Ar infile
47.Sh DESCRIPTION
48.Nm
49is a tool that generates C code to implement an
50.Tn RPC
51protocol.
52The input to
53.Nm
54is a language similar to C known as
55.Tn RPC
56Language (Remote Procedure Call Language).
57.Nm
58is normally used as in the first synopsis where
59it takes an input file and generates up to four output files.
60If the
61.Ar infile
62is named
63.Pa proto.x ,
64then
65.Nm
66will generate a header file in
67.Pa proto.h ,
68.Tn XDR
69routines in
70.Pa proto_xdr.c ,
71server-side stubs in
72.Pa proto_svc.c ,
73and client-side stubs in
74.Pa proto_clnt.c .
75With the
76.Fl T
77option,
78it will also generate the
79.Tn RPC
80dispatch table in
81.Pa proto_tbl.i .
82With the
83.Fl S\&c
84option,
85it will also generate sample code which would illustrate how to use the
86remote procedures on the client side.
87This code would be created in
88.Pa proto_client.c .
89With the
90.Fl S\&s
91option,
92it will also generate a sample server code which would illustrate how to write
93the remote procedures.
94This code would be created in
95.Pa proto_server.c .
96.Pp
97The server created can be started both by the port monitors
98(for example,
99.Em inetd
100or
101.Em listen )
102or by itself.
103When it is started by a port monitor,
104it creates servers only for the transport for which
105the file descriptor 0 was passed.
106The name of the transport must be specified
107by setting up the environmental variable
108.Ev PM_TRANSPORT .
109When the server generated by
110.Nm
111is executed,
112it creates server handles for all the transports
113specified in
114.Ev NETPATH
115environment variable,
116or if it is unset,
117it creates server handles for all the visible transports from
118.Pa /etc/netconfig
119file.
120.Pp
121.Em Note :
122the transports are chosen at run time and not at compile time.
123When the server is self-started,
124it backgrounds itself by default.
125A special define symbol
126.Dv RPC_SVC_FG
127can be used to run the server process in foreground.
128.P
129The second synopsis provides special features which allow
130for the creation of more sophisticated
131.Tn RPC
132servers.
133These features include support for user provided
134.Li #defines
135and
136.Tn RPC
137dispatch tables.
138The entries in the
139.Tn RPC
140dispatch table contain:
141.Pp
142.Bl -inset -offset indent -compact
143.It +
144pointers to the service routine corresponding to that procedure,
145.It +
146a pointer to the input and output arguments,
147.It +
148the size of these routines
149.El
150.Pp
151A server can use the dispatch table to check authorization
152and then to execute the service routine;
153a client library may use it to deal with the details of storage
154management and
155.Tn XDR
156data conversion.
157.Pp
158The other three synopses shown above are used when
159one does not want to generate all the output files,
160but only a particular one.
161Some examples of their usage is described in the
162.Sx EXAMPLES
163section below.
164When
165.Nm
166is executed with the
167.Fl s
168option,
169it creates servers for that particular class of transports.
170When
171executed with the
172.Fl n
173option,
174it creates a server for the transport specified by
175.Em netid .
176If
177.Ar infile
178is not specified,
179.Nm
180accepts the standard input.
181.Pp
182The C preprocessor,
183.Xr cpp 1
184is run on the input file before it is actually interpreted by
185.Nm
186For each type of output file,
187.Nm
188defines a special preprocessor symbol for use by the
189.Nm
190programmer:
191.Bl -tag -width RPC_CLNT
192.It Dv RPC_HDR
193defined when compiling into header files
194.It Dv RPC_XDR
195defined when compiling into
196.Tn XDR
197routines
198.It Dv RPC_SVC
199defined when compiling into server-side stubs
200.It Dv RPC_CLNT
201defined when compiling into client-side stubs
202.It Dv RPC_TBL
203defined when compiling into
204.Tn RPC
205dispatch tables
206.El
207.Pp
208Any line beginning with
209.Sq %
210is passed directly into the output file,
211uninterpreted by
212.Nm .
213.Pp
214For every data type referred to in
215.Ar infile
216.Nm
217assumes that there exists a
218routine with the string
219.Dq xdr_
220prepended to the name of the data type.
221If this routine does not exist in the
222.Tn RPC/XDR
223library, it must be provided.
224Providing an undefined data type
225allows customization of
226.Tn XDR
227routines.
228.Sh OPTIONS
229.Bl -tag -width indent
230.It Fl a
231Generate all the files including sample code for client and server side.
232.It Fl A
233Generate an
234.Fn svc_caller
235function.
236.It Fl b
237Compile stubs in "backwards compatible" mode, disabling support for
238transport-independent RPC.
239The
240.Fl b
241should always be specified when generating files for
242.Nx ,
243since there is no transport-independent RPC support in
244.Nx .
245.It Fl c
246Compile into
247.Tn XDR
248routines.
249.It Fl C
250Generate code in
251.Tn ANSI
252C.
253This option also generates code that could be compiled with the
254C++ compiler.
255.It Fl D Ar name Ns Op Ar =value
256Define a symbol
257.Dv name .
258Equivalent to the
259.Dv #define
260directive in the source.
261If no
262.Dv value
263is given,
264.Dv value
265is defined as 1.
266This option may be specified more than once.
267.It Fl h
268Compile into C data-definitions (a header file).
269The
270.Fl T
271option can be used in conjunction to produce a
272header file which supports
273.Tn RPC
274dispatch tables.
275.It Fl i Ar size
276Size to decide when to start generating inline code.
277The default size is 3.
278.It Fl I
279Support
280.Xr inetd 8
281in the server side stubs.
282Servers generated using this flag can either be standalone or
283started from
284.Xr inetd 8 .
285If a server is started as standalone, then it places itself
286in the background, unless
287.Dv RCP_SVC_FG
288is defined, or the server is compiled without
289.Fl I .
290.It Fl K Ar secs
291By default, services created using
292.Nm
293wait 120 seconds
294after servicing a request before exiting.
295That interval can be changed using the
296.Fl K
297flag.
298To create a server that exits immediately upon servicing a request,
299.Dq Fl K No 0
300can be used.
301To create a server that never exits, the appropriate argument is
302.Dq Fl K No -1 .
303.Pp
304When monitoring for a server,
305some port monitors, like the
306.At V.4
307utility
308.Ic listen ,
309.Em always
310spawn a new process in response to a service request.
311If it is known that a server will be used with such a monitor, the
312server should exit immediately on completion.
313For such servers,
314.Nm
315should be used with
316.Dq Fl K No -1 .
317.It Fl l
318Compile into client-side stubs.
319.Xr inetd 8 .
320.It Fl I
321Compile stubs meant for use in programs started by
322.Xr inetd 8 .
323.It Fl L
324Server errors will be sent to syslog instead of stderr.
325.It Fl m
326Compile into server-side stubs,
327but do not generate a
328.Fn main
329routine.
330This option is useful for doing callback-routines
331and for users who need to write their own
332.Fn main
333routine to do initialization.
334.It Fl M
335Generate thread-safe stubs.
336This alters the calling pattern of client and
337server stubs so that storage for results is allocated by the caller.
338Note
339that all components for a particular service (stubs, client and service
340wrappers, etc.) must be built either with or without the
341.Fl M
342flag.
343.It Fl N
344Use the newstyle of
345.Nm .
346This allows procedures to have multiple arguments.
347It also uses the style of parameter passing that closely resembles C.
348So, when passing an argument to a remote procedure you do not have
349to pass a pointer to the argument but the argument itself.
350This behaviour is different from the oldstyle
351of
352.Nm
353generated code.
354The newstyle is not the default case because of backward compatibility.
355.It Fl n Ar netid
356Compile into server-side stubs for the transport
357specified by
358.Ar netid .
359There should be an entry for
360.Ar netid
361in the
362netconfig database.
363This option may be specified more than once,
364so as to compile a server that serves multiple transports.
365.It Fl o Ar outfile
366Specify the name of the output file.
367If none is specified,
368standard output is used
369.Po
370.Fl c Fl h Fl l
371.Fl m Fl n Fl s
372modes only
373.Pc
374.It Fl n Ar netid
375Specify the transport for the server-side stubs.
376.Ar netid
377should be defined in
378.Xr netconfig 5 .
379This option can be repeated in order to support more than one transport.
380.It Fl s Ar nettype
381Compile into server-side stubs for all the
382transports belonging to the class
383.Ar nettype .
384The supported classes are
385.Em netpath ,
386.Em visible ,
387.Em circuit_n ,
388.Em circuit_v ,
389.Em datagram_n ,
390.Em datagram_v ,
391.Em tcp ,
392and
393.Em udp
394[see
395.Xr rpc 3
396for the meanings associated with these classes.
397.Em Note :
398.Bx
399currently supports only the
400.Em tcp
401and
402.Em udp
403classes].
404This option may be specified more than once.
405.Em Note :
406the transports are chosen at run time and not at compile time.
407.It Fl S\&c
408Generate sample code to show the use of remote procedure and how to bind
409to the server before calling the client side stubs generated by
410.Nm .
411.It Fl S\&s
412Generate skeleton code for the remote procedures on the server side.
413You would need
414to fill in the actual code for the remote procedures.
415.\" .It Fl S\&m
416.\" Generate a sample Makefile that can be used to compile the application.
417.It Fl t
418Compile into
419.Tn RPC
420dispatch table.
421.It Fl T
422Generate the code to support
423.Tn RPC
424dispatch tables.
425.It Fl v
426Display the version number.
427.It Fl Y Ar pathname
428Specify the directory where
429.Nm
430looks for the C pre-processor.
431.El
432.Pp
433The options
434.Fl c ,
435.Fl h ,
436.Fl l ,
437.Fl m ,
438.Fl s ,
439and
440.Fl t
441are used exclusively to generate a particular type of file,
442while the options
443.Fl D
444and
445.Fl T
446are global and can be used with the other options.
447.Sh NOTES
448The
449.Tn RPC
450Language does not support nesting of structures.
451As a work-around,
452structures can be declared at the top-level,
453and their name used inside other structures in
454order to achieve the same effect.
455.Pp
456Name clashes can occur when using program definitions,
457since the apparent scoping does not really apply.
458Most of these can be avoided by giving
459unique names for programs,
460versions,
461procedures and types.
462.Pp
463The server code generated with
464.Fl n
465option refers to the transport indicated by
466.Em netid
467and hence is very site specific.
468.Sh EXAMPLES
469The command
470.Pp
471.Bd -literal -offset indent
472$ rpcgen -T prot.x
473.Ed
474.Pp
475generates the five files:
476.Pa prot.h ,
477.Pa prot_clnt.c ,
478.Pa prot_svc.c ,
479.Pa prot_xdr.c
480and
481.Pa prot_tbl.i .
482.Pp
483The following example sends the C data-definitions (header file)
484to standard output.
485.Pp
486.Bd -literal -offset indent
487$ rpcgen -h prot.x
488.Ed
489.Pp
490To send the test version of the
491.Dv -DTEST ,
492server side stubs for
493all the transport belonging to the class
494.Em datagram_n
495to standard output, use:
496.Pp
497.Bd -literal -offset indent
498$ rpcgen -s datagram_n -DTEST prot.x
499.Ed
500.Pp
501To create the server side stubs for the transport indicated by
502.Em netid
503.Em tcp ,
504use:
505.Pp
506.Bd -literal -offset indent
507$ rpcgen -n tcp -o prot_svc.c prot.x
508.Ed
509.Sh SEE ALSO
510.Xr cpp 1 ,
511.Xr inetd 8
512.Sh HISTORY
513The
514.Fl M
515option was first implemented in RedHat Linux, and was reimplemented by
516Charles M. Hannum in
517.Nx 1.6 .
518