usage: rpcgen infile
rpcgen [-abkCLNTM][-Dname[=value]] [-i size] [-I [-K seconds]] [-Y path] infile
rpcgen [-c | -h | -l | -m | -t | -Sc | -Ss | -Sm] [-o outfile] [infile]
rpcgen [-s nettype]* [-o outfile] [infile]
rpcgen [-n netid]* [-o outfile] [infile]
options:
-a generate all files, including samples
-b backward compatibility mode (generates code for SunOS 4.1)
-c generate XDR routines
-C ANSI C mode
-Dname[=value] define a symbol (same as #define)
-h generate header file
-i size size at which to start generating inline code
-I generate code for inetd support in server (for SunOS 4.1)
-K seconds server exits after K seconds of inactivity
-l generate client side stubs
-L server errors will be printed to syslog
-m generate server side stubs
-M generate MT-safe code
-n netid generate server code that supports named netid
-N supports multiple arguments and call-by-value
-o outfile name of the output file
-s nettype generate server code that supports named nettype
-Sc generate sample client code that uses remote procedures
-Ss generate sample server code that defines remote procedures
-Sm generate makefile template
-t generate RPC dispatch table
-T generate code to support RPC dispatch tables
-Y path directory name to find C preprocessor (cpp)
For bug reporting instructions, please see:
usage: rpcgen infile
rpcgen [-abkCLNTM][-Dname[=value]] [-i size] [-I [-K seconds]] [-Y path] infile
rpcgen [-c | -h | -l | -m | -t | -Sc | -Ss | -Sm] [-o outfile] [infile]
rpcgen [-s nettype]* [-o outfile] [infile]
rpcgen [-n netid]* [-o outfile] [infile]
options:
-a generate all files, including samples
-b backward compatibility mode (generates code for SunOS 4.1)
-c generate XDR routines
-C ANSI C mode
-Dname[=value] define a symbol (same as #define)
-h generate header file
-i size size at which to start generating inline code
-I generate code for inetd support in server (for SunOS 4.1)
-K seconds server exits after K seconds of inactivity
-l generate client side stubs
-L server errors will be printed to syslog
-m generate server side stubs
-M generate MT-safe code
-n netid generate server code that supports named netid
-N supports multiple arguments and call-by-value
-o outfile name of the output file
-s nettype generate server code that supports named nettype
-Sc generate sample client code that uses remote procedures
-Ss generate sample server code that defines remote procedures
-Sm generate makefile template
-t generate RPC dispatch table
-T generate code to support RPC dispatch tables
-Y path directory name to find C preprocessor (cpp)
For bug reporting instructions, please see:
rpcgen(1) rpcgen(1)
名前
rpcgen - RPC プロトコルコンパイラ
書式
rpcgen infile
rpcgen [-Dname[=value]] [-T] [-K secs] infile
rpcgen -c|-h|-l|-m|-t [-o outfile ] infile
rpcgen [-I] -s nettype [-o outfile] infile
rpcgen -n netid [-o outfile] infile
説明
rpcgen は RPC プロトコルを実装する C 言語のコードを生成するツールである
。 rpcgen への入力は RPC 言語 (遠隔手続き呼び出し言語 Remote Procedure
Call Language) として知られる C 言語に似た言語である。
rpcgen は通常、1 つの入力ファイルを受け取って 4 つの出力ファイルを生成
する、第 1 の書式で使われる。入力ファイル infile が proto.x という名 前
である場合、 rpcgen はヘッダファイル proto.h、 XDR ルーチン proto_xdr.c
、サーバ側スタブ proto_svc.c、クライアント側スタブ proto_clnt.c を生 成
す る 。 -T オ プションを指定すると、さらに RPC ディスパッチテーブル
nproto_tbl.i も生成する。 -Sc オプションを指定すると、クライアント側 で
の 遠 隔 手続きの使用法を説明するサンプルコードも生成する。このコードは
proto_client.c に書き出される。 -Ss オプションを指定すると、遠隔手続 き
の 書 き 方 を 説明するサンプルのサーバ用コードを生成する。このコードは
proto_server.c に書き出される。
生成されたサーバは、ポートモニタ (例えば inetd や listen) で起動する こ
と も、それ自身で起動することもできる。ポートモニタで起動される場合、フ
ァイルディスクリプタ 0 を引き渡すトランスポートのためだけのサーバを生成
す る。トランスポートの名前は環境変数 PM_TRANSPORT を設定することで指定
しなければならない。 rpcgen で作成されたサーバが実行されると、サーバ は
環境変数 NETPATH で指定された全てのトランスポート用にサーバハンドルを生
成する。環境変数 NETPATH が設定されていない場合、 /etc/netconfig ファイ
ル に記述された全ての可視トランスポート用にサーバハンドルを生成する。注
意: トランスポートはコンパイル時ではなく実行時に選択される。サーバが 自
分 自身で開始する場合、デフォルトではバックグラウンド実行に移る。サーバ
プロセスをフォアグラウンドで実行するには、特殊定義シンボ ル RPC_SVC_FG
が使われる。
第 2 の書式は、より洗練された RPC サーバを生成する特別な機能を提供する
。これらの機能には、ユーザー定義の #define と RPC ディスパッチテーブ ル
のサポートが含まれる。 RPC ディスパッチテーブルのエントリには以下のもの
がある。
· その手続きに対応するサービスルーチンへのポインタ
· 入出力引き数へのポインタ
· これらのルーチンのサイズ
サーバは、認証をチェックした後にサービスルーチンを実行するために、デ ィ
ス パッチテーブルを使うことができる。クライアントライブラリは、記憶領域
管理と XDR データ変換を詳細に扱うために、ディスパッチテーブルを使うこと
ができる。
上 で示した他の 3 つの書式は、全ての出力ファイルではなく、特定の 1 つの
ファイルが必要な場合に使われる。いくつかの使用例が以下の「例」のセク シ
ョ ンで説明されている。 rpcgen が -s オプション付きで実行された場合、特
定クラスのトランスポート用のサーバを生成する。 -n オプション付きで実 行
さ れ た 場 合 、 netid で指定したトランスポート用のサーバを生成する。
infile が指定されていない場合、 rpcgen は標準入力から入力を受け付ける。
入力ファイルが rpcgen によって実際に処理される前に、C プリプロセッサ cc
-E [cc(1) を参照] が実行される。 rpcgen は各タイプの出力ファイルに対 し
て、 rpcgen プログラマが使う特別なプリプロセッサシンボルを定義する。
RPC_HDR ヘッダファイルにコンパイルする際に定義される。
RPC_XDR XDR ルーチンにコンパイルする際に定義される。
RPC_SVC サーバ側スタブにコンパイルする際に定義される。
RPC_CLNT クライアント側スタブにコンパイルする際に定義される。
RPC_TBL RPC ディスパッチテーブルにコンパイルする際に定義される。
‘%’ で始まる全ての行は、 rpcgen に解釈されることなく、出力ファイルに直
接そのまま渡される。
infile で参照される全てのデータタイプに対して、 rpcgen はデータタイプ名
の 前に xdr_ を付けた名前のルーチンが存在することを仮定する。このルーチ
ンが RPC/XDR ライブラリにない場合、そのルーチンを提供しなければならない
。未定義のデータタイプを提供することで XDR ルーチンをカスタマイズするこ
とができる。
以下のオプションが使用可能である。
-a クライアント側とサーバ側のサンプルコードを含む全てのファイルを生
成する。
-b SunOS4.1 スタイルの RPC コードを生成する。昔のコードとの互換性の
ためにある。これがデフォルトである。
-5 SysVr4 スタイルの RPC コードを生成する。これは Svr4 システムのト
ラ ンスポート独立 RPC (Transport Independent RPC) で使われる。デ
フォルトでは rpcgen は、SunOS4.1 スタイルの RPC コードを生成する
。
-c コンパイルして XDR ルーチンを生成する。
-C ANSI C のコードを生成する。このオプションは C++ コンパイラでもコ
ンパイルできるコードを生成する。これがデフォルトである。
-k K&R C のコードを生成する。デフォルトは ANSI C である。
-Dname[=value]
シンボル name を定義する。ソース中の #define ディレクティブと 同
じ 。 value が与えられていない場合、 value は 1 と定義される。こ
のオプションは複数回指定してもよい。
-h コンパイルして C 言語のデータ定義 (ヘッダファイル) を生成する 。
RPC ディスパッチテーブルをサポートするヘッダファイルを生成したい
場合は、 -T オプションを同時に指定すること。
-I inetd から起動できるサービスを生成する。デフォルトでは、-s オ プ
ションで選択されるトランスポートを処理する、静的サービスを生成す
る。 -I を使うことで、サービスをどちらの方法でも起動できるように
なる。
-K secs
デ フォルトでは、rpcgen で生成されたサービスは、リクエストを処理
した後 120 秒待って終了する。この待機時間は -K フラグを使って 変
更できる。リクエストを処理した後すぐに終了するサーバを生成するに
は、 -K 0 を指定すること。決して終了しないサーバを生成するには、
適切な引き数である -K -1 を指定すること。
サ ー バをモニタリングしている場合、ある種のポートモニタ、例えば
listen(1M) のようなものは、サービスリクエストに応答して 常に新し
いプロセスを生成する。サーバがそのようなモニタとともに使われるこ
とが分かっている場合、サーバは処理の完了後すぐに終了すべきである
。 そのようなサーバを生成するためには、 rpcgen を -K -1 オプショ
ン付きで使うべきである。
-l コンパイルしてクライアント側スタブを生成する。
-m コンパイルしてサーバ側スタブファイルを生成するが、 “main” ルーチ
ンは作成しない。このオプションは、コールバックルーチンを作成する
場合や、初期化を行うために独自の “main” ルーチンを記述する必要が
あるユーザーにとって役に立つ。
-n netid
コ ンパイルして netid で指定したトランスポート用のサーバ側スタブ
を生成する。 netconfig データベースに netid 用のエントリが存在す
る必要がある。複数のトランスポートに対してサービスを行うサーバを
作成するために、このオプションを複数回指定することができる。
-N 新しいスタイルの rpcgen を使う。手続きが複数の引き数を持てるよう
にする。これはまた、C 言語にとてもよく似たパラメータ渡しの方法を
用いる。これにより、遠隔手続きに引き数を渡す場合に、引き数へのポ
インタではなく引き数そのものを渡すことができる。この動作は、以前
のスタイルの rpcgen が生成したコードによるものとは異なる。以前の
ものとの互換性のため、新しいスタイルはデフォルトになっていない。
-o outfile
出力ファイル名を指定する。何も指定されない場合、標準出力に書き出
す (-c, -h, -l, -m, -n, -s, -Sc, -Ss, -t モード時のみ)。
-s nettype
コ ンパイルして nettype クラスに属する全てのトランスポート用のサ
ーバ側スタブを生成する。サポートされているクラスは以下の通りであ
る 。 netpath, visible, circuit_n, circuit_v, datagram_n, data-
gram_v, tcp, udp [これらのクラスに関連づけられた意味については、
rpc(3N) を参照すること]。このオプションは複数回指定することがで
きる。注意: トランスポートはコンパイル時ではなく実行時に選択され
る。
-Sc 遠隔手続きの使用法と、rpcgen で生成されたクライアント側スタブを
呼び出す前にサーバをバインドする方法を説明するサンプルコードを生
成する。
-Ss サーバ側遠隔手続きの骨組みとなるコードを生成する。遠隔手続きの実
際のコードを記述する必要がある。
-t コンパイルして RPC ディスパッチテーブルを生成する。
-T RPC ディスパッチテーブルをサポートするコードを生成する。
オプション -c, -h, -l, -m, -s, -t は、特定のタイプのファイルを生成す る
ために、どれか 1 つを単独で使う。一方、オプション -D と -T は、グローバ
ルオプションで、他のオプションとともに使うことができる。
注意
RPC 言語は構造体の入れ子構造をサポートしない。対処法として同様の効果 を
得 るために、構造体をトップレベルで宣言し、その構造体名を他の構造体の中
で使うことができる。
明確な名前スコープが実際に適応されていないため、プログラム定義の使用 中
に 名前の衝突が起きる場合がある。この問題の大部分は、プログラム・バージ
ョン・手続き・タイプに対して固有の名前を付けることで回避できる。
-n オプションで生成されたサーバ用コードは、 netid で指定されたトラン ス
ポートを参照するので、非常にサイト依存したものになる。
例
以下の例:
$ rpcgen -T prot.x
は 5 つ の フ ァ イ ル: prot.h, prot_clnt.c, prot_svc.c, prot_xdr.c,
prot_tbl.i を生成する。
以下の例では、C 言語のデータ定義 (ヘッダファイル) が標準出力に送られ る
。
$ rpcgen -h prot.x
datagram_n クラスに属する全トランスポート用のサーバ側スタブのテストバー
ジョン -DTEST を標準出力に書き出すためには、以下のようにすること:
$ rpcgen -s datagram_n -DTEST prot.x
netid tcp で指定されたトランスポート用のサーバ側スタブを生成するため に
は、以下のようにすること:
$ rpcgen -n tcp -o prot_svc.c prot.x
関連項目
cc(1)
翻訳者謝辞
こ の man ペ ー ジ の 翻 訳 に あ た り 、 FreeBSD jpman project
rpcgen(1) rpcgen(1) NAME rpcgen - an RPC protocol compiler SYNOPSIS rpcgen infile rpcgen [-Dname[=value]] [-T] [-K secs] infile rpcgen -c|-h|-l|-m|-t [-o outfile ] infile rpcgen [-I] -s nettype [-o outfile] infile rpcgen -n netid [-o outfile] infile DESCRIPTION rpcgen is a tool that generates C code to implement an RPC protocol. The input to rpcgen is a language similar to C known as RPC Language (Remote Procedure Call Language). rpcgen is normally used as in the first synopsis where it takes an input file and generates up to four output files. If the infile is named proto.x, then rpcgen will generate a header file in proto.h, XDR routines in proto_xdr.c, server-side stubs in proto_svc.c, and client- side stubs in proto_clnt.c. With the -T option, it will also generate the RPC dispatch table in proto_tbl.i. With the -Sc 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 proto_client.c. With the -Ss option, it will also generate a sample server code which would illustrate how to write the remote procedures. This code would be created in proto_server.c. The server created can be started both by the port monitors (for exam- ple, inetd or listen) or by itself. When it is started by a port moni- tor, 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 PM_TRANSPORT. When the server generated by rpcgen is executed, it creates server handles for all the transports specified in NETPATH environment variable, or if it is unset, it creates server handles for all the visible transports from /etc/netconfig 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 RPC_SVC_FG can be used to run the server process in foreground. The second synopsis provides special features which allow for the cre- ation of more sophisticated RPC servers. These features include sup- port for user provided #defines and RPC dispatch tables. The entries in the RPC dispatch table contain: · pointers to the service routine corresponding to that proce- dure, · a pointer to the input and output arguments · the size of these routines 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 XDR data conversion. 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 exam- ples of their usage is described in the EXAMPLE section below. When rpcgen is executed with the -s option, it creates servers for that par- ticular class of transports. When executed with the -n option, it cre- ates a server for the transport specified by netid. If infile is not specified, rpcgen accepts the standard input. The C preprocessor, cc -E [see cc(1)], is run on the input file before it is actually interpreted by rpcgen. For each type of output file, rpcgen defines a special preprocessor symbol for use by the rpcgen pro- grammer: RPC_HDR defined when compiling into header files RPC_XDR defined when compiling into XDR routines RPC_SVC defined when compiling into server-side stubs RPC_CLNT defined when compiling into client-side stubs RPC_TBL defined when compiling into RPC dispatch tables Any line beginning with ‘%’ is passed directly into the output file, uninterpreted by rpcgen. For every data type referred to in infile, rpcgen assumes that there exists a routine with the string xdr_ prepended to the name of the data type. If this routine does not exist in the RPC/XDR library, it must be provided. Providing an undefined data type allows customization of XDR routines. The following options are available: -a Generate all the files including sample code for client and server side. -b This generates code for the SunOS4.1 style of rpc. It is for backward compatibilty. This is the default. -5 This generates code for the SysVr4 style of rpc. It is used by the Transport Independent RPC that is in Svr4 systems. By default rpcgen generates code for SunOS4.1 stype of rpc. -c Compile into XDR routines. -C Generate code in ANSI C. This option also generates code that could be compiled with the C++ compiler. This is the default. -k Generate code in K&R C. The default is ANSI C. -Dname[=value] Define a symbol name. Equivalent to the #define directive in the source. If no value is given, value is defined as 1. This option may be specified more than once. -h Compile into C data-definitions (a header file). -T option can be used in conjunction to produce a header file which supports RPC dispatch tables. -I Generate a service that can be started from inetd. The default is to generate a static service that handles transports selected with -s. Using -I allows starting a service by either method. -K secs By default, services created using rpcgen wait 120 seconds after servicing a request before exiting. That interval can be changed using the -K flag. To create a server that exits imme- diately upon servicing a request, -K 0 can be used. To create a server that never exits, the appropriate argument is -K -1. When monitoring for a server, some portmonitors, like lis- ten(1M), 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, rpcgen should be used with -K -1. -l Compile into client-side stubs. -m Compile 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 ini- tialization. -n netid Compile into server-side stubs for the transport specified by netid. There should be an entry for netid in the netconfig database. This option may be specified more than once, so as to compile a server that serves multiple transports. -N Use the newstyle of rpcgen. This allows procedures to have mul- tiple 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 argu- ment but the argument itself. This behaviour is different from the oldstyle of rpcgen generated code. The newstyle is not the default case because of backward compatibility. -o outfile Specify the name of the output file. If none is specified, standard output is used (-c, -h, -l, -m, -n, -s, -s -sand -t modes only). -s nettype Compile into server-side stubs for all the transports belonging to the class nettype. The supported classes are netpath, visi- ble, circuit_n, circuit_v, datagram_n, datagram_v, tcp, and udp [see rpc(3N) for the meanings associated with these classes]. This option may be specified more than once. Note: the trans- ports are chosen at run time and not at compile time. -Sc Generate sample code to show the use of remote procedure and how to bind to the server before calling the client side stubs gen- erated by rpcgen. -Ss Generate skeleton code for the remote procedures on the server side. You would need to fill in the actual code for the remote procedures. -t Compile into RPC dispatch table. -T Generate the code to support RPC dispatch tables. The options -c, -h, -l, -m, -s and -t are used exclusively to generate a particular type of file, while the options -D and -T are global and can be used with the other options. NOTES The 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. Name clashes can occur when using program definitions, since the appar- ent scoping does not really apply. Most of these can be avoided by giving unique names for programs, versions, procedures and types. The server code generated with -n option refers to the transport indi- cated by netid and hence is very site specific. EXAMPLE The following example: $ rpcgen -T prot.x generates the five files: prot.h, prot_clnt.c, prot_svc.c, prot_xdr.c and prot_tbl.i. The following example sends the C data-definitions (header file) to the standard output. $ rpcgen -h prot.x To send the test version of the -DTEST, server side stubs for all the transport belonging to the class datagram_n to standard output, use: $ rpcgen -s datagram_n -DTEST prot.x To create the server side stubs for the transport indicated by netid tcp, use: $ rpcgen -n tcp -o prot_svc.c prot.x SEE ALSO gcc(1). 0a
Copyright(C) linux-cmd.com All Rights Reserved. Author Takayuki Yukawa