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