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