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