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
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
|
'\" te
.\" Copyright (C) 2009, Sun Microsystems, Inc. All Rights Reserved
.\" Copyright 1989 AT&T
.\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License. You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.
.\" See the License for the specific language governing permissions and limitations under the License. When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the
.\" fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
.TH RPCGEN 1 "Aug 24, 2009"
.SH NAME
rpcgen \- an RPC protocol compiler
.SH SYNOPSIS
.LP
.nf
\fBrpcgen\fR \fIinfile\fR
.fi
.LP
.nf
\fBrpcgen\fR [\fB-a\fR] [\fB-A\fR] [\fB-b\fR] [\fB-C\fR] [\fB-D\fR \fIname\fR [= \fIvalue\fR]] [\fB-i\fR \fIsize\fR]
[\fB-I\fR [\fB-K\fR \fIseconds\fR]] [\fB-L\fR] [\fB-M\fR] [\fB-N\fR] [\fB- T\fR] [\fB-v\fR]
[\fB-Y\fR \fIpathname\fR] \fIinfile\fR
.fi
.LP
.nf
\fBrpcgen\fR [\fB-c\fR | \fB-h\fR | \fB-l\fR | \fB-m\fR | \fB-t\fR | \fB-Sc\fR | \fB-Ss\fR | \fB-Sm\fR]
[\fB-o\fR \fIoutfile\fR] [\fIinfile\fR]
.fi
.LP
.nf
\fBrpcgen\fR [\fB-s\fR \fInettype\fR] [\fB-o\fR \fIoutfile\fR] [\fIinfile\fR]
.fi
.LP
.nf
\fBrpcgen\fR [\fB-n\fR \fInetid\fR] [\fB-o\fR \fIoutfile\fR] [\fIinfile\fR]
.fi
.SH DESCRIPTION
.sp
.LP
The \fBrpcgen\fR utility is a tool that generates C code to implement an
\fBRPC\fR protocol. The input to \fBrpcgen\fR is a language similar to C known
as \fBRPC\fR Language (Remote Procedure Call Language).
.sp
.LP
The \fBrpcgen\fR utility is normally used as in the first synopsis where it
takes an input file and generates three output files. If the \fIinfile\fR is
named \fBproto.x\fR, then \fBrpcgen\fR generates a header in \fBproto.h\fR,
\fBXDR\fR routines in \fBproto_xdr.c\fR, server-side stubs in
\fBproto_svc.c\fR, and client-side stubs in \fBproto_clnt.c\fR. With the
\fB-T\fR option, it also generates the \fBRPC\fR dispatch table in
\fBproto_tbl.i\fR.
.sp
.LP
\fBrpcgen\fR can also generate sample client and server files that can be
customized to suit a particular application. The \fB-Sc\fR, \fB-Ss\fR, and
\fB-Sm\fR options generate sample client, server and makefile, respectively.
The \fB-a\fR option generates all files, including sample files. If the infile
is \fBproto.x\fR, then the client side sample file is written to
\fBproto_client.c\fR, the server side sample file to \fBproto_server.c\fR and
the sample makefile to \fBmakefile.proto\fR.
.sp
.LP
The server created can be started both by the port monitors (for example,
\fBinetd\fR or \fBlisten\fR) or by itself. When it is started by a port
monitor, it creates servers only for the transport for which the file
descriptor \fB0\fR was passed. The name of the transport must be specified by
setting up the environment variable \fBPM_TRANSPORT\fR. When the server
generated by \fBrpcgen\fR is executed, it creates server handles for all the
transports specified in the \fBNETPATH\fR environment variable, or if it is
unset, it creates server handles for all the visible transports from the
\fB/etc/netconfig\fR file. 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 \fBRPC_SVC_FG\fR can be used to run the server
process in foreground.
.sp
.LP
The second synopsis provides special features which allow for the creation of
more sophisticated \fBRPC\fR servers. These features include support for
user-provided \fB#defines\fR and \fBRPC\fR dispatch tables. The entries in the
\fBRPC\fR dispatch table contain:
.RS +4
.TP
.ie t \(bu
.el o
pointers to the service routine corresponding to that procedure
.RE
.RS +4
.TP
.ie t \(bu
.el o
a pointer to the input and output arguments
.RE
.RS +4
.TP
.ie t \(bu
.el o
the size of these routines
.RE
.sp
.LP
A server can use the dispatch table to check authorization and then to execute
the service routine. A client library can use the dispatch table to deal with
the details of storage management and \fBXDR\fR data conversion.
.sp
.LP
The other three synopses shown above are used when one does not want to
generate all the output files, but only a particular one. See the EXAMPLES
section below for examples of \fBrpcgen\fR usage. When \fBrpcgen\fR is executed
with the \fB-s\fR option, it creates servers for that particular class of
transports. When executed with the \fB-n\fR option, it creates a server for the
transport specified by \fInetid\fR. If \fIinfile\fR is not specified,
\fBrpcgen\fR accepts the standard input.
.sp
.LP
All the options mentioned in the second synopsis can be used with the other
three synopses, but the changes are made only to the specified output file.
.sp
.LP
The C preprocessor \fBcc\fR \fB-E\fR is run on the input file before it is
actually interpreted by \fBrpcgen\fR. For each type of output file,
\fBrpcgen\fR defines a special preprocessor symbol for use by the \fBrpcgen\fR
programmer:
.sp
.ne 2
.na
\fB\fBRPC_HDR\fR\fR
.ad
.RS 12n
defined when compiling into headers
.RE
.sp
.ne 2
.na
\fB\fBRPC_XDR\fR\fR
.ad
.RS 12n
defined when compiling into \fBXDR\fR routines
.RE
.sp
.ne 2
.na
\fB\fBRPC_SVC\fR\fR
.ad
.RS 12n
defined when compiling into server-side stubs
.RE
.sp
.ne 2
.na
\fB\fBRPC_CLNT\fR\fR
.ad
.RS 12n
defined when compiling into client-side stubs
.RE
.sp
.ne 2
.na
\fB\fBRPC_TBL\fR\fR
.ad
.RS 12n
defined when compiling into \fBRPC\fR dispatch tables
.RE
.sp
.LP
Any line beginning with ``\fB%\fR'' is passed directly into the output file,
uninterpreted by \fBrpcgen\fR, except that the leading ``\fB%\fR" is stripped
off. To specify the path name of the C preprocessor, use the \fB-Y\fR flag.
.sp
.LP
For every data type referred to in \fIinfile\fR, \fBrpcgen\fR assumes that
there exists a routine with the string \fBxdr_\fR prepended to the name of the
data type. If this routine does not exist in the \fBRPC\fR/\fBXDR\fR library,
it must be provided. Providing an undefined data type allows customization of
\fBXDR\fR routines.
.SS "Server Error Reporting"
.sp
.LP
By default, errors detected by \fBproto_svc.c\fR is reported to standard error
and/or the system log.
.sp
.LP
This behavior can be overridden by compiling the file with a definition of
\fBRPC_MSGOUT\fR, for example, \fB-DRPC_MSGOUT=mymsgfunc\fR. The function
specified is called to report errors. It must conform to the following
\fBprintf\fR-like signature:
.sp
.in +2
.nf
extern void RPC_MSGOUT(const char *fmt, ...);
.fi
.in -2
.sp
.SH OPTIONS
.sp
.LP
The following options are supported:
.sp
.ne 2
.na
\fB\fB-a\fR\fR
.ad
.RS 18n
Generates all files, including sample files.
.RE
.sp
.ne 2
.na
\fB\fB-A\fR\fR
.ad
.RS 18n
Enables the Automatic \fBMT\fR mode in the server main program. In this mode,
the \fBRPC\fR library automatically creates threads to service client requests.
This option generates multithread-safe stubs by implicitly turning on the
\fB-M\fR option. Server multithreading modes and parameters can be set using
the \fBrpc_control\fR(3NSL) call. \fBrpcgen\fR generated code does not change
the default values for the Automatic \fBMT\fR mode.
.RE
.sp
.ne 2
.na
\fB\fB-b\fR\fR
.ad
.RS 18n
Backward compatibility mode. Generates transport-specific \fBRPC\fR code for
older versions of the operating system.
.RE
.sp
.ne 2
.na
\fB\fB-c\fR\fR
.ad
.RS 18n
Compiles into \fBXDR\fR routines.
.RE
.sp
.ne 2
.na
\fB\fB-C\fR\fR
.ad
.RS 18n
Generates header and stub files which can be used with ANSI C compilers.
Headers generated with this flag can also be used with C++ programs.
.RE
.sp
.ne 2
.na
\fB\fB-D\fR\fIname\fR\fB[=\fR\fIvalue\fR\fB]\fR\fR
.ad
.RS 18n
Defines a symbol \fIname\fR. Equivalent to the \fB#define\fR directive in the
source. If no \fIvalue\fR is given, \fIvalue\fR is defined as \fB1\fR. This
option can be specified more than once.
.RE
.sp
.ne 2
.na
\fB\fB-h\fR\fR
.ad
.RS 18n
Compiles into \fBC\fR data-definitions (a header). The \fB-T\fR option can be
used in conjunction to produce a header which supports \fBRPC\fR dispatch
tables.
.RE
.sp
.ne 2
.na
\fB\fB-i\fR \fIsize\fR\fR
.ad
.RS 18n
Size at which to start generating inline code. This option is useful for
optimization. The default \fIsize\fR is 5.
.RE
.sp
.ne 2
.na
\fB\fB-I\fR\fR
.ad
.RS 18n
Compiles support for \fBinetd\fR(1M) in the server side stubs. Such servers can
be self-started or can be started by \fBinetd\fR. When the server is
self-started, it backgrounds itself by default. A special define symbol
\fBRPC_SVC_FG\fR can be used to run the server process in foreground, or the
user can simply compile without the \fB-I\fR option.
.sp
If there are no pending client requests, the \fBinetd\fR servers exit after 120
seconds (default). The default can be changed with the \fB-K\fR option. All of
the error messages for \fBinetd\fR servers are always logged with
\fBsyslog\fR(3C).
.sp
\fBNote:\fR This option is supported for backward compatibility only. It should
always be used in conjunction with the \fB-b\fR option which generates backward
compatibility code. By default (that is, when \fB-b\fR is not specified),
\fBrpcgen\fR generates servers that can be invoked through portmonitors.
.RE
.sp
.ne 2
.na
\fB\fB-K\fR \fIseconds\fR\fR
.ad
.RS 18n
By default, services created using \fBrpcgen\fR and invoked through port
monitors wait 120 seconds after servicing a request before exiting. That
interval can be changed using the \fB-K\fR flag. To create a server that exits
immediately upon servicing a request, use \fB-K\fR \fB0\fR. To create a server
that never exits, the appropriate argument is \fB-K\fR \fB\(mi1\fR\&.
.sp
When monitoring for a server, some portmonitors, like \fBlisten\fR(1M),
\fBalways\fR spawn a new process in response to a service request. If it is
known that a server are used with such a monitor, the server should exit
immediately on completion. For such servers, \fBrpcgen\fR should be used with
\fB-K\fR \fB0\fR.
.RE
.sp
.ne 2
.na
\fB\fB-l\fR\fR
.ad
.RS 18n
Compiles into client-side stubs.
.RE
.sp
.ne 2
.na
\fB\fB-L\fR\fR
.ad
.RS 18n
When the servers are started in foreground, uses \fBsyslog\fR(3C) to log the
server errors instead of printing them on the standard error.
.RE
.sp
.ne 2
.na
\fB\fB-m\fR\fR
.ad
.RS 18n
Compiles into server-side stubs, but do not generate a "main" routine. This
option is useful for doing callback-routines and for users who need to write
their own "main" routine to do initialization.
.RE
.sp
.ne 2
.na
\fB\fB-M\fR\fR
.ad
.RS 18n
Generates multithread-safe stubs for passing arguments and results between
\fBrpcgen\fR-generated code and user written code. This option is useful for
users who want to use threads in their code.
.RE
.sp
.ne 2
.na
\fB\fB-N\fR\fR
.ad
.RS 18n
This option 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 can pass the argument itself. This behavior is different from the
old style of \fBrpcgen\fR-generated code. To maintain backward compatibility,
this option is not the default.
.RE
.sp
.ne 2
.na
\fB\fB-n\fR \fInetid\fR\fR
.ad
.RS 18n
Compiles into server-side stubs for the transport specified by \fInetid\fR.
There should be an entry for \fInetid\fR in the \fBnetconfig\fR database. This
option can be specified more than once, so as to compile a server that serves
multiple transports.
.RE
.sp
.ne 2
.na
\fB\fB-o\fR \fIoutfile\fR\fR
.ad
.RS 18n
Specifies the name of the output file. If none is specified, standard output is
used (\fB-c\fR, \fB-h\fR, \fB-l\fR, \fB-m\fR, \fB-n\fR, \fB-s\fR, \fB-Sc\fR,
\fB-Sm\fR, \fB-Ss\fR, and \fB-t\fR modes only).
.RE
.sp
.ne 2
.na
\fB\fB-s\fR \fInettype\fR\fR
.ad
.RS 18n
Compiles into server-side stubs for all the transports belonging to the class
\fInettype\fR. The supported classes are \fBnetpath\fR, \fBvisible\fR,
\fBcircuit_n\fR, \fBcircuit_v\fR, \fBdatagram_n\fR, \fBdatagram_v\fR,
\fBtcp\fR, and \fBudp\fR (see \fBrpc\fR(3NSL) for the meanings associated with
these classes). This option can be specified more than once. \fBNote:\fR The
transports are chosen at run time and not at compile time.
.RE
.sp
.ne 2
.na
\fB\fB-Sc\fR\fR
.ad
.RS 18n
Generates sample client code that uses remote procedure calls.
.RE
.sp
.ne 2
.na
\fB\fB-Sm\fR\fR
.ad
.RS 18n
Generates a sample Makefile which can be used for compiling the application.
.RE
.sp
.ne 2
.na
\fB\fB-Ss\fR\fR
.ad
.RS 18n
Generates sample server code that uses remote procedure calls.
.RE
.sp
.ne 2
.na
\fB\fB-t\fR\fR
.ad
.RS 18n
Compiles into \fBRPC\fR dispatch table.
.RE
.sp
.ne 2
.na
\fB\fB-T\fR\fR
.ad
.RS 18n
Generates the code to support \fBRPC\fR dispatch tables.
.sp
The options \fB-c\fR, \fB-h\fR, \fB-l\fR, \fB-m\fR, \fB-s\fR, \fB-Sc\fR,
\fB-Sm\fR, \fB-Ss\fR, and \fB-t\fR are used exclusively to generate a
particular type of file, while the options \fB-D\fR and \fB-T\fR are global and
can be used with the other options.
.RE
.sp
.ne 2
.na
\fB\fB-v\fR\fR
.ad
.RS 18n
Displays the version number.
.RE
.sp
.ne 2
.na
\fB\fB-Y\fR \fIpathname\fR\fR
.ad
.RS 18n
Gives the name of the directory where \fBrpcgen\fR starts looking for the C
preprocessor.
.RE
.SH OPERANDS
.sp
.LP
The following operand is supported:
.sp
.ne 2
.na
\fB\fIinfile\fR\fR
.ad
.RS 10n
input file
.RE
.SH EXAMPLES
.LP
\fBExample 1 \fRGenerating the output files and dispatch table
.sp
.LP
The following entry
.sp
.in +2
.nf
example% \fBrpcgen -T prot.x\fR
.fi
.in -2
.sp
.sp
.LP
generates all the five files: \fBprot.h\fR, \fBprot_clnt.c\fR,
\fBprot_svc.c\fR, \fBprot_xdr.c\fR, and \fBprot_tbl.i\fR.
.LP
\fBExample 2 \fRSending headers to standard output
.sp
.LP
The following example sends the C data-definitions (header) to the standard
output:
.sp
.in +2
.nf
example% \fBrpcgen -h prot.x\fR
.fi
.in -2
.sp
.LP
\fBExample 3 \fRSending a test version
.sp
.LP
To send the test version of the \fB-DTEST\fR, server side stubs for all the
transport belonging to the class \fBdatagram_n\fR to standard output, use:
.sp
.in +2
.nf
example% \fBrpcgen -s datagram_n -DTEST prot.x\fR
.fi
.in -2
.sp
.LP
\fBExample 4 \fRCreating server side stubs
.sp
.LP
To create the server side stubs for the transport indicated by \fInetid\fR
\fBtcp\fR, use:
.sp
.in +2
.nf
example% \fBrpcgen -n tcp -o prot_svc.c prot.x\fR
.fi
.in -2
.sp
.SH EXIT STATUS
.sp
.ne 2
.na
\fB\fB0\fR\fR
.ad
.RS 6n
Successful operation.
.RE
.sp
.ne 2
.na
\fB\fB>0\fR\fR
.ad
.RS 6n
An error occurred.
.RE
.SH SEE ALSO
.sp
.LP
\fBinetd\fR(1M), \fBlisten\fR(1M), \fBrpc\fR(3NSL), \fBrpc_control\fR(3NSL),
\fBrpc_svc_calls\fR(3NSL), \fBsyslog\fR(3C), \fBnetconfig\fR(4),
\fBattributes\fR(5)
.sp
.LP
The \fBrpcgen\fR chapter in the \fIONC+ Developer\&'s Guide\fR manual.
|