xref: /freebsd/usr.bin/rpcgen/rpcgen.1 (revision b52b9d56d4e96089873a75f9e29062eec19fabba)
1.\" @(#)rpcgen.1 1.35 93/06/02 SMI
2.\" $FreeBSD$
3.\" Copyright 1985-1993 Sun Microsystems, Inc.
4.\"
5.Dd March 28, 1993
6.Dt RPCGEN 1
7.Os
8.Sh NAME
9.Nm rpcgen
10.Nd an RPC protocol compiler
11.Sh SYNOPSIS
12.Nm
13.Ar infile
14.Nm
15.Op Fl a
16.Op Fl b
17.Op Fl C
18.Oo
19.Fl D Ns Ar name Ns Op Ar =value
20.Oc
21.Op Fl i Ar size
22.Op Fl I Fl P Op Fl K Ar seconds
23.Op Fl L
24.Op Fl M
25.Op Fl N
26.Op Fl T
27.Op Fl Y Ar pathname
28.Ar infile
29.Nm
30.Oo
31.Fl c |
32.Fl h |
33.Fl l |
34.Fl m |
35.Fl t |
36.Fl \&Sc |
37.Fl \&Ss |
38.Fl \&Sm
39.Oc
40.Op Fl o Ar outfile
41.Op Ar infile
42.Nm
43.Op Fl s Ar nettype
44.Op Fl o Ar outfile
45.Op Ar infile
46.Nm
47.Op Fl n Ar netid
48.Op Fl o Ar outfile
49.Op Ar infile
50.\" .SH AVAILABILITY
51.\" .LP
52.\" SUNWcsu
53.Sh DESCRIPTION
54The
55.Nm
56utility is a tool that generates C code to implement an
57.Tn RPC
58protocol.
59The input to
60.Nm
61is a language similar to C known as
62.Tn RPC
63Language (Remote Procedure Call Language).
64.Pp
65The
66.Nm
67utility is normally used as in the first synopsis where
68it takes an input file and generates three output files.
69If the
70.Ar infile
71is named
72.Pa proto.x ,
73then
74.Nm
75generates a header in
76.Pa proto.h ,
77XDR routines in
78.Pa proto_xdr.c ,
79server-side stubs in
80.Pa proto_svc.c ,
81and client-side stubs in
82.Pa proto_clnt.c .
83With the
84.Fl T
85option,
86it also generates the
87.Tn RPC
88dispatch table in
89.Pa proto_tbl.i .
90.Pp
91The
92.Nm
93utility can also generate sample client and server files
94that can be customized to suit a particular application.
95The
96.Fl \&Sc ,
97.Fl \&Ss
98and
99.Fl \&Sm
100options generate sample client, server and makefile, respectively.
101The
102.Fl a
103option generates all files, including sample files.
104If the
105.Ar infile
106is
107.Pa proto.x ,
108then the client side sample file is written to
109.Pa proto_client.c ,
110the server side sample file to
111.Pa proto_server.c
112and the sample makefile to
113.Pa makefile.proto .
114.Pp
115If option
116.Fl I
117is set,
118The server created can be started both by the port monitors
119(for example,
120.Xr inetd 8 )
121or by itself.
122When it is started by a port monitor,
123it creates servers only for the transport for which
124the file descriptor
125.Em 0
126was passed.
127The name of the transport may be specified
128by setting up the environment variable
129.Ev NLSPROVIDER .
130When the server generated by
131.Nm
132is executed,
133it creates server handles for all the transports
134specified in
135.Ev NETPATH
136environment variable,
137or if it is unset,
138it creates server handles for all the visible transports from
139.Pa /etc/netconfig
140file.
141Note:
142the transports are chosen at run time and not at compile time.
143When the server is self-started,
144it backgrounds itself by default.
145A special define symbol
146.Em RPC_SVC_FG
147can be used to run the server process in foreground.
148.Pp
149The second synopsis provides special features which allow
150for the creation of more sophisticated
151.Tn RPC
152servers.
153These features include support for user provided
154.Em #defines
155and
156.Tn RPC
157dispatch tables.
158The entries in the
159.Tn RPC
160dispatch table contain:
161.Bl -bullet -offset indent -compact
162.It
163pointers to the service routine corresponding to that procedure,
164.It
165a pointer to the input and output arguments,
166.It
167the size of these routines.
168.El
169A server can use the dispatch table to check authorization
170and then to execute the service routine;
171a client library may use it to deal with the details of storage
172management and XDR data conversion.
173.Pp
174The other three synopses shown above are used when
175one does not want to generate all the output files,
176but only a particular one.
177See the
178.Sx EXAMPLES
179section below for examples of
180.Nm
181usage.
182When
183.Nm
184is executed with the
185.Fl s
186option,
187it creates servers for that particular class of transports.
188When
189executed with the
190.Fl n
191option,
192it creates a server for the transport specified by
193.Ar netid .
194If
195.Ar infile
196is not specified,
197.Nm
198accepts the standard input.
199.Pp
200The C preprocessor,
201.Em cc -E
202is run on the input file before it is actually interpreted by
203.Nm .
204For each type of output file,
205.Nm
206defines a special preprocessor symbol for use by the
207.Nm
208programmer:
209.Bl -tag -width indent
210.It RPC_HDR
211defined when compiling into headers
212.It RPC_XDR
213defined when compiling into XDR routines
214.It RPC_SVC
215defined when compiling into server-side stubs
216.It RPC_CLNT
217defined when compiling into client-side stubs
218.It RPC_TBL
219defined when compiling into RPC dispatch tables
220.El
221.Pp
222Any line beginning with
223.Dq %
224is passed directly into the output file,
225uninterpreted by
226.Nm .
227To specify the path name of the C preprocessor use
228.Fl Y
229flag.
230.Pp
231For every data type referred to in
232.Ar infile ,
233.Nm
234assumes that there exists a
235routine with the string
236.Em xdr_
237prepended to the name of the data type.
238If this routine does not exist in the
239.Tn RPC/XDR
240library, it must be provided.
241Providing an undefined data type
242allows customization of
243.Xr xdr 3
244routines.
245.Sh OPTIONS
246The following options are available:
247.Bl -tag -width indent
248.It Fl a
249Generate all files, including sample files.
250.It Fl b
251Backward compatibility mode.
252Generate transport specific
253.Tn RPC
254code for older versions
255of the operating system.
256.It Fl c
257Compile into
258.Tn XDR
259routines.
260.It Fl C
261Generate header and stub files which can be used with
262.Tn ANSI
263C compilers.  Headers generated with this flag can also be
264used with C++ programs.
265.It Fl D Ns Ar name
266.It Fl D Ns Ar name=value
267.\".It Fl D Ns Ar name Ns Op Ar =value
268Define a symbol
269.Ar name .
270Equivalent to the
271.Em #define
272directive in the source.
273If no
274.Ar value
275is given,
276.Ar value
277is defined as
278.Em 1 .
279This option may be specified more than once.
280.It Fl h
281Compile into C data-definitions (a header).
282.Fl T
283option can be used in conjunction to produce a
284header which supports
285.Tn RPC
286dispatch tables.
287.It Fl i Ar size
288Size at which to start generating inline code.
289This option is useful for optimization.
290The default size is 5.
291.Pp
292Note: in order to provide backwards compatibility with the older
293.Nm
294on the
295.Fx
296platform, the default is actually 0 (which means
297that inline code generation is disabled by default). You must specify
298a non-zero value explicitly to override this default.
299.It Fl I
300Compile support for
301.Xr inetd 8
302in the server side stubs.
303Such servers can be self-started or can be started by
304.Nm inetd .
305When the server is self-started, it backgrounds itself by default.
306A special define symbol
307.Em RPC_SVC_FG
308can be used to run the
309server process in foreground, or the user may simply compile without
310the
311.Fl I
312option.
313.Pp
314If there are no pending client requests, the
315.Nm inetd
316servers exit after 120 seconds (default).
317The default can be changed with the
318.Fl K
319option.
320All the error messages for
321.Nm inetd
322servers
323are always logged with
324.Xr syslog 3 .
325.Pp
326Note:
327Contrary to some systems, in
328.Fx
329this option is needed to generate
330servers that can be invoked through portmonitors and inetd.
331.Pp
332.It Fl K Ar seconds
333By default, services created using
334.Nm
335and invoked through
336port monitors wait 120 seconds
337after servicing a request before exiting.
338That interval can be changed using the
339.Fl K
340flag.
341To create a server that exits immediately upon servicing a request,
342use
343.Fl K Ar 0 .
344To create a server that never exits, the appropriate argument is
345.Fl k Ar -1 .
346.Pp
347When monitoring for a server,
348some portmonitors
349.Em always
350spawn a new process in response to a service request.
351If it is known that a server will be used with such a monitor, the
352server should exit immediately on completion.
353For such servers,
354.Nm
355should be used with
356.Fl K Ar 0 .
357.It Fl l
358Compile into client-side stubs.
359.It Fl L
360When the servers are started in foreground, use
361.Xr syslog 3
362to log the server errors instead of printing them on the standard
363error.
364.It Fl m
365Compile into server-side stubs,
366but do not generate a
367.Qq main
368routine.
369This option is useful for doing callback-routines
370and for users who need to write their own
371.Qq main
372routine to do initialization.
373.It Fl M
374Generate multithread-safe stubs for passing arguments and results between
375rpcgen generated code and user written code.
376This option is useful
377for users who want to use threads in their code.
378However, the
379.Xr rpc_svc_calls 3
380functions are not yet MT-safe, which means that rpcgen generated server-side
381code will not be MT-safe.
382.It Fl N
383Allow procedures to have multiple arguments.
384It also uses the style of parameter passing that closely resembles C.
385So, when passing an argument to a remote procedure, you do not have to
386pass a pointer to the argument, but can pass the argument itself.
387This behavior is different from the old style of
388.Nm
389generated code.
390To maintain backward compatibility,
391this option is not the default.
392.It Fl n Ar netid
393Compile into server-side stubs for the transport
394specified by
395.Ar netid .
396There should be an entry for
397.Ar netid
398in the
399netconfig database.
400This option may be specified more than once,
401so as to compile a server that serves multiple transports.
402.It Fl o Ar outfile
403Specify the name of the output file.
404If none is specified,
405standard output is used
406(
407.Fl c ,
408.Fl h ,
409.Fl l ,
410.Fl m ,
411.Fl n ,
412.Fl s ,
413.Fl \&Sc ,
414.Fl \&Sm ,
415.Fl \&Ss ,
416and
417.Fl t
418modes only).
419.It Fl P
420Compile support for
421port monitors
422in the server side stubs.
423.Pp
424Note:
425Contrary to some systems, in
426.Fx
427this option is needed to generate
428servers that can be monitored.
429.Pp
430If the
431.Fl I
432option has been specified,
433.Fl P
434is turned off automatically.
435.Pp
436.It Fl s Ar nettype
437Compile into server-side stubs for all the
438transports belonging to the class
439.Ar nettype .
440The supported classes are
441.Em netpath ,
442.Em visible ,
443.Em circuit_n ,
444.Em circuit_v ,
445.Em datagram_n ,
446.Em datagram_v ,
447.Em tcp ,
448and
449.Em udp
450(see
451.Xr rpc 3
452for the meanings associated with these classes).
453This option may be specified more than once.
454Note:
455the transports are chosen at run time and not at compile time.
456.It Fl \&Sc
457Generate sample client code that uses remote procedure calls.
458.It Fl \&Sm
459Generate a sample
460.Pa Makefile
461which can be used for compiling the application.
462.It Fl \&Ss
463Generate sample server code that uses remote procedure calls.
464.It Fl t
465Compile into
466.Tn RPC
467dispatch table.
468.It Fl T
469Generate the code to support
470.Tn RPC
471dispatch tables.
472.Pp
473The options
474.Fl c ,
475.Fl h ,
476.Fl l ,
477.Fl m ,
478.Fl s ,
479.Fl \&Sc ,
480.Fl \&Sm ,
481.Fl \&Ss ,
482and
483.Fl t
484are used exclusively to generate a particular type of file,
485while the options
486.Fl D
487and
488.Fl T
489are global and can be used with the other options.
490.It Fl Y Ar pathname
491Give the name of the directory where
492.Nm
493will start looking for the C-preprocessor.
494.El
495.Sh EXAMPLES
496The following example:
497.Dl example% rpcgen -T prot.x
498.Pp
499generates all the five files:
500.Pa prot.h ,
501.Pa prot_clnt.c ,
502.Pa prot_svc.c ,
503.Pa prot_xdr.c
504and
505.Pa prot_tbl.i .
506.Pp
507The following example sends the C data-definitions (header)
508to the standard output.
509.Dl example% rpcgen -h prot.x
510.Pp
511To send the test version of the
512.Fl D Ns Ar TEST ,
513server side stubs for
514all the transport belonging to the class
515.Ar datagram_n
516to standard output, use:
517.Dl example% rpcgen -s datagram_n -DTEST prot.x
518.Pp
519To create the server side stubs for the transport indicated
520by
521.Ar netid
522tcp,
523use:
524.Dl example% rpcgen -n tcp -o prot_svc.c prot.x
525.Sh SEE ALSO
526.Xr cc 1 ,
527.Xr rpc 3 ,
528.Xr rpc_svc_calls 3 ,
529.Xr syslog 3 ,
530.Xr xdr 3 ,
531.Xr inetd 8
532.Rs
533.%T The rpcgen chapter in the NETP manual
534.Re
535