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