rpcgen(1)
๐ NAME ๐
rpcgen(1) ยท General Commands Manual ๐
okay so rpcgen is an RPC protocol compiler ๐
rpcgen - an RPC protocol compiler
โจ SYNOPSIS โจ
rpcgen infile
rpcgen [-Dname[=value]] [-T] [-K secs] infile
rpcgen -c|-h|-l|-m|-M|-t [-o outfile ] infile
rpcgen [-I] -s nettype [-o outfile] infile
rpcgen -n netid [-o outfile] infile
๐ DESCRIPTION ๐
okay bestie, listen up ๐ซถ rpcgen is a tool that generates C code to implement an RPC protocol. The input is written in a language that looks a lot like C, called RPC Language (Remote Procedure Call Language). it's giving C but make it remote ๐ฅ
the first synopsis is the normal way to use it. you hand it an input file and it spits out up to four output files ๐ง if your infile is called proto.x, rpcgen makes:
- a header file,
proto.h - XDR routines, in
proto_xdr.c - server-side stubs, in
proto_svc.c - client-side stubs, in
proto_clnt.c
with the -T option, it also makes the RPC dispatch table in proto_tbl.i โจ with the -Sc option, it also generates sample code showing how to use the remote procedures on the client side, and that lives in proto_client.c ๐ฆ and with the -Ss option, it generates sample server code showing how to write the remote procedures, saved to proto_server.c ๐
the server you make can be started by the port monitors (like inetd or listen) or by itself ๐ธ when a port monitor starts it, it only makes servers for the transport that file descriptor 0 was passed in. the transport name has to be set up in the PM_TRANSPORT environment variable ๐ซ when the generated server runs on its own, it makes server handles for every transport listed in the NETPATH environment variable. if that's unset, it makes handles for all the visible transports from the /etc/netconfig file. note: the transports get picked at run time, not compile time, so no surprises ๐
when you build for a port monitor (rpcgen -I) and the server starts itself, it backgrounds itself by default ๐ if you want it in the foreground instead, define the special symbol RPC_SVC_FG ๐
the second synopsis is where things get fancy โจ it unlocks more sophisticated RPC servers, with support for user-provided #defines and RPC dispatch tables. each entry in the dispatch table holds:
- a pointer to the service routine for that procedure
- a pointer to the input and output arguments
- the size of those routines
a server can use the dispatch table to check authorization and then run the service routine, and a client library can use it to handle storage management and XDR data conversion. main character energy ๐
the other three synopses are for when you don't want every output file, just one specific one. some examples are in the EXAMPLE section below ๐ running rpcgen with -s makes servers for that particular class of transports, and running it with -n makes a server for the transport named by netid. if you don't specify an infile, rpcgen reads standard input ๐ซถ
before rpcgen interprets the input file, the C preprocessor runs on it, using cc -E [see cc(1)]. for each type of output file, rpcgen defines a special preprocessor symbol you can use in your .x file:
RPC_HDRโ defined when compiling into header filesRPC_XDRโ defined when compiling into XDR routinesRPC_SVCโ defined when compiling into server-side stubsRPC_CLNTโ defined when compiling into client-side stubsRPC_TBLโ defined when compiling into RPC dispatch tables
any line that starts with % gets passed straight into the output file, and rpcgen doesn't touch it ๐
for every data type mentioned in infile, rpcgen assumes there's a routine named with xdr_ stuck on the front of the type name โจ if that routine isn't in the RPC/XDR library, you have to provide it yourself. providing your own routine for an undefined data type is how you customize XDR routines ๐ฅ
๐ The Options ๐
here's everything you can pass, bestie ๐
-aโ makes all the files, including sample code for both the client and server side ๐ธ-bโ generates code for the SunOS4.1 style of rpc. it's there for backward compatibility, and it's the default ๐ฆ-5โ generates code for the SysVr4 style of rpc ๐ this is the one used by Transport Independent RPC on Svr4 systems. by default rpcgen generates the SunOS4.1 style of rpc-cโ compiles into XDR routines ๐ง-Cโ generates code in ANSI C. this also makes code that can be compiled by a C++ compiler, and it's the default โจ-kโ generates code in K&R C. the default is ANSI C ๐ซ-Dname[=value]โ defines a symbol calledname, same as a#definein the source. if you don't give a value, it's set to1. you can use this option more than once ๐-hโ compiles into C data-definitions, aka a header file ๐ you can pair it with the-Toption to make a header that supports RPC dispatch tables ๐-Iโ generates a service that can be started frominetd๐ the default is a static service that handles the transports you pick with-s. using-Ilets you start the service either way ๐-K secsโ by default, services made with rpcgen wait 120 seconds after handling a request before they exit ๐ญ you can change that interval with-K. for a server that exits right after handling a request, use-K 0. for a server that never exits, use-K -1๐
when you're monitoring for a server, some port monitors, like listen(1M), always spawn a new process for each service request. if you know your server will be used with one of those, it should exit immediately when it's done. for those servers, run rpcgen with -K -1 ๐
-lโ compiles into client-side stubs ๐ฆ-mโ compiles into server-side stubs, but doesn't generate a โmainโ routine ๐ this is handy for callback routines, and for people who want to write their own โmainโ for setup stuff ๐ซถ-Mโ generates multithread-safe stubs for passing arguments and results between rpcgen-generated code and the code you write ๐งต this one's great if you want threads in your code โจ-n netidโ compiles into server-side stubs for the transport named by netid ๐ฅ there should be an entry for that netid in the netconfig database. you can use this option more than once to build a server that serves multiple transports ๐ธ-Nโ uses the newstyle of rpcgen ๐ this lets procedures take multiple arguments, and it passes parameters in a way that looks a lot more like C. so when you pass an argument to a remote procedure, you pass the argument itself, not a pointer to it ๐ซ this is different from the oldstyle generated code. newstyle isn't the default because of backward compatibility ๐-o outfileโ names the output file ๐ if you don't pick one, the output goes to standard output. this works for the-c,-h,-l,-m,-n,-s,-Sc,-Sm,-Ss, and-tmodes only ๐ง-s nettypeโ compiles into server-side stubs for every transport in the nettype class โจ the supported classes arenetpath,visible,circuit_n,circuit_v,datagram_n,datagram_v,tcp, andudp[see rpc(3N) for what these classes mean]. you can use this option more than once ๐ note: the transports are chosen at run time, not compile time ๐-Scโ generates sample code showing how to use the remote procedures and how to bind to the server before calling the client-side stubs rpcgen made ๐ฆ-Smโ generates a sample Makefile you can use to compile the application ๐-Ssโ generates skeleton code for the remote procedures on the server side ๐ธ you'll need to fill in the actual code for them yourself ๐-tโ compiles into an RPC dispatch table ๐-Tโ generates the code that supports RPC dispatch tables ๐ง
the options -c, -h, -l, -m, -s, and -t are used exclusively, meaning each one makes one specific type of file ๐ฅ the options -D and -T are global, so you can combine them with the other options ๐ซถ
๐ NOTES ๐
heads up: the RPC Language doesn't support nesting structures ๐ญ the workaround is to declare structures at the top level, then use their names inside other structures to get the same effect ๐
name clashes can happen with program definitions, because the apparent scoping doesn't really apply ๐ you can avoid most of them by giving programs, versions, procedures, and types unique names โจ
the server code generated with the -n option refers to the transport indicated by netid, so it's very site specific ๐
๐ง EXAMPLE ๐ง
this one's a classic ๐ it generates five files:
$ rpcgen -T prot.x
the files are prot.h, prot_clnt.c, prot_svc.c, prot_xdr.c, and prot_tbl.i โจ
this one sends the C data-definitions (the header file) to standard output ๐
$ rpcgen -h prot.x
to send the test version of the server-side stubs for all the transports in the datagram_n class to standard output, with -DTEST defined, use this ๐ฆ
$ rpcgen -s datagram_n -DTEST prot.x
and to create the server-side stubs for the transport indicated by netid tcp, use this ๐ซถ
$ rpcgen -n tcp -o prot_svc.c prot.x
๐ SEE ALSO ๐
cc(1) ๐
ok that's the whole tea โ rpcgen(1), signing off ๐๐ฆโจ
๐ฆ where this page comes from
- alpine 3.22: nfs-utils-doc 2.6.4-r4 ยท GPL-2.0-only
- alpine 3.22: rpcsvc-proto-doc 1.4.4-r0 ยท BSD-3-Clause
- alpine 3.23: nfs-utils-doc 2.6.4-r6 ยท GPL-2.0-only
- alpine 3.23: rpcsvc-proto-doc 1.4.4-r0 ยท BSD-3-Clause
- alpine 3.24: nfs-utils-doc 2.6.4-r6 ยท GPL-2.0-only
- alpine 3.24: rpcsvc-proto-doc 1.4.4-r0 ยท BSD-3-Clause
- arch rolling: rpcsvc-proto 1.4.4-2 ยท BSD
- centos-stream 10: rpcgen 1.4-17.el10 ยท BSD and LGPLv2+
- centos-stream 9: rpcgen 1.4-9.el9 ยท BSD and LGPLv2+
- debian bookworm: rpcsvc-proto 1.4.3-1 ยท BSD-3-Clause
- debian trixie: rpcsvc-proto 1.4.3-1 ยท BSD-3-Clause
- fedora 43: rpcgen 1.4-18.fc43 ยท LicenseRef-Callaway-BSD AND LicenseRef-Callaway-LGPLv2+
- fedora 44: rpcgen 1.4-19.fc44 ยท LicenseRef-Callaway-BSD AND LicenseRef-Callaway-LGPLv2+
- nixpkgs unstable: rpcsvc-proto 1.4.4
- opensuse-leap 16.0: rpcgen 1.4.4-160000.2.2 ยท BSD-3-Clause
- opensuse-leap 16.0: rpcgen 1.4.4-160000.2.2 ยท BSD-3-Clause
- opensuse-leap 16.0: rpcgen 1.4.4-160000.2.2 ยท BSD-3-Clause
- opensuse-leap 16.0: rpcgen 1.4.4-160000.2.2 ยท BSD-3-Clause
- ubuntu jammy: rpcsvc-proto 1.4.2-0ubuntu6 ยท BSD-3-Clause
- ubuntu noble: rpcsvc-proto 1.4.2-0ubuntu7 ยท BSD-3-Clause
- ubuntu questing: rpcsvc-proto 1.4.3-1 ยท BSD-3-Clause
- ubuntu resolute: rpcsvc-proto 1.4.3-1build1 ยท BSD-3-Clause
- ubuntu stonking: rpcsvc-proto 1.4.4-1 ยท BSD-3-Clause
- Copyright (c) 1988,1990 Sun Microsystems, Inc. - All Rights Reserved
- ๐ girlified by anthropic/claude-haiku-5.5 on : a language model's rewrite of the original, under its terms