home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 3 / goldfish_volume_3.bin / files / comm / tcp / amitcp / src / devtools / rpcgen / rpcgen.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-02  |  10.5 KB  |  233 lines

  1. RCS_ID_C="$Id: rpcgen.c,v 1.3 1994/05/02 19:34:31 jraja Exp $"
  2. /*
  3.  * rpcgen -- a SUN RPC language compiler
  4.  */
  5.  
  6. #include "rpcgen_rev.h"
  7.  
  8. const char version[] = VERSTAG;
  9.  
  10. /****** devtools.doc/rpcgen *************************************************
  11.  
  12.     NAME
  13.         rpcgen - an RPC protocol compiler
  14.  
  15.     SYNOPSIS
  16.         rpcgen infile
  17.         rpcgen [-Dname[=value]] [-T] [-K secs] infile
  18.         rpcgen -c|-h|-l|-m|-t [-o outfile ] infile
  19.         rpcgen [-I] -s nettype [-o outfile] infile
  20.         rpcgen -n netid [-o outfile] infile
  21.  
  22.     DESCRIPTION
  23.         rpcgen is a tool that generates C code to implement an RPC protocol.
  24.         The input to rpcgen is a language similar to C known as RPC Language
  25.         (Remote Procedure Call Language).
  26.  
  27.         rpcgen is normally used as in the first synopsis where it takes an
  28.         input file and generates up to four output files.  If the infile is
  29.         named proto.x, then rpcgen will generate a header file in proto.h,
  30.         XDR routines in proto_xdr.c, server-side stubs in proto_svc.c, and
  31.         client-side stubs in proto_clnt.c.  With the -T option, it will also
  32.         generate the RPC dispatch table in proto_tbl.i.  With the -Sc
  33.         option, it will also generate sample code which would illustrate how
  34.         to use the remote procedures on the client side. This code would be
  35.         created in proto_client.c.  With the -Ss option, it will also
  36.         generate a sample server code which would illustrate how to write
  37.         the remote procedures. This code would be created in proto_server.c.
  38.  
  39.         The server created can be started both by the port monitors (for
  40.         example, inetd or listen) or by itself.  When it is started by a
  41.         port monitor, it creates servers only for the transport for which
  42.         the file descriptor 0 was passed.  The name of the transport must be
  43.         specified by setting up the environmental variable PM_TRANSPORT.
  44.         When the server generated by rpcgen is executed, it creates server
  45.         handles for all the transports specified in NETPATH environment
  46.         variable, or if it is unset, it creates server handles for all the
  47.         visible transports from /etc/netconfig file.  Note: the transports
  48.         are chosen at run time and not at compile time.  When the server is
  49.         self-started, it backgrounds itself by default.  A special define
  50.         symbol RPC_SVC_FG can be used to run the server process in
  51.         foreground.
  52.  
  53.         The second synopsis provides special features which allow for the
  54.         creation of more sophisticated RPC servers.  These features include
  55.         support for user provided #defines and RPC dispatch tables.  The
  56.         entries in the RPC dispatch table contain:
  57.            +  pointers to the service routine corresponding to that
  58.               procedure,
  59.            +  a pointer to the input and output arguments
  60.            +  the size of these routines
  61.         A server can use the dispatch table to check authorization and then
  62.         to execute the service routine; a client library may use it to deal
  63.         with the details of storage management and XDR data conversion.
  64.  
  65.         The other three synopses shown above are used when one does not want
  66.         to generate all the output files, but only a particular one.  Some
  67.         examples of their usage is described in the EXAMPLE section below.
  68.         When rpcgen is executed with the -s option, it creates servers for
  69.         that particular class of transports.  When executed with the -n
  70.         option, it creates a server for the transport specified by netid.
  71.         If infile is not specified, rpcgen accepts the standard input.
  72.  
  73.         The C preprocessor, ccp, is run on the input file before it is
  74.         actually interpreted by rpcgen.  For each type of output file,
  75.         rpcgen defines a special preprocessor symbol for use by the rpcgen
  76.         programmer:
  77.  
  78.         RPC_HDR   defined when compiling into header files
  79.         RPC_XDR   defined when compiling into XDR routines
  80.         RPC_SVC   defined when compiling into server-side stubs
  81.         RPC_CLNT  defined when compiling into client-side stubs
  82.         RPC_TBL   defined when compiling into RPC dispatch tables
  83.  
  84.         Any line beginning with `%' is passed directly into the output file,
  85.         uninterpreted by rpcgen.
  86.  
  87.         For every data type referred to in infile, rpcgen assumes that there
  88.         exists a routine with the string xdr_ prepended to the name of the
  89.         data type.  If this routine does not exist in the RPC/XDR library,
  90.         it must be provided.  Providing an undefined data type allows
  91.         customization of XDR routines.
  92.  
  93.         The following options are available:
  94.  
  95.         -a   Generate all the files including sample code for client and
  96.              server side.
  97.  
  98.         -b   This generates code for the SunOS4.1 style of rpc. It is for
  99.              backward compatibilty.  This is the default.
  100.  
  101.         -5   This generates code for the SysVr4 style of rpc. It is used by
  102.              the Transport Independent RPC that is in Svr4 systems.  By
  103.              default rpcgen generates code for SunOS4.1 stype of rpc.
  104.  
  105.         -c   Compile into XDR routines.
  106.  
  107.         -C   Generate code in ANSI C. This option also generates code that
  108.              could be compiled with the C++ compiler.  This is the default.
  109.  
  110.         -k   Generate code in K&R C.  The default is ANSI C.
  111.  
  112.         -Dname[=value]
  113.              Define a symbol name.  Equivalent to the #define directive in the
  114.              source.  If no value is given, value is defined as 1.  This
  115.              option may be specified more than once.
  116.  
  117.         -h   Compile into C data-definitions (a header file).  -T option can
  118.              be used in conjunction to produce a header file which supports
  119.              RPC dispatch tables.
  120.  
  121.         -I  Generate a service that can be started from inetd.  The default
  122.              is to generate a static service that handles transports
  123.              selected with -s.  Using -I allows starting a service by either
  124.              method.
  125.  
  126.         -K secs
  127.              By default, services created using rpcgen wait 120 seconds
  128.              after servicing a request before exiting.  That interval can be
  129.              changed using the -K flag.  To create a server that exits
  130.              immediately upon servicing a request, -K 0 can be used.  To
  131.              create a server that never exits, the appropriate argument is
  132.              -K -1.
  133.  
  134.              When monitoring for a server, some portmonitors, like
  135.              listen(1M), always spawn a new process in response to a service
  136.              request.  If it is known that a server will be used with such a
  137.              monitor, the server should exit immediately on completion.  For
  138.              such servers, rpcgen should be used with -K -1.
  139.  
  140.         -l   Compile into client-side stubs.
  141.  
  142.         -m   Compile into server-side stubs, but do not generate a main
  143.              routine.  This option is useful for doing callback-routines and
  144.              for users who need to write their own main routine to do
  145.              initialization.
  146.  
  147.         -n netid
  148.              Compile into server-side stubs for the transport specified by
  149.              netid.  There should be an entry for netid in the netconfig
  150.              database.  This option may be specified more than once, so as
  151.              to compile a server that serves multiple transports.
  152.  
  153.         -N   Use the newstyle of rpcgen. This allows procedures to have
  154.              multiple arguments. It also uses the style of parameter passing
  155.              that closely resembles C. So, when passing an argument to a
  156.              remote procedure you do not have to pass a pointer to the
  157.              argument but the argument itself. This behaviour is different
  158.              from the oldstyle of rpcgen generated code. The newstyle is not
  159.              the default case because of backward compatibility.
  160.  
  161.         -o outfile
  162.              Specify the name of the output file.  If none is specified,
  163.              standard output is used (-c, -h, -l, -m, -n, -s, -sSc, -sSs and
  164.              -t modes only).
  165.  
  166.         -s nettype
  167.              Compile into server-side stubs for all the transports belonging
  168.              to the class nettype.  The supported classes are netpath,
  169.              visible, circuit_n, circuit_v, datagram_n, datagram_v, tcp, and
  170.              udp [see rpc(3N) for the meanings associated with these
  171.              classes].  This option may be specified more than once.  Note:
  172.              the transports are chosen at run time and not at compile time.
  173.  
  174.         -Sc  Generate sample code to show the use of remote procedure and
  175.              how to bind to the server before calling the client side stubs
  176.              generated by rpcgen.
  177.  
  178.         -Ss  Generate skeleton code for the remote procedures on the server
  179.              side. You would need to fill in the actual code for the remote
  180.              procedures.
  181.  
  182.         -t   Compile into RPC dispatch table.
  183.  
  184.         -T   Generate the code to support RPC dispatch tables.
  185.  
  186.         The options -c, -h, -l, -m, -s and -t are used exclusively to generate
  187.         a particular type of file, while the options -D and -T are global and
  188.         can be used with the other options.
  189.  
  190.     NOTES
  191.         The RPC Language does not support nesting of structures.  As a work-
  192.         around, structures can be declared at the top-level, and their name
  193.         used inside other structures in order to achieve the same effect.
  194.  
  195.         Name clashes can occur when using program definitions, since the
  196.         apparent scoping does not really apply.  Most of these can be
  197.         avoided by giving unique names for programs, versions, procedures
  198.         and types.
  199.  
  200.         The server code generated with -n option refers to the transport
  201.         indicated by netid and hence is very site specific.
  202.  
  203.     EXAMPLE
  204.         The following example:
  205.  
  206.            $ rpcgen -T prot.x
  207.  
  208.         generates the five files: prot.h, prot_clnt.c, prot_svc.c,
  209.         prot_xdr.c and prot_tbl.i.
  210.  
  211.         The following example sends the C data-definitions (header file) to
  212.         the standard output.
  213.  
  214.            $ rpcgen -h prot.x
  215.  
  216.         To send the test version of the -DTEST, server side stubs for all
  217.         the transport belonging to the class datagram_n to standard output,
  218.         use:
  219.  
  220.            $ rpcgen -s datagram_n -DTEST prot.x
  221.  
  222.         To create the server side stubs for the transport indicated by netid
  223.         tcp, use:
  224.  
  225.            $ rpcgen -n tcp -o prot_svc.c prot.x
  226.  
  227.     SEE ALSO
  228.         devtools.doc/cpp
  229.  
  230. *****************************************************************************
  231. */
  232.