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