home *** CD-ROM | disk | FTP | other *** search
Text File | 1986-11-30 | 32.3 KB | 1,634 lines |
- .LP
- In order to do an RPC callback,
- you need a program number to make the RPC call on.
- Since this will be a dynamically generated program number,
- it should be in the transient range, 0x40000000 - 0x5fffffff.
- The routine
- .LW gettransient()
- returns a valid program number in the transient range,
- and registers it with the portmapper.
- It only talks to the portmapper running on the same machine as the
- .LW gettransient()
- routine itself.
- The call to
- .LW pmap_set()
- is a test and set operation,
- in that it indivisibly tests whether a program number
- has already been registered,
- and if it has not, then reserves it.
- On return, the
- .LW sockp
- argument will contain a socket that can be used
- as the argument to an
- .LW svcudp_create()
- or
- .LW svctcp_create()
- call.
- .BS
- .LS no
- #include <stdio.h>
- #include <rpc/rpc.h>
- #include <sys/socket.h>
- .sp.5
- gettransient(proto, vers, sockp)
- int proto, vers, *sockp;
- {
- static int prognum = 0x40000000;
- int s, len, socktype;
- struct sockaddr_in addr;
- .sp.5
- switch(proto) {
- case IPPROTO_UDP:
- socktype = SOCK_DGRAM;
- break;
- case IPPROTO_TCP:
- socktype = SOCK_STREAM;
- break;
- default:
- fprintf(stderr, "unknown protocol type\en");
- return 0;
- }
- if (*sockp == RPC_ANYSOCK) {
- if ((s = socket(AF_INET, socktype, 0)) < 0) {
- perror("socket");
- return (0);
- }
- *sockp = s;
- }
- else
- s = *sockp;
- addr.sin_addr.s_addr = 0;
- addr.sin_family = AF_INET;
- addr.sin_port = 0;
- len = sizeof(addr);
- /*
- * may be already bound, so don't check for error
- */
- bind(s, &addr, len);
- if (getsockname(s, &addr, &len)< 0) {
- perror("getsockname");
- return (0);
- }
- while (!pmap_set(prognum++, vers, proto, addr.sin_port))
- continue;
- return (prognum-1);
- }
- .Lf
- .BE
- The following pair of programs illustrate how to use the
- .LW gettransient()
- routine.
- The client makes an RPC call to the server,
- passing it a transient program number.
- Then the client waits around to receive a callback
- from the server at that program number.
- The server registers the program
- .LW EXAMPLEPROG ,
- so that it can receive the RPC call
- informing it of the callback program number.
- Then at some random time (on receiving an
- .LW ALRM
- signal in this example), it sends a callback RPC call,
- using the program number it received earlier.
- .BS
- .LS no
- /*
- * client
- */
- #include <stdio.h>
- #include <rpc/rpc.h>
- .sp.5
- int callback();
- char hostname[256];
- .sp.5
- main(argc, argv)
- char **argv;
- {
- int x, ans, s;
- SVCXPRT *xprt;
- .sp.5
- gethostname(hostname, sizeof(hostname));
- s = RPC_ANYSOCK;
- x = gettransient(IPPROTO_UDP, 1, &s);
- fprintf(stderr, "client gets prognum %d\en", x);
- if ((xprt = svcudp_create(s)) == NULL) {
- fprintf(stderr, "rpc_server: svcudp_create\en");
- exit(1);
- }
- /* protocol is 0 - gettransient() does registering
- */
- (void)svc_register(xprt, x, 1, callback, 0);
- ans = callrpc(hostname, EXAMPLEPROG, EXAMPLEVERS,
- EXAMPLEPROC_CALLBACK, xdr_int, &x, xdr_void, 0);
- if (ans != RPC_SUCCESS) {
- fprintf(stderr, "call: ");
- clnt_perrno(ans);
- fprintf(stderr, "\en");
- }
- svc_run();
- fprintf(stderr, "Error: svc_run shouldn't return\en");
- }
- .sp.5
- callback(rqstp, transp)
- register struct svc_req *rqstp;
- register SVCXPRT *transp;
- {
- switch (rqstp->rq_proc) {
- case 0:
- if (!svc_sendreply(transp, xdr_void, 0)) {
- fprintf(stderr, "err: rusersd\en");
- exit(1);
- }
- exit(0);
- case 1:
- if (!svc_getargs(transp, xdr_void, 0)) {
- svcerr_decode(transp);
- exit(1);
- }
- fprintf(stderr, "client got callback\en");
- if (!svc_sendreply(transp, xdr_void, 0)) {
- fprintf(stderr, "err: rusersd");
- exit(1);
- }
- }
- }
- .sp.5
- /*
- * server
- */
- #include <stdio.h>
- #include <rpc/rpc.h>
- #include <sys/signal.h>
- .sp.5
- char *getnewprog();
- char hostname[256];
- int docallback();
- int pnum; /* program number for callback routine */
- .sp.5
- main(argc, argv)
- char **argv;
- {
- gethostname(hostname, sizeof(hostname));
- registerrpc(EXAMPLEPROG, EXAMPLEVERS,
- EXAMPLEPROC_CALLBACK, getnewprog, xdr_int, xdr_void);
- fprintf(stderr, "server going into svc_run\en");
- signal(SIGALRM, docallback);
- alarm(10);
- svc_run();
- fprintf(stderr, "Error: svc_run shouldn't return\en");
- }
- .sp.5
- char *
- getnewprog(pnump)
- char *pnump;
- {
- pnum = *(int *)pnump;
- return NULL;
- }
- .sp.5
- docallback()
- {
- int ans;
- .sp.5
- ans = callrpc(hostname, pnum, 1, 1, xdr_void, 0,
- xdr_void, 0);
- if (ans != 0) {
- fprintf(stderr, "server: ");
- clnt_perrno(ans);
- fprintf(stderr, "\en");
- }
- }
- .Lf
- .BE
- .SH
- Appendix A: Synopsis of RPC Routines
- .SH
- auth_destroy()
- .LP
- .BS
- .LS
- void
- auth_destroy(auth)
- AUTH *auth;
- .Lf
- .BE
- A macro that destroys the authentication information associated with
- .LW auth .
- Destruction usually involves deallocation
- of private data structures. The use of
- .LW auth
- is undefined after calling
- .LW auth_destroy() .
- .SH
- authnone_create()
- .LP
- .BS
- .LS
- AUTH *
- authnone_create()
- .Lf
- .BE
- Creates and returns an RPC authentication handle that passes no
- usable authentication information with each remote procedure call.
- .SH
- authunix_create()
- .LP
- .BS
- .LS
- AUTH *
- authunix_create(host, uid, gid, len, aup_gids)
- char *host;
- int uid, gid, len, *aup_gids;
- .Lf
- .BE
- Creates and returns an RPC authentication handle that contains
- .UX
- authentication information.
- The parameter
- .LW host
- is the name of the machine on which the information was created;
- .LW uid
- is the user's user ID;
- .LW gid
- is the user's current group ID;
- .LW len
- and
- .LW aup_gids
- refer to a counted array of groups to which the user belongs.
- It is easy to impersonate a user.
- .SH
- authunix_create\%_default()
- .LP
- .BS
- .LS
- AUTH *
- authunix_create_default()
- .Lf
- .BE
- Calls
- .LW authunix_create()
- with the appropriate parameters.
- .SH
- callrpc()
- .LP
- .BS
- .LS
- callrpc(host,prognum,versnum,procnum,inproc,in,outproc,out)
- char *host;
- u_long prognum, versnum, procnum;
- char *in, *out;
- xdrproc_t inproc, outproc;
- .Lf
- .BE
- Calls the remote procedure associated with
- .LW prognum ,
- .LW versnum ,
- and
- .LW procnum
- on the machine,
- .LW host .
- The parameter
- .LW in
- is the address of the procedure's argument(s), and
- .LW out
- is the address of where to place the result(s);
- .LW inproc
- is used to encode the procedure's parameters, and
- .LW outproc
- is used to decode the procedure's results.
- This routine returns zero if it succeeds, or the value of
- .LW "enum clnt_stat"
- cast to an integer if it fails.
- The routine
- .LW clnt_perrno()
- is handy for translating failure statuses into messages.
- Warning: calling remote procedures with this routine
- uses UDP/IP as a transport; see
- .LW clntudp_create()
- for restrictions.
- .SH
- clnt_broadcast()
- .LP
- .BS
- .LS
- enum clnt_stat
- clnt_broadcast(prognum, versnum, procnum,
- inproc, in, outproc, out, eachresult)
- u_long prognum, versnum, procnum;
- char *in, *out;
- xdrproc_t inproc, outproc;
- resultproc_t eachresult;
- .Lf
- .BE
- Like
- .LW callrpc() ,
- except the call message is broadcast to all locally connected broadcast nets.
- Each time it receives a response, this routine calls
- .LW eachresult() ,
- whose form is
- .BS
- .LS
- eachresult(out, addr)
- char *out;
- struct sockaddr_in *addr;
- .Lf
- .BE
- where
- .LW out
- is the same as
- .LW out
- passed to
- .LW clnt_broadcast() ,
- except that the remote procedure's output is decoded there;
- .LW addr
- points to the address of the machine that sent the results. If
- .LW eachresult()
- returns zero,
- .LW clnt_broadcast()
- waits for more replies;
- otherwise it returns with appropriate status.
- .SH
- clnt_call()
- .LP
- .BS
- .LS
- enum clnt_stat
- clnt_call(clnt, procnum, inproc, in, outproc, out, tout)
- CLIENT *clnt; long procnum;
- xdrproc_t inproc, outproc;
- char *in, *out;
- struct timeval tout;
- .Lf
- .BE
- A macro that calls the remote procedure
- .LW procnum
- associated with the client handle,
- .LW clnt ,
- which is obtained with an RPC client creation routine such as
- .LW clntudp_create() .
- The parameter
- .LW in
- is the address of the procedure's argument(s), and
- .LW out
- is the address of where to place the result(s);
- .LW inproc
- is used to encode the procedure's parameters, and
- .LW outproc
- is used to decode the procedure's results;
- .LW tout
- is the time allowed for results to come back.
- .SH
- clnt_destroy()
- .LP
- .BS
- .LS
- clnt_destroy(clnt)
- CLIENT *clnt;
- .Lf
- .BE
- A macro that destroys the client's RPC handle.
- Destruction usually involves deallocation
- of private data structures, including
- .LW clnt
- itself. Use of
- .LW clnt
- is undefined after calling
- .LW clnt_destroy() .
- It is the user's responsibility to close sockets associated with
- .LW clnt .
- .SH
- clnt_freeres()
- .LP
- .BS
- .LS
- clnt_freeres(clnt, outproc, out)
- CLIENT *clnt;
- xdrproc_t outproc;
- char *out;
- .Lf
- .BE
- A macro that frees any data allocated by the RPC/XDR system
- when it decoded the results of an RPC call.
- The parameter
- .LW out
- is the address of the results, and
- .LW outproc
- is the XDR routine describing the results in simple primitives.
- This routine returns one if the results were successfully freed,
- and zero otherwise.
- .SH
- clnt_geterr()
- .LP
- .BS
- .LS
- void
- clnt_geterr(clnt, errp)
- CLIENT *clnt;
- struct rpc_err *errp;
- .Lf
- .BE
- A macro that copies the error structure out of the client handle
- to the structure at address
- .LW errp .
- .SH
- clnt_pcreateerror()
- .LP
- .BS
- .LS
- void
- clnt_pcreateerror(s)
- char *s;
- .Lf
- .BE
- Prints a message to standard error indicating
- why a client RPC handle could not be created.
- The message is prepended with string
- .LW s
- and a colon.
- Used after a
- .LW clntraw_create() ,
- .LW clnttcp_create() ,
- or
- .LW clntudp_create()
- call.
- .SH
- clnt_perrno()
- .LP
- .BS
- .LS
- void
- clnt_perrno(stat)
- enum clnt_stat stat;
- .Lf
- .BE
- Prints a message to standard error corresponding
- to the condition indicated by
- .LW stat .
- Used after
- .LW callrpc() .
- .SH
- clnt_perror()
- .LP
- .BS
- .LS
- clnt_perror(clnt, s)
- CLIENT *clnt;
- char *s;
- .Lf
- .BE
- Prints a message to standard error indicating why an RPC call failed;
- .LW clnt
- is the handle used to do the call.
- The message is prepended with string
- .LW s
- and a colon.
- Used after
- .LW clnt_call() .
- .SH
- clntraw_create()
- .LP
- .BS
- .LS
- CLIENT *
- clntraw_create(prognum, versnum)
- u_long prognum, versnum;
- .Lf
- .BE
- This routine creates a toy RPC client for the remote program
- .LW prognum ,
- version
- .LW versnum .
- The transport used to pass messages to the service
- is actually a buffer within the process's address space,
- so the corresponding RPC server should live in the same address space; see
- .LW svcraw_create() .
- This allows simulation of RPC and acquisition of RPC overheads,
- such as round trip times, without any kernel interference.
- This routine returns
- .LW NULL
- if it fails.
- .SH
- clnttcp_create()
- .LP
- .BS
- .LS
- CLIENT *
- clnttcp_create(addr,prognum,versnum,sockp,sendsz,recvsz)
- struct sockaddr_in *addr;
- u_long prognum, versnum;
- int *sockp;
- u_int sendsz, recvsz;
- .Lf
- .BE
- This routine creates an RPC client for the remote program
- .LW prognum ,
- version
- .LW versnum ;
- the client uses TCP/IP as a transport.
- The remote program is located at Internet address
- .LW *addr .
- If
- .LW addr->sin_port
- is zero, then it is set to the actual port that the remote
- program is listening on (the remote
- .I portmap
- service is consulted for this information).
- The parameter
- .LW *sockp
- is a socket; if it is
- .LW RPC_ANYSOCK ,
- then this routine opens a new one and sets
- .LW *sockp .
- Since TCP-based RPC uses buffered I/O, the user may specify
- the size of the send and receive buffers with the parameters
- .LW sendsz
- and
- .LW recvsz ;
- values of zero choose suitable defaults.
- This routine returns
- .LW NULL
- if it fails.
- .SH
- clntudp_create()
- .LP
- .BS
- .LS
- CLIENT *
- clntudp_create(addr, prognum, versnum, wait, sockp)
- struct sockaddr_in *addr;
- u_long prognum, versnum;
- struct timeval wait;
- int *sockp;
- .Lf
- .BE
- This routine creates an RPC client for the remote program
- .LW prognum ,
- version
- .LW versnum ;
- the client uses use UDP/IP as a transport.
- The remote program is located at Internet address
- .LW *addr .
- If
- .LW addr->sin_port
- is zero, then it is set to actual port that the remote
- program is listening on (the remote
- .I portmap
- service is consulted for this information).
- The parameter
- .LW *sockp
- is a socket; if it is
- .LW RPC_ANYSOCK ,
- then this routine opens a new one and sets
- .LW *sockp .
- The UDP transport resends the call message in intervals of
- .LW wait
- time until a response is received or until the call times out.
- The total time for the call to time out is specified by
- .LW clnt_call() .
- Warning: since UDP-based RPC messages can only hold up to 8 Kbytes
- of encoded data, this transport cannot be used for procedures
- that take large arguments or return huge results.
- .SH
- get_myaddress()
- .LP
- .BS
- .LS
- void
- get_myaddress(addr)
- struct sockaddr_in *addr;
- .Lf
- .BE
- Stuffs the machine's IP address into
- .LW *addr ,
- without consulting the library routines that deal with
- .I /etc/hosts .
- The port number is always set to
- .LW htons(PMAPPORT) .
- .SH
- pmap_getmaps()
- .LP
- .BS
- .LS
- struct pmaplist *
- pmap_getmaps(addr)
- struct sockaddr_in *addr;
- .Lf
- .BE
- A user interface to the
- .I portmap
- service, which returns a list of the current RPC program-to-port mappings
- on the host located at IP address
- .LW *addr .
- This routine can return
- .LW NULL .
- The command
- .LW "rpcinfo -p"
- uses this routine.
- .SH
- pmap_getport()
- .LP
- .BS
- .LS
- u_short
- pmap_getport(addr, prognum, versnum, protocol)
- struct sockaddr_in *addr;
- u_long prognum, versnum, protocol;
- .Lf
- .BE
- A user interface to the
- .I portmap
- service, which returns the port number
- on which waits a service that supports program number
- .LW prognum ,
- version
- .LW versnum ,
- and speaks the transport protocol associated with protocol.
- A return value of zero means that the mapping does not exist or that
- the RPC system failured to contact the remote
- .I portmap
- service. In the latter case, the global variable
- .LW rpc_createerr
- contains the RPC status.
- .SH
- pmap_rmtcall()
- .LP
- .BS
- .LS
- enum clnt_stat
- pmap_rmtcall(addr, prognum, versnum, procnum,
- inproc, in, outproc, out, tout, portp)
- struct sockaddr_in *addr;
- u_long prognum, versnum, procnum;
- char *in, *out;
- xdrproc_t inproc, outproc;
- struct timeval tout;
- u_long *portp;
- .Lf
- .BE
- A user interface to the
- .I portmap
- service, which instructs
- .I portmap
- on the host at IP address
- .LW *addr
- to make an RPC call on your behalf to a procedure on that host.
- The parameter
- .LW *portp
- will be modified to the program's port number if the procedure succeeds.
- The definitions of other parameters are discussed in
- .LW callrpc()
- and
- .LW clnt_call() .
- This procedure should be used for a ``ping'' and nothing else.
- See also
- .LW clnt_broadcast() .
- .SH
- pmap_set()
- .LP
- .BS
- .LS
- pmap_set(prognum, versnum, protocol, port)
- u_long prognum, versnum, protocol;
- u_short port;
- .Lf
- .BE
- A user interface to the
- .I portmap
- service, which establishes a mapping between the triple
- .LW [prognum,versnum,protocol]
- and
- .LW port
- on the machine's
- .I portmap
- service. The value of protocol is most likely
- .LW IPPROTO_UDP
- or
- .LW IPPROTO_TCP .
- This routine returns one if it succeeds, zero otherwise.
- Automatically done by
- .LW svc_register() .
- .SH
- pmap_unset()
- .LP
- .BS
- .LS
- pmap_unset(prognum, versnum)
- u_long prognum, versnum;
- .Lf
- .BE
- A user interface to the
- .I portmap
- service, which destroys all mappings between the triple
- .LW [prognum,versnum,*]
- and
- .LW ports
- on the machine's
- .I portmap
- service.
- This routine returns one if it succeeds, zero otherwise.
- .SH
- registerrpc()
- .LP
- .BS
- .LS
- registerrpc(prognum,versnum,procnum,procname,inproc,outproc)
- u_long prognum, versnum, procnum;
- char *(*procname)();
- xdrproc_t inproc, outproc;
- .Lf
- .BE
- Registers procedure
- .LW procname
- with the RPC service package. If a request arrives for program
- .LW prognum ,
- version
- .LW versnum ,
- and procedure
- .LW procnum ,
- .LW procname
- is called with a pointer to its parameter(s);
- .LW progname
- should return a pointer to its static result(s);
- .LW inproc
- is used to decode the parameters while
- .LW outproc
- is used to encode the results.
- This routine returns zero if the registration succeeded, \-1 otherwise.
- Warning: remote procedures registered in this form
- are accessed using the UDP/IP transport; see
- .LW svcudp_create()
- for restrictions.
- .SH
- rpc_createerr
- .LP
- .BS
- .LS
- struct rpc_createerr rpc_createerr;
- .Lf
- .BE
- A global variable whose value is set by any RPC client creation routine
- that does not succeed. Use the routine
- .LW clnt_pcreateerror()
- to print the reason why.
- .SH
- svc_destroy()
- .LP
- .BS
- .LS
- svc_destroy(xprt)
- SVCXPRT *xprt;
- .Lf
- .BE
- A macro that destroys the RPC service transport handle,
- .LW xprt .
- Destruction usually involves deallocation
- of private data structures, including
- .LW xprt
- itself. Use of
- .LW xprt
- is undefined after calling this routine.
- .SH
- svc_fds
- .LP
- .BS
- .LS
- int svc_fds;
- .Lf
- .BE
- A global variable reflecting the RPC service side's
- read file descriptor bit mask; it is suitable as a parameter to the
- .LW select()
- system call. This is only of interest
- if a service implementor does not call
- .LW svc_run() ,
- but rather does his own asynchronous event processing.
- This variable is read-only (do not pass its address to
- .LW select() !),
- yet it may change after calls to
- .LW svc_getreq()
- or any creation routines.
- .SH
- svc_freeargs()
- .LP
- .BS
- .LS
- svc_freeargs(xprt, inproc, in)
- SVCXPRT *xprt;
- xdrproc_t inproc;
- char *in;
- .Lf
- .BE
- A macro that frees any data allocated by the RPC/XDR system
- when it decoded the arguments to a service procedure using
- .LW svc_getargs() .
- This routine returns one if the results were successfully freed,
- and zero otherwise.
- .SH
- svc_getargs()
- .LP
- .BS
- .LS
- svc_getargs(xprt, inproc, in)
- SVCXPRT *xprt;
- xdrproc_t inproc;
- char *in;
- .Lf
- .BE
- A macro that decodes the arguments of an RPC request
- associated with the RPC service transport handle,
- .LW xprt .
- The parameter
- .LW in
- is the address where the arguments will be placed;
- .LW inproc
- is the XDR routine used to decode the arguments.
- This routine returns one if decoding succeeds, and zero otherwise.
- .SH
- svc_getcaller()
- .LP
- .BS
- .LS
- struct sockaddr_in
- svc_getcaller(xprt)
- SVCXPRT *xprt;
- .Lf
- .BE
- The approved way of getting the network address of the caller
- of a procedure associated with the RPC service transport handle,
- .LW xprt .
- .SH
- svc_getreq()
- .LP
- .BS
- .LS
- svc_getreq(rdfds)
- int rdfds;
- .Lf
- .BE
- This routine is only of interest if a service implementor does not call
- .LW svc_run() ,
- but instead implements custom asynchronous event processing.
- It is called when the
- .LW select()
- system call has determined that an RPC request
- has arrived on some RPC socket(s);
- .LW rdfds
- is the resultant read file descriptor bit mask.
- The routine returns when all sockets associated with the value of
- .LW rdfds
- have been serviced.
- .SH
- svc_register()
- .LP
- .BS
- .LS
- svc_register(xprt, prognum, versnum, dispatch, protocol)
- SVCXPRT *xprt;
- u_long prognum, versnum;
- void (*dispatch)();
- u_long protocol;
- .Lf
- .BE
- Associates
- .LW prognum
- and
- .LW versnum
- with the service dispatch procedure,
- .LW dispatch() .
- If
- .LW protocol
- is zero, the service is not registered with the
- .I portmap
- service. If
- .LW protocol
- is non-zero, then a mapping of the triple
- .LW [prognum,versnum,protocol]
- to
- .LW xprt->xp_port
- is established with the local
- .I portmap
- service (generally
- .LW protocol
- is zero,
- .LW IPPROTO_UDP
- or
- .LW IPPROTO_TCP ).
- The procedure
- .LW dispatch()
- has the following form:
- .BS
- .LS
- dispatch(request, xprt)
- struct svc_req *request;
- SVCXPRT *xprt;
- .Lf
- .BE
- The
- .LW svc_register()
- routine returns one if it succeeds, and zero otherwise.
- .SH
- svc_run()
- .LP
- .BS
- .LS
- svc_run()
- .Lf
- .BE
- This routine never returns. It waits for RPC requests to arrive,
- and calls the appropriate service procedure using
- .LW svc_getreq()
- when one arrives. This procedure is usually waiting for a
- .LW select()
- system call to return.
- .SH
- svc_sendreply()
- .LP
- .BS
- .LS
- svc_sendreply(xprt, outproc, out)
- SVCXPRT *xprt;
- xdrproc_t outproc;
- char *out;
- .Lf
- .BE
- Called by an RPC service's dispatch routine
- to send the results of a remote procedure call.
- The parameter
- .LW xprt
- is the caller's associated transport handle;
- .LW outproc
- is the XDR routine which is used to encode the results; and
- .LW out
- is the address of the results.
- This routine returns one if it succeeds, zero otherwise.
- .SH
- svc_unregister()
- .LP
- .BS
- .LS
- void
- svc_unregister(prognum, versnum)
- u_long prognum, versnum;
- .Lf
- .BE
- Removes all mapping of the double
- .LW [prognum,versnum]
- to dispatch routines, and of the triple
- .LW [prognum,versnum,*]
- to port number.
- .SH
- svcerr_auth()
- .LP
- .BS
- .LS
- void
- svcerr_auth(xprt, why)
- SVCXPRT *xprt;
- enum auth_stat why;
- .Lf
- .BE
- Called by a service dispatch routine that refuses to perform
- a remote procedure call due to an authentication error.
- .SH
- svcerr_decode()
- .LP
- .BS
- .LS
- void
- svcerr_decode(xprt)
- SVCXPRT *xprt;
- .Lf
- .BE
- Called by a service dispatch routine that can't successfully
- decode its parameters. See also
- .LW svc_getargs() .
- .SH
- svcerr_noproc()
- .LP
- .BS
- .LS
- void
- svcerr_noproc(xprt)
- SVCXPRT *xprt;
- .Lf
- .BE
- Called by a service dispatch routine that doesn't implement
- the desired procedure number the caller request.
- .SH
- svcerr_noprog()
- .LP
- .BS
- .LS
- void
- svcerr_noprog(xprt)
- SVCXPRT *xprt;
- .Lf
- .BE
- Called when the desired program is not registered with the RPC package.
- Service implementors usually don't need this routine.
- .SH
- svcerr_progvers()
- .LP
- .BS
- .LS
- void
- svcerr_progvers(xprt)
- SVCXPRT *xprt;
- .Lf
- .BE
- Called when the desired version of a program is not registered
- with the RPC package.
- Service implementors usually don't need this routine.
- .SH
- svcerr_systemerr()
- .LP
- .BS
- .LS
- void
- svcerr_systemerr(xprt)
- SVCXPRT *xprt;
- .Lf
- .BE
- Called by a service dispatch routine when it detects a system error
- not covered by any particular protocol.
- For example, if a service can no longer allocate storage,
- it may call this routine.
- .SH
- svcerr_weakauth()
- .LP
- .BS
- .LS
- void
- svcerr_weakauth(xprt)
- SVCXPRT *xprt;
- .Lf
- .BE
- Called by a service dispatch routine that refuses to perform
- a remote procedure call due to insufficient (but correct)
- authentication parameters. The routine calls
- .LW svcerr_auth(xprt,AUTH_TOOWEAK) .
- .SH
- svcraw_create()
- .LP
- .BS
- .LS
- SVCXPRT *
- svcraw_create()
- .Lf
- .BE
- This routine creates a toy RPC service transport,
- to which it returns a pointer. The transport
- is really a buffer within the process's address space,
- so the corresponding RPC client should live in the same address space; see
- .LW clntraw_create() .
- This routine allows simulation of RPC and acquisition of RPC overheads
- (such as round trip times), without any kernel interference.
- This routine returns
- .LW NULL
- if it fails.
- .SH
- svctcp_create()
- .LP
- .BS
- .LS
- SVCXPRT *
- svctcp_create(sock, send_buf_size, recv_buf_size)
- int sock;
- u_int send_buf_size, recv_buf_size;
- .Lf
- .BE
- This routine creates a TCP/IP-based RPC service transport,
- to which it returns a pointer.
- The transport is associated with the socket
- .LW sock ,
- which may be
- .LW RPC_ANYSOCK ,
- in which case a new socket is created.
- If the socket is not bound to a local TCP port, then this routine
- binds it to an arbitrary port. Upon completion,
- .LW xprt->xp_sock
- is the transport's socket number, and
- .LW xprt->xp_port
- is the transport's port number.
- This routine returns
- .LW NULL
- if it fails. Since TCP-based RPC uses buffered I/O,
- users may specify the size of the
- .LW send
- and
- .LW receive
- buffers; values of zero choose suitable defaults.
- .SH
- svcudp_create()
- .LP
- .BS
- .LS
- SVCXPRT *
- svcudp_create(sock)
- int sock;
- .Lf
- .BE
- This routine creates a UDP/IP-based RPC service transport,
- to which it returns a pointer.
- The transport is associated with the socket
- .LW sock ,
- which may be
- .LW RPC_ANYSOCK ,
- in which case a new socket is created.
- If the socket is not bound to a local UDP port, then this routine
- binds it to an arbitrary port. Upon completion,
- .LW xprt->xp_sock
- is the transport's socket number, and
- .LW xprt->xp_port
- is the transport's port number.
- This routine returns
- .LW NULL
- if it fails.
- Warning: since UDP-based RPC messages can only hold up to 8 Kbytes
- of encoded data, this transport cannot be used for procedures
- that take large arguments or return huge results.
- .SH
- xdr_accepted_reply()
- .LP
- .BS
- .LS
- xdr_accepted_reply(xdrs, ar)
- XDR *xdrs;
- struct accepted_reply *ar;
- .Lf
- .BE
- Used for describing RPC messages, externally.
- This routine is useful for users who wish to generate
- RPC-style messages without using the RPC package.
- .SH
- xdr_array()
- .LP
- .BS
- .LS
- xdr_array(xdrs, arrp, sizep, maxsize, elsize, elproc)
- XDR *xdrs;
- char **arrp;
- u_int *sizep, maxsize, elsize;
- xdrproc_t elproc;
- .Lf
- .BE
- A filter primitive that translates between arrays
- and their corresponding external representations.
- The parameter
- .LW arrp
- is the address of the pointer to the array, while
- .LW sizep
- is the address of the element count of the array;
- this element count cannot exceed
- .LW maxsize .
- The parameter
- .LW elsize
- is the
- .LW sizeof()
- each of the array's elements, and
- .LW elproc
- is an XDR filter that translates between
- the array elements' C form, and their external representation.
- This routine returns one if it succeeds, zero otherwise.
- .SH
- xdr_authunix_parms()
- .LP
- .BS
- .LS
- xdr_authunix_parms(xdrs, aupp)
- XDR *xdrs;
- struct authunix_parms *aupp;
- .Lf
- .BE
- Used for describing UNIX credentials, externally.
- This routine is useful for users who wish to generate
- these credentials without using the RPC authentication package.
- .SH
- xdr_bool()
- .LP
- .BS
- .LS
- xdr_bool(xdrs, bp)
- XDR *xdrs;
- bool_t *bp;
- .Lf
- .BE
- A filter primitive that translates between booleans (C integers)
- and their external representations.
- When encoding data, this filter produces values of either one or zero.
- This routine returns one if it succeeds, zero otherwise.
- .SH
- xdr_bytes()
- .LP
- .BS
- .LS
- xdr_bytes(xdrs, sp, sizep, maxsize)
- XDR *xdrs;
- char **sp;
- u_int *sizep, maxsize;
- .Lf
- .BE
- A filter primitive that translates between counted byte strings
- and their external representations.
- The parameter
- .LW sp
- is the address of the string pointer.
- The length of the string is located at address
- .LW sizep ;
- strings cannot be longer than
- .LW maxsize .
- This routine returns one if it succeeds, zero otherwise.
- .SH
- xdr_callhdr()
- .LP
- .BS
- .LS
- void
- xdr_callhdr(xdrs, chdr)
- XDR *xdrs;
- struct rpc_msg *chdr;
- .Lf
- .BE
- Used for describing RPC messages, externally.
- This routine is useful for users who wish to generate
- RPC-style messages without using the RPC package.
- .SH
- xdr_callmsg()
- .LP
- .BS
- .LS
- xdr_callmsg(xdrs, cmsg)
- XDR *xdrs;
- struct rpc_msg *cmsg;
- .Lf
- .BE
- Used for describing RPC messages, externally.
- This routine is useful for users who wish to generate
- RPC-style messages without using the RPC package.
- .SH
- xdr_double()
- .LP
- .BS
- .LS
- xdr_double(xdrs, dp)
- XDR *xdrs;
- double *dp;
- .Lf
- .BE
- A filter primitive that translates between C
- .LW double
- precision numbers and their external representations.
- This routine returns one if it succeeds, zero otherwise.
- .SH
- xdr_enum()
- .LP
- .BS
- .LS
- xdr_enum(xdrs, ep)
- XDR *xdrs;
- enum_t *ep;
- .Lf
- .BE
- A filter primitive that translates between C
- .LW enum s
- (actually integers) and their external representations.
- This routine returns one if it succeeds, zero otherwise.
- .SH
- xdr_float()
- .LP
- .BS
- .LS
- xdr_float(xdrs, fp)
- XDR *xdrs;
- float *fp;
- .Lf
- .BE
- A filter primitive that translates between C
- .LW float s
- and their external representations.
- This routine returns one if it succeeds, zero otherwise.
- .SH
- xdr_inline()
- .LP
- .BS
- .LS
- long *
- xdr_inline(xdrs, len)
- XDR *xdrs;
- int len;
- .Lf
- .BE
- A macro that invokes the in-line routine associated with the XDR stream,
- .LW xdrs .
- The routine returns a pointer
- to a contiguous piece of the stream's buffer;
- .LW len
- is the byte length of the desired buffer.
- Note that pointer is cast to
- .LW "long *" .
- Warning:
- .LW xdr_inline()
- may return
- .LW NULL
- (0) if it cannot allocate a contiguous piece of a buffer.
- Therefore the behavior may vary among stream instances;
- it exists for the sake of efficiency.
- .SH
- xdr_int()
- .LP
- .BS
- .LS
- xdr_int(xdrs, ip)
- XDR *xdrs;
- int *ip;
- .Lf
- .BE
- A filter primitive that translates between C integers
- and their external representations.
- This routine returns one if it succeeds, zero otherwise.
- .SH
- xdr_long()
- .LP
- .BS
- .LS
- xdr_long(xdrs, lp)
- XDR *xdrs;
- long *lp;
- .Lf
- .BE
- A filter primitive that translates between C
- .LW long
- integers and their external representations.
- This routine returns one if it succeeds, zero otherwise.
- .SH
- xdr_opaque()
- .LP
- .BS
- .LS
- xdr_opaque(xdrs, cp, cnt)
- XDR *xdrs;
- char *cp;
- u_int cnt;
- .Lf
- .BE
- A filter primitive that translates between fixed size opaque data
- and its external representation.
- The parameter
- .LW cp
- is the address of the opaque object, and
- .LW cnt
- is its size in bytes.
- This routine returns one if it succeeds, zero otherwise.
- .SH
- xdr_opaque_auth()
- .LP
- .BS
- .LS
- xdr_opaque_auth(xdrs, ap)
- XDR *xdrs;
- struct opaque_auth *ap;
- .Lf
- .BE
- Used for describing RPC messages, externally.
- This routine is useful for users who wish to generate
- RPC-style messages without using the RPC package.
- .SH
- xdr_pmap()
- .LP
- .BS
- .LS
- xdr_pmap(xdrs, regs)
- XDR *xdrs;
- struct pmap *regs;
- .Lf
- .BE
- Used for describing parameters to various
- .I portmap
- procedures, externally.
- This routine is useful for users who wish to generate
- these parameters without using the
- .LW pmap
- interface.
- .SH
- xdr_pmaplist()
- .LP
- .BS
- .LS
- xdr_pmaplist(xdrs, rp)
- XDR *xdrs;
- struct pmaplist **rp;
- .Lf
- .BE
- Used for describing a list of port mappings, externally.
- This routine is useful for users who wish to generate
- these parameters without using the
- .LW pmap
- interface.
- .SH
- xdr_reference()
- .LP
- .BS
- .LS
- xdr_reference(xdrs, pp, size, proc)
- XDR *xdrs;
- char **pp;
- u_int size;
- xdrproc_t proc;
- .Lf
- .BE
- A primitive that provides pointer chasing within structures.
- The parameter
- .LW pp
- is the address of the pointer;
- .LW size
- is the
- .LW sizeof()
- the structure that
- .LW *pp
- points to; and
- .LW proc
- is an XDR procedure that filters the structure
- between its C form and its external representation.
- This routine returns one if it succeeds, zero otherwise.
- .SH
- xdr_rejected_reply()
- .LP
- .BS
- .LS
- xdr_rejected_reply(xdrs, rr)
- XDR *xdrs;
- struct rejected_reply *rr;
- .Lf
- .BE
- Used for describing RPC messages, externally.
- This routine is useful for users who wish to generate
- RPC-style messages without using the RPC package.
- .SH
- xdr_replymsg()
- .LP
- .BS
- .LS
- xdr_replymsg(xdrs, rmsg)
- XDR *xdrs;
- struct rpc_msg *rmsg;
- .Lf
- .BE
- Used for describing RPC messages, externally.
- This routine is useful for users who wish to generate
- RPC style messages without using the RPC package.
- .SH
- xdr_short()
- .LP
- .BS
- .LS
- xdr_short(xdrs, sp)
- XDR *xdrs;
- short *sp;
- .Lf
- .BE
- A filter primitive that translates between C
- .LW short
- integers and their external representations.
- This routine returns one if it succeeds, zero otherwise.
- .SH
- xdr_string()
- .LP
- .BS
- .LS
- xdr_string(xdrs, sp, maxsize)
- XDR *xdrs;
- char **sp;
- u_int maxsize;
- .Lf
- .BE
- A filter primitive that translates between C strings and their
- corresponding external representations.
- Strings cannot be longer than
- .LW maxsize .
- Note that
- .LW sp
- is the address of the string's pointer.
- This routine returns one if it succeeds, zero otherwise.
- .SH
- xdr_u_int()
- .LP
- .BS
- .LS
- xdr_u_int(xdrs, up)
- XDR *xdrs;
- unsigned *up;
- .Lf
- .BE
- A filter primitive that translates between C
- .LW unsigned
- integers and their external representations.
- This routine returns one if it succeeds, zero otherwise.
- .SH
- xdr_u_long()
- .LP
- .BS
- .LS
- xdr_u_long(xdrs, ulp)
- XDR *xdrs;
- unsigned long *ulp;
- .Lf
- .BE
- A filter primitive that translates between C
- .LW "unsigned long"
- integers and their external representations.
- This routine returns one if it succeeds, zero otherwise.
- .SH
- xdr_u_short()
- .LP
- .BS
- .LS
- xdr_u_short(xdrs, usp)
- XDR *xdrs;
- unsigned short *usp;
- .Lf
- .BE
- A filter primitive that translates between C
- .LW "unsigned short"
- integers and their external representations.
- This routine returns one if it succeeds, zero otherwise.
- .SH
- xdr_union()
- .LP
- .BS
- .LS
- xdr_union(xdrs, dscmp, unp, choices, dfault)
- XDR *xdrs;
- int *dscmp;
- char *unp;
- struct xdr_discrim *choices;
- xdrproc_t dfault;
- .Lf
- .BE
- A filter primitive that translates between a discriminated C
- .LW union
- and its corresponding external representation. The parameter
- .LW dscmp
- is the address of the union's discriminant, while
- .LW unp
- in the address of the union.
- This routine returns one if it succeeds, zero otherwise.
- .SH
- xdr_void()
- .LP
- .BS
- .LS
- xdr_void()
- .Lf
- .BE
- This routine always returns one.
- .SH
- xdr_wrapstring()
- .LP
- .BS
- .LS
- xdr_wrapstring(xdrs, sp)
- XDR *xdrs;
- char **sp;
- .Lf
- .BE
- A primitive that calls
- .LW xdr_string(xdrs,sp,MAXUNSIGNED);
- where
- .LW MAXUNSIGNED
- is the maximum value of an unsigned integer.
- This is handy because the RPC package passes
- only two parameters XDR routines, whereas
- .LW xdr_string() ,
- one of the most frequently used primitives, requires three parameters.
- This routine returns one if it succeeds, zero otherwise.
- .SH
- xprt_register()
- .LP
- .BS
- .LS
- void
- xprt_register(xprt)
- SVCXPRT *xprt;
- .Lf
- .BE
- After RPC service transport handles are created,
- they should register themselves with the RPC service package.
- This routine modifies the global variable
- .LW svc_fds .
- Service implementors usually don't need this routine.
- .SH
- xprt_unregister()
- .LP
- .BS
- .LS
- void
- xprt_unregister(xprt)
- SVCXPRT *xprt;
- .Lf
- .BE
- Before an RPC service transport handle is destroyed,
- it should unregister itself with the RPC service package.
- This routine modifies the global variable
- .LW svc_fds .
- Service implementors usually don't need this routine.
-