man-pages/man3/rpc.3.html
2021-03-31 01:06:50 +01:00

1853 lines
37 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of RPC</TITLE>
</HEAD><BODY>
<H1>RPC</H1>
Section: Linux Programmer's Manual (3)<BR>Updated: 2017-09-15<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
rpc - library routines for remote procedure calls
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS AND DESCRIPTION</H2>
These routines allow C programs to make procedure
calls on other machines across the network.
First, the client calls a procedure to send a data packet to the server.
Upon receipt of the packet, the server calls a dispatch routine
to perform the requested service, and then sends back a reply.
Finally, the procedure call returns to the client.
<P>
To take use of these routines, include the header file
<I>&lt;<A HREF="file:///usr/include/rpc/rpc.h">rpc/rpc.h</A>&gt;</I>.
<P>
The prototypes below make use of the following types:
<P>
<B>typedef int </B><I>bool_t</I><B>;</B>
<P>
<B>typedef bool_t (*</B><I>xdrproc_t</I><B>) (XDR *, void *, ...);</B>
<P>
<B>typedef bool_t (*</B><I>resultproc_t</I><B>) (caddr_t </B><I>resp</I><B>,</B>
<B> struct sockaddr_in *</B><I>raddr</I><B>);</B>
<P>
See the header files for the declarations of the
<I>AUTH</I>,
<I>CLIENT</I>,
<I>SVCXPRT</I>,
and
<I>XDR</I>
types.
<P>
<PRE>
<B>void auth_destroy(AUTH *</B><I>auth</I><B>);</B>
</PRE>
<DL COMPACT>
<DT id="1"><DD>
A macro that destroys the authentication information associated with
<I>auth</I>.
Destruction usually involves deallocation of private data structures.
The use of
<I>auth</I>
is undefined after calling
<B>auth_destroy</B>().
</DL>
<P>
<PRE>
<B>AUTH *authnone_create(void);</B>
</PRE>
<DL COMPACT>
<DT id="2"><DD>
Create and return an RPC
authentication handle that passes nonusable authentication
information with each remote procedure call.
This is the default authentication used by RPC.
</DL>
<P>
<PRE>
<B>AUTH *authunix_create(char *</B><I>host</I><B>, int </B><I>uid</I><B>, int </B><I>gid</I><B>,</B>
<B> int </B><I>len</I><B>, int *</B><I>aup_gids</I><B>);</B>
</PRE>
<DL COMPACT>
<DT id="3"><DD>
Create and return an RPC authentication handle that contains
authentication information.
The parameter
<I>host</I>
is the name of the machine on which the information was created;
<I>uid</I>
is the user's user ID;
<I>gid</I>
is the user's current group ID;
<I>len</I>
and
<I>aup_gids</I>
refer to a counted array of groups to which the user belongs.
It is easy to impersonate a user.
</DL>
<P>
<PRE>
<B>AUTH *authunix_create_default(void);</B>
</PRE>
<DL COMPACT>
<DT id="4"><DD>
Calls
<B>authunix_create</B>()
with the appropriate parameters.
</DL>
<P>
<PRE>
<B>int callrpc(char *</B><I>host</I><B>, unsigned long </B><I>prognum</I><B>,</B>
<B> unsigned long </B><I>versnum</I><B>, unsigned long </B><I>procnum</I><B>,</B>
<B> xdrproc_t </B><I>inproc</I><B>, char *</B><I>in</I><B>,</B>
<B> xdrproc_t </B><I>outproc</I><B>, char *</B><I>out</I><B>);</B>
</PRE>
<DL COMPACT>
<DT id="5"><DD>
Call the remote procedure associated with
<I>prognum</I>,
<I>versnum</I>,
and
<I>procnum</I>
on the machine,
<I>host</I>.
The parameter
<I>in</I>
is the address of the procedure's argument(s), and
<I>out</I>
is the address of where to place the result(s);
<I>inproc</I>
is used to encode the procedure's parameters, and
<I>outproc</I>
is used to decode the procedure's results.
This routine returns zero if it succeeds, or the value of
<B>enum clnt_stat</B>
cast to an integer if it fails.
The routine
<B>clnt_perrno</B>()
is handy for translating failure statuses into messages.
<DT id="6"><DD>
Warning: calling remote procedures with this routine
uses UDP/IP as a transport; see
<B>clntudp_create</B>()
for restrictions.
You do not have control of timeouts or authentication using this routine.
</DL>
<P>
<PRE>
<B>enum clnt_stat clnt_broadcast(unsigned long </B><I>prognum</I><B>,</B>
<B> unsigned long </B><I>versnum</I><B>, unsigned long </B><I>procnum</I><B>,</B>
<B> xdrproc_t </B><I>inproc</I><B>, char *</B><I>in</I><B>,</B>
<B> xdrproc_t </B><I>outproc</I><B>, char *</B><I>out</I><B>,</B>
<B> resultproc_t </B><I>eachresult</I><B>);</B>
</PRE>
<DL COMPACT>
<DT id="7"><DD>
Like
<B>callrpc</B>(),
except the call message is broadcast to all locally
connected broadcast nets.
Each time it receives a response, this routine calls
<B>eachresult</B>(),
whose form is:
<DT id="8"><DD>
<B>eachresult(char *</B><I>out</I><B>, struct sockaddr_in *</B><I>addr</I><B>);</B>
<DT id="9"><DD>
where
<I>out</I>
is the same as
<I>out</I>
passed to
<B>clnt_broadcast</B>(),
except that the remote procedure's output is decoded there;
<I>addr</I>
points to the address of the machine that sent the results.
If
<B>eachresult</B>()
returns zero,
<B>clnt_broadcast</B>()
waits for more replies; otherwise it returns with appropriate status.
<DT id="10"><DD>
Warning: broadcast sockets are limited in size to the
maximum transfer unit of the data link.
For ethernet, this value is 1500 bytes.
</DL>
<P>
<PRE>
<B>enum clnt_stat clnt_call(CLIENT *</B><I>clnt</I><B>, unsigned long </B><I>procnum</I><B>,</B>
<B> xdrproc_t </B><I>inproc</I><B>, char *</B><I>in</I><B>,</B>
<B> xdrproc_t </B><I>outproc</I><B>, char *</B><I>out</I><B>,</B>
<B> struct timeval </B><I>tout</I><B>);</B>
</PRE>
<DL COMPACT>
<DT id="11"><DD>
A macro that calls the remote procedure
<I>procnum</I>
associated with the client handle,
<I>clnt</I>,
which is obtained with an RPC client creation routine such as
<B>clnt_create</B>().
The parameter
<I>in</I>
is the address of the procedure's argument(s), and
<I>out</I>
is the address of where to place the result(s);
<I>inproc</I>
is used to encode the procedure's parameters, and
<I>outproc</I>
is used to decode the procedure's results;
<I>tout</I>
is the time allowed for results to come back.
</DL>
<P>
<PRE>
<B>clnt_destroy(CLIENT *</B><I>clnt</I><B>);</B>
</PRE>
<DL COMPACT>
<DT id="12"><DD>
A macro that destroys the client's RPC handle.
Destruction usually involves deallocation
of private data structures, including
<I>clnt</I>
itself.
Use of
<I>clnt</I>
is undefined after calling
<B>clnt_destroy</B>().
If the RPC library opened the associated socket, it will close it also.
Otherwise, the socket remains open.
</DL>
<P>
<PRE>
<B>CLIENT *clnt_create(char *</B><I>host</I><B>, unsigned long </B><I>prog</I><B>,</B>
<B> unsigned long </B><I>vers</I><B>, char *</B><I>proto</I><B>);</B>
</PRE>
<DL COMPACT>
<DT id="13"><DD>
Generic client creation routine.
<I>host</I>
identifies the name of the remote host where the server is located.
<I>proto</I>
indicates which kind of transport protocol to use.
The currently supported values for this field are "udp"
and "tcp".
Default timeouts are set, but can be modified using
<B>clnt_control</B>().
<DT id="14"><DD>
Warning: using UDP has its shortcomings.
Since UDP-based RPC messages can hold only up to 8 Kbytes of encoded data,
this transport cannot be used for procedures that take
large arguments or return huge results.
</DL>
<P>
<PRE>
<B>bool_t clnt_control(CLIENT *</B><I>cl</I><B>, int </B><I>req</I><B>, char *</B><I>info</I><B>);</B>
</PRE>
<DL COMPACT>
<DT id="15"><DD>
A macro used to change or retrieve various information
about a client object.
<I>req</I>
indicates the type of operation, and
<I>info</I>
is a pointer to the information.
For both UDP and TCP, the supported values of
<I>req</I>
and their argument types and what they do are:
<DT id="16"><DD>
<B>CLSET_TIMEOUT</B> <I>struct timeval</I> // set total timeout
<B>CLGET_TIMEOUT</B> <I>struct timeval</I> // get total timeout
<DT id="17"><DD>
Note: if you set the timeout using
<B>clnt_control</B>(),
the timeout parameter passed to
<B>clnt_call</B>()
will be ignored in all future calls.
<DT id="18"><DD>
<B>CLGET_SERVER_ADDR</B> <I>struct sockaddr_in </I> // get server's address
<DT id="19"><DD>
The following operations are valid for UDP only:
<DT id="20"><DD>
<B>CLSET_RETRY_TIMEOUT</B> <I>struct timeval</I> // set the retry timeout
<B>CLGET_RETRY_TIMEOUT</B> <I>struct timeval</I> // get the retry timeout
<DT id="21"><DD>
The retry timeout is the time that &quot;UDP RPC&quot;
waits for the server to reply before
retransmitting the request.
</DL>
<P>
<PRE>
<B>clnt_freeres(CLIENT * </B><I>clnt</I><B>, xdrproc_t </B><I>outproc</I><B>, char *</B><I>out</I><B>);</B>
</PRE>
<DL COMPACT>
<DT id="22"><DD>
A macro that frees any data allocated by the RPC/XDR
system when it decoded the results of an RPC call.
The parameter
<I>out</I>
is the address of the results, and
<I>outproc</I>
is the XDR routine describing the results.
This routine returns one if the results were successfully freed,
and zero otherwise.
</DL>
<P>
<PRE>
<B>void clnt_geterr(CLIENT *</B><I>clnt</I><B>, struct rpc_err *</B><I>errp</I><B>);</B>
</PRE>
<DL COMPACT>
<DT id="23"><DD>
A macro that copies the error structure out of the client
handle to the structure at address
<I>errp</I>.
</DL>
<P>
<PRE>
<B>void clnt_pcreateerror(char *</B><I>s</I><B>);</B>
</PRE>
<DL COMPACT>
<DT id="24"><DD>
Print a message to standard error indicating why a client RPC
handle could not be created.
The message is prepended with string
<I>s</I>
and a colon.
Used when a
<B>clnt_create</B>(),
<B>clntraw_create</B>(),
<B>clnttcp_create</B>(),
or
<B>clntudp_create</B>()
call fails.
</DL>
<P>
<PRE>
<B>void clnt_perrno(enum clnt_stat </B><I>stat</I><B>);</B>
</PRE>
<DL COMPACT>
<DT id="25"><DD>
Print a message to standard error corresponding
to the condition indicated by
<I>stat</I>.
Used after
<B>callrpc</B>().
</DL>
<P>
<PRE>
<B>clnt_perror(CLIENT *</B><I>clnt</I><B>, char *</B><I>s</I><B>);</B>
</PRE>
<DL COMPACT>
<DT id="26"><DD>
Print a message to standard error indicating why an RPC call failed;
<I>clnt</I>
is the handle used to do the call.
The message is prepended with string
<I>s</I>
and a colon.
Used after
<B>clnt_call</B>().
</DL>
<P>
<PRE>
<B>char *clnt_spcreateerror(char *</B><I>s</I><B>);</B>
</PRE>
<DL COMPACT>
<DT id="27"><DD>
Like
<B>clnt_pcreateerror</B>(),
except that it returns a string instead of printing to the standard error.
<DT id="28"><DD>
Bugs: returns pointer to static data that is overwritten on each call.
</DL>
<P>
<PRE>
<B>char *clnt_sperrno(enum clnt_stat </B><I>stat</I><B>);</B>
</PRE>
<DL COMPACT>
<DT id="29"><DD>
Take the same arguments as
<B>clnt_perrno</B>(),
but instead of sending a message to the standard error indicating why an RPC
call failed, return a pointer to a string which contains the message.
The string ends with a NEWLINE.
<DT id="30"><DD>
<B>clnt_sperrno</B>()
is used instead of
<B>clnt_perrno</B>()
if the program does not have a standard error (as a program
running as a server quite likely does not), or if the programmer
does not want the message to be output with
<B><A HREF="/cgi-bin/man/man2html?3+printf">printf</A></B>(3),
or if a message format different than that supported by
<B>clnt_perrno</B>()
is to be used.
Note: unlike
<B>clnt_sperror</B>()
and
<B>clnt_spcreateerror</B>(),
<B>clnt_sperrno</B>()
returns pointer to static data, but the
result will not get overwritten on each call.
</DL>
<P>
<PRE>
<B>char *clnt_sperror(CLIENT *</B><I>rpch</I><B>, char *</B><I>s</I><B>);</B>
</PRE>
<DL COMPACT>
<DT id="31"><DD>
Like
<B>clnt_perror</B>(),
except that (like
<B>clnt_sperrno</B>())
it returns a string instead of printing to standard error.
<DT id="32"><DD>
Bugs: returns pointer to static data that is overwritten on each call.
</DL>
<P>
<PRE>
<B>CLIENT *clntraw_create(unsigned long </B><I>prognum</I><B>, unsigned long </B><I>versnum</I><B>);</B>
</PRE>
<DL COMPACT>
<DT id="33"><DD>
This routine creates a toy RPC client for the remote program
<I>prognum</I>,
version
<I>versnum</I>.
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
<B>svcraw_create</B>().
This allows simulation of RPC and acquisition of RPC
overheads, such as round trip times, without any kernel interference.
This routine returns NULL if it fails.
</DL>
<P>
<PRE>
<B>CLIENT *clnttcp_create(struct sockaddr_in *</B><I>addr</I><B>,</B>
<B> unsigned long </B><I>prognum</I><B>, unsigned long </B><I>versnum</I><B>,</B>
<B> int *</B><I>sockp</I><B>, unsigned int </B><I>sendsz</I><B>, unsigned int </B><I>recvsz</I><B>);</B>
</PRE>
<DL COMPACT>
<DT id="34"><DD>
This routine creates an RPC client for the remote program
<I>prognum</I>,
version
<I>versnum</I>;
the client uses TCP/IP as a transport.
The remote program is located at Internet address
<I>*addr</I>.
If
<I>addr-&gt;sin_port</I>
is zero, then it is set to the actual port that the remote
program is listening on (the remote
<B>portmap</B>
service is consulted for this information).
The parameter
<I>sockp</I>
is a socket; if it is
<B>RPC_ANYSOCK</B>,
then this routine opens a new one and sets
<I>sockp</I>.
Since TCP-based RPC uses buffered I/O,
the user may specify the size of the send and receive buffers
with the parameters
<I>sendsz</I>
and
<I>recvsz</I>;
values of zero choose suitable defaults.
This routine returns NULL if it fails.
</DL>
<P>
<PRE>
<B>CLIENT *clntudp_create(struct sockaddr_in *</B><I>addr</I><B>,</B>
<B> unsigned long </B><I>prognum</I><B>, unsigned long </B><I>versnum</I><B>,</B>
<B> struct timeval </B><I>wait</I><B>, int *</B><I>sockp</I><B>);</B>
</PRE>
<DL COMPACT>
<DT id="35"><DD>
This routine creates an RPC client for the remote program
<I>prognum</I>,
version
<I>versnum</I>;
the client uses use UDP/IP as a transport.
The remote program is located at Internet address
<I>addr</I>.
If
<I>addr-&gt;sin_port</I>
is zero, then it is set to actual port that the remote
program is listening on (the remote
<B>portmap</B>
service is consulted for this information).
The parameter
<I>sockp</I>
is a socket; if it is
<B>RPC_ANYSOCK</B>,
then this routine opens a new one and sets
<I>sockp</I>.
The UDP transport resends the call message in intervals of
<I>wait</I>
time until a response is received or until the call times out.
The total time for the call to time out is specified by
<B>clnt_call</B>().
<DT id="36"><DD>
Warning: since UDP-based RPC messages can hold only up to 8 Kbytes
of encoded data, this transport cannot be used for procedures
that take large arguments or return huge results.
</DL>
<P>
<PRE>
<B>CLIENT *clntudp_bufcreate(struct sockaddr_in *</B><I>addr</I><B>,</B>
<B> unsigned long </B><I>prognum</I><B>, unsigned long </B><I>versnum</I><B>,</B>
<B> struct timeval </B><I>wait</I><B>, int *</B><I>sockp</I><B>,</B>
<B> unsigned int </B><I>sendsize</I><B>, unsigned int recosize</B><I>);</I>
</PRE>
<DL COMPACT>
<DT id="37"><DD>
This routine creates an RPC client for the remote program
<I>prognum</I>,
on
<I>versnum</I>;
the client uses use UDP/IP as a transport.
The remote program is located at Internet address
<I>addr</I>.
If
<I>addr-&gt;sin_port</I>
is zero, then it is set to actual port that the remote
program is listening on (the remote
<B>portmap</B>
service is consulted for this information).
The parameter
<I>sockp</I>
is a socket; if it is
<B>RPC_ANYSOCK</B>,
then this routine opens a new one and sets
<I>sockp</I>.
The UDP transport resends the call message in intervals of
<I>wait</I>
time until a response is received or until the call times out.
The total time for the call to time out is specified by
<B>clnt_call</B>().
<DT id="38"><DD>
This allows the user to specify the maximum packet
size for sending and receiving UDP-based RPC messages.
</DL>
<P>
<PRE>
<B>void get_myaddress(struct sockaddr_in *</B><I>addr</I><B>);</B>
</PRE>
<DL COMPACT>
<DT id="39"><DD>
Stuff the machine's IP address into
<I>*addr</I>,
without consulting the library routines that deal with
<I>/etc/hosts</I>.
The port number is always set to
<B>htons(PMAPPORT)</B>.
</DL>
<P>
<PRE>
<B>struct pmaplist *pmap_getmaps(struct sockaddr_in *</B><I>addr</I><B>);</B>
</PRE>
<DL COMPACT>
<DT id="40"><DD>
A user interface to the
<B>portmap</B>
service, which returns a list of the current RPC
program-to-port mappings on the host located at IP address
<I>*addr</I>.
This routine can return NULL.
The command
<I>rpcinfo&nbsp;-p</I>
uses this routine.
</DL>
<P>
<PRE>
<B>unsigned short pmap_getport(struct sockaddr_in *</B><I>addr</I><B>,</B>
<B> unsigned long </B><I>prognum</I><B>, unsigned long </B><I>versnum</I><B>,</B>
<B> unsigned int </B><I>protocol</I><B>);</B>
</PRE>
<DL COMPACT>
<DT id="41"><DD>
A user interface to the
<B>portmap</B>
service, which returns the port number
on which waits a service that supports program number
<I>prognum</I>,
version
<I>versnum</I>,
and speaks the transport protocol associated with
<I>protocol</I>.
The value of
<I>protocol</I>
is most likely
<B>IPPROTO_UDP</B>
or
<B>IPPROTO_TCP</B>.
A return value of zero means that the mapping does not exist
or that the RPC system failed to contact the remote
<B>portmap</B>
service.
In the latter case, the global variable
<I>rpc_createerr</I>
contains the RPC status.
</DL>
<P>
<PRE>
<B>enum clnt_stat pmap_rmtcall(struct sockaddr_in *</B><I>addr</I><B>,</B>
<B> unsigned long </B><I>prognum</I><B>, unsigned long </B><I>versnum</I><B>,</B>
<B> unsigned long </B><I>procnum</I><B>,</B>
<B> xdrproc_t </B><I>inproc</I><B>, char *</B><I>in</I><B>,</B>
<B> xdrproc_t </B><I>outproc</I><B>, char *</B><I>out</I><B>,</B>
<B> struct timeval </B><I>tout</I><B>, unsigned long *</B><I>portp</I><B>);</B>
</PRE>
<DL COMPACT>
<DT id="42"><DD>
A user interface to the
<B>portmap</B>
service, which instructs
<B>portmap</B>
on the host at IP address
<I>*addr</I>
to make an RPC call on your behalf to a procedure on that host.
The parameter
<I>*portp</I>
will be modified to the program's port number if the procedure succeeds.
The definitions of other parameters are discussed
in
<B>callrpc</B>()
and
<B>clnt_call</B>().
This procedure should be used for a "ping" and nothing else.
See also
<B>clnt_broadcast</B>().
</DL>
<P>
<PRE>
<B>bool_t pmap_set(unsigned long </B><I>prognum</I><B>, unsigned long </B><I>versnum</I><B>,</B>
<B> unsigned int </B><I>protocol</I><B>, unsigned short </B><I>port</I><B>);</B>
</PRE>
<DL COMPACT>
<DT id="43"><DD>
A user interface to the
<B>portmap</B>
service, which establishes a mapping between the triple
[<I>prognum</I>,<I>versnum</I>,<I>protocol</I>]
and
<I>port</I>
on the machine's
<B>portmap</B>
service.
The value of
<I>protocol</I>
is most likely
<B>IPPROTO_UDP</B>
or
<B>IPPROTO_TCP</B>.
This routine returns one if it succeeds, zero otherwise.
Automatically done by
<B>svc_register</B>().
</DL>
<P>
<PRE>
<B>bool_t pmap_unset(unsigned long </B><I>prognum</I><B>, unsigned long </B><I>versnum</I><B>);</B>
</PRE>
<DL COMPACT>
<DT id="44"><DD>
A user interface to the
<B>portmap</B>
service, which destroys all mapping between the triple
[<I>prognum</I>,<I>versnum</I>,<I>*</I>]
and
<B>ports</B>
on the machine's
<B>portmap</B>
service.
This routine returns one if it succeeds, zero otherwise.
</DL>
<P>
<PRE>
<B>int registerrpc(unsigned long </B><I>prognum</I><B>, unsigned long </B><I>versnum</I><B>,</B>
<B> unsigned long </B><I>procnum</I><B>, char *(*</B><I>procname</I><B>)(char *),</B>
<B> xdrproc_t </B><I>inproc</I><B>, xdrproc_t </B><I>outproc</I><B>);</B>
</PRE>
<DL COMPACT>
<DT id="45"><DD>
Register procedure
<I>procname</I>
with the RPC service package.
If a request arrives for program
<I>prognum</I>,
version
<I>versnum</I>,
and procedure
<I>procnum</I>,
<I>procname</I>
is called with a pointer to its parameter(s);
<I>procname</I>
should return a pointer to its static result(s);
<I>inproc</I>
is used to decode the parameters while
<I>outproc</I>
is used to encode the results.
This routine returns zero if the registration succeeded, -1 otherwise.
<DT id="46"><DD>
Warning: remote procedures registered in this form
are accessed using the UDP/IP transport; see
<B>svcudp_create</B>()
for restrictions.
</DL>
<P>
<PRE>
<B>struct rpc_createerr </B><I>rpc_createerr</I><B>;</B>
</PRE>
<DL COMPACT>
<DT id="47"><DD>
A global variable whose value is set by any RPC client creation routine
that does not succeed.
Use the routine
<B>clnt_pcreateerror</B>()
to print the reason why.
</DL>
<P>
<PRE>
<B>void svc_destroy(SVCXPRT *</B><I>xprt</I><B>);</B>
</PRE>
<DL COMPACT>
<DT id="48"><DD>
A macro that destroys the RPC service transport handle,
<I>xprt</I>.
Destruction usually involves deallocation
of private data structures, including
<I>xprt</I>
itself.
Use of
<I>xprt</I>
is undefined after calling this routine.
</DL>
<P>
<PRE>
<B>fd_set </B><I>svc_fdset</I><B>;</B>
</PRE>
<DL COMPACT>
<DT id="49"><DD>
A global variable reflecting the RPC service side's
read file descriptor bit mask; it is suitable as a parameter to the
<B><A HREF="/cgi-bin/man/man2html?2+select">select</A></B>(2)
system call.
This is of interest only if a service implementor does their own
asynchronous event processing, instead of calling
<B>svc_run</B>().
This variable is read-only (do not pass its address to
<B><A HREF="/cgi-bin/man/man2html?2+select">select</A></B>(2)!),
yet it may change after calls to
<B>svc_getreqset</B>()
or any creation routines.
</DL>
<P>
<PRE>
<B>int </B><I>svc_fds</I><B>;</B>
</PRE>
<DL COMPACT>
<DT id="50"><DD>
Similar to
<B>svc_fdset</B>,
but limited to 32 file descriptors.
This interface is obsoleted by
<B>svc_fdset</B>.
</DL>
<P>
<PRE>
<B>svc_freeargs(SVCXPRT *</B><I>xprt</I><B>, xdrproc_t </B><I>inproc</I><B>, char *</B><I>in</I><B>);</B>
</PRE>
<DL COMPACT>
<DT id="51"><DD>
A macro that frees any data allocated by the RPC/XDR
system when it decoded the arguments to a service procedure using
<B>svc_getargs</B>().
This routine returns 1 if the results were successfully freed,
and zero otherwise.
</DL>
<P>
<PRE>
<B>svc_getargs(SVCXPRT *</B><I>xprt</I><B>, xdrproc_t </B><I>inproc</I><B>, char *</B><I>in</I><B>);</B>
</PRE>
<DL COMPACT>
<DT id="52"><DD>
A macro that decodes the arguments of an RPC request
associated with the RPC service transport handle,
<I>xprt</I>.
The parameter
<I>in</I>
is the address where the arguments will be placed;
<I>inproc</I>
is the XDR routine used to decode the arguments.
This routine returns one if decoding succeeds, and zero otherwise.
</DL>
<P>
<PRE>
<B>struct sockaddr_in *svc_getcaller(SVCXPRT *</B><I>xprt</I><B>);</B>
</PRE>
<DL COMPACT>
<DT id="53"><DD>
The approved way of getting the network address of the caller
of a procedure associated with the RPC service transport handle,
<I>xprt</I>.
</DL>
<P>
<PRE>
<B>void svc_getreqset(fd_set *</B><I>rdfds</I><B>);</B>
</PRE>
<DL COMPACT>
<DT id="54"><DD>
This routine is of interest only if a service implementor does not call
<B>svc_run</B>(),
but instead implements custom asynchronous event processing.
It is called when the
<B><A HREF="/cgi-bin/man/man2html?2+select">select</A></B>(2)
system call has determined that an RPC request has arrived on some
RPC socket(s);
<I>rdfds</I>
is the resultant read file descriptor bit mask.
The routine returns when all sockets associated with the value of
<I>rdfds</I>
have been serviced.
</DL>
<P>
<PRE>
<B>void svc_getreq(int </B><I>rdfds</I><B>);</B>
</PRE>
<DL COMPACT>
<DT id="55"><DD>
Similar to
<B>svc_getreqset</B>(),
but limited to 32 file descriptors.
This interface is obsoleted by
<B>svc_getreqset</B>().
</DL>
<P>
<PRE>
<B>bool_t svc_register(SVCXPRT *</B><I>xprt</I><B>, unsigned long </B><I>prognum</I><B>,</B>
<B> unsigned long </B><I>versnum</I><B>,</B>
<B> void (*</B><I>dispatch</I><B>)(svc_req *, SVCXPRT *),</B>
<B> unsigned long </B><I>protocol</I><B>);</B>
</PRE>
<DL COMPACT>
<DT id="56"><DD>
Associates
<I>prognum</I>
and
<I>versnum</I>
with the service dispatch procedure,
<I>dispatch</I>.
If
<I>protocol</I>
is zero, the service is not registered with the
<B>portmap</B>
service.
If
<I>protocol</I>
is nonzero, then a mapping of the triple
[<I>prognum</I>,<I>versnum</I>,<I>protocol</I>]
to
<I>xprt-&gt;xp_port</I>
is established with the local
<B>portmap</B>
service (generally
<I>protocol</I>
is zero,
<B>IPPROTO_UDP</B>
or
<B>IPPROTO_TCP</B>).
The procedure
<I>dispatch</I>
has the following form:
<DT id="57"><DD>
dispatch(struct svc_req *request, SVCXPRT *xprt);
<DT id="58"><DD>
The
<B>svc_register</B>()
routine returns one if it succeeds, and zero otherwise.
</DL>
<P>
<PRE>
<B>void svc_run(void);</B>
</PRE>
<DL COMPACT>
<DT id="59"><DD>
This routine never returns.
It waits for RPC requests to arrive, and calls the appropriate service
procedure using
<B>svc_getreq</B>()
when one arrives.
This procedure is usually waiting for a
<B><A HREF="/cgi-bin/man/man2html?2+select">select</A></B>(2)
system call to return.
</DL>
<P>
<PRE>
<B>bool_t svc_sendreply(SVCXPRT *</B><I>xprt</I><B>, xdrproc_t </B><I>outproc</I><B>, char *</B><I>out</I><B>);</B>
</PRE>
<DL COMPACT>
<DT id="60"><DD>
Called by an RPC service's dispatch routine to send the results of a
remote procedure call.
The parameter
<I>xprt</I>
is the request's associated transport handle;
<I>outproc</I>
is the XDR routine which is used to encode the results; and
<I>out</I>
is the address of the results.
This routine returns one if it succeeds, zero otherwise.
</DL>
<P>
<PRE>
<B>void svc_unregister(unsigned long </B><I>prognum</I><B>, unsigned long </B><I>versnum</I><B>);</B>
</PRE>
<DL COMPACT>
<DT id="61"><DD>
Remove all mapping of the double
[<I>prognum</I>,<I>versnum</I>]
to dispatch routines, and of the triple
[<I>prognum</I>,<I>versnum</I>,<I>*</I>]
to port number.
</DL>
<P>
<PRE>
<B>void svcerr_auth(SVCXPRT *</B><I>xprt</I><B>, enum auth_stat </B><I>why</I><B>);</B>
</PRE>
<DL COMPACT>
<DT id="62"><DD>
Called by a service dispatch routine that refuses to perform
a remote procedure call due to an authentication error.
</DL>
<P>
<PRE>
<B>void svcerr_decode(SVCXPRT *</B><I>xprt</I><B>);</B>
</PRE>
<DL COMPACT>
<DT id="63"><DD>
Called by a service dispatch routine that cannot successfully
decode its parameters.
See also
<B>svc_getargs</B>().
</DL>
<P>
<PRE>
<B>void svcerr_noproc(SVCXPRT *</B><I>xprt</I><B>);</B>
</PRE>
<DL COMPACT>
<DT id="64"><DD>
Called by a service dispatch routine that does not implement
the procedure number that the caller requests.
</DL>
<P>
<PRE>
<B>void svcerr_noprog(SVCXPRT *</B><I>xprt</I><B>);</B>
</PRE>
<DL COMPACT>
<DT id="65"><DD>
Called when the desired program is not registered with the RPC package.
Service implementors usually do not need this routine.
</DL>
<P>
<PRE>
<B>void svcerr_progvers(SVCXPRT *</B><I>xprt</I><B>);</B>
</PRE>
<DL COMPACT>
<DT id="66"><DD>
Called when the desired version of a program is not registered
with the RPC package.
Service implementors usually do not need this routine.
</DL>
<P>
<PRE>
<B>void svcerr_systemerr(SVCXPRT *</B><I>xprt</I><B>);</B>
</PRE>
<DL COMPACT>
<DT id="67"><DD>
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.
</DL>
<P>
<PRE>
<B>void svcerr_weakauth(SVCXPRT *</B><I>xprt</I><B>);</B>
</PRE>
<DL COMPACT>
<DT id="68"><DD>
Called by a service dispatch routine that refuses to perform
a remote procedure call due to insufficient authentication parameters.
The routine calls
<B>svcerr_auth(xprt, AUTH_TOOWEAK)</B>.
</DL>
<P>
<PRE>
<B>SVCXPRT *svcfd_create(int </B><I>fd</I><B>, unsigned int </B><I>sendsize</I><B>,</B>
<B> unsigned int </B><I>recvsize</I><B>);</B>
</PRE>
<DL COMPACT>
<DT id="69"><DD>
Create a service on top of any open file descriptor.
Typically, this file descriptor is a connected socket for a stream protocol such
as TCP.
<I>sendsize</I>
and
<I>recvsize</I>
indicate sizes for the send and receive buffers.
If they are zero, a reasonable default is chosen.
</DL>
<P>
<PRE>
<B>SVCXPRT *svcraw_create(void);</B>
</PRE>
<DL COMPACT>
<DT id="70"><DD>
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
<B>clntraw_create</B>().
This routine allows simulation of RPC and acquisition of RPC
overheads (such as round trip times), without any kernel interference.
This routine returns NULL if it fails.
</DL>
<P>
<PRE>
<B>SVCXPRT *svctcp_create(int </B><I>sock</I><B>, unsigned int </B><I>send_buf_size</I><B>,</B>
<B> unsigned int </B><I>recv_buf_size</I><B>);</B>
</PRE>
<DL COMPACT>
<DT id="71"><DD>
This routine creates a TCP/IP-based RPC
service transport, to which it returns a pointer.
The transport is associated with the socket
<I>sock</I>,
which may be
<B>RPC_ANYSOCK</B>,
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,
<I>xprt-&gt;xp_sock</I>
is the transport's socket descriptor, and
<I>xprt-&gt;xp_port</I>
is the transport's port number.
This routine returns NULL if it fails.
Since TCP-based RPC uses buffered I/O,
users may specify the size of buffers; values of zero
choose suitable defaults.
</DL>
<P>
<PRE>
<B>SVCXPRT *svcudp_bufcreate(int </B><I>sock</I><B>, unsigned int </B><I>sendsize</I><B>,</B>
<B> unsigned int </B><I>recosize</I><B>);</B>
</PRE>
<DL COMPACT>
<DT id="72"><DD>
This routine creates a UDP/IP-based RPC
service transport, to which it returns a pointer.
The transport is associated with the socket
<I>sock</I>,
which may be
<B>RPC_ANYSOCK</B>,
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,
<I>xprt-&gt;xp_sock</I>
is the transport's socket descriptor, and
<I>xprt-&gt;xp_port</I>
is the transport's port number.
This routine returns NULL if it fails.
<DT id="73"><DD>
This allows the user to specify the maximum packet size for sending and
receiving UDP-based RPC messages.
</DL>
<P>
<PRE>
<B>SVCXPRT *svcudp_create(int </B><I>sock</I><B>);</B>
</PRE>
<DL COMPACT>
<DT id="74"><DD>
This call is equivalent to
<I>svcudp_bufcreate(sock,SZ,SZ)</I>
for some default size
<I>SZ</I>.
</DL>
<P>
<PRE>
<B>bool_t xdr_accepted_reply(XDR *</B><I>xdrs</I><B>, struct accepted_reply *</B><I>ar</I><B>);</B>
</PRE>
<DL COMPACT>
<DT id="75"><DD>
Used for encoding RPC reply messages.
This routine is useful for users who wish to generate
RPC-style messages without using the RPC package.
</DL>
<P>
<PRE>
<B>bool_t xdr_authunix_parms(XDR *</B><I>xdrs</I><B>, struct authunix_parms *</B><I>aupp</I><B>);</B>
</PRE>
<DL COMPACT>
<DT id="76"><DD>
Used for describing UNIX credentials.
This routine is useful for users
who wish to generate these credentials without using the RPC
authentication package.
</DL>
<P>
<PRE>
<B>void xdr_callhdr(XDR *</B><I>xdrs</I><B>, struct rpc_msg *</B><I>chdr</I><B>);</B>
</PRE>
<DL COMPACT>
<DT id="77"><DD>
Used for describing RPC call header messages.
This routine is useful for users who wish to generate
RPC-style messages without using the RPC package.
</DL>
<P>
<PRE>
<B>bool_t xdr_callmsg(XDR *</B><I>xdrs</I><B>, struct rpc_msg *</B><I>cmsg</I><B>);</B>
</PRE>
<DL COMPACT>
<DT id="78"><DD>
Used for describing RPC call messages.
This routine is useful for users who wish to generate RPC-style
messages without using the RPC package.
</DL>
<P>
<PRE>
<B>bool_t xdr_opaque_auth(XDR *</B><I>xdrs</I><B>, struct opaque_auth *</B><I>ap</I><B>);</B>
</PRE>
<DL COMPACT>
<DT id="79"><DD>
Used for describing RPC authentication information messages.
This routine is useful for users who wish to generate
RPC-style messages without using the RPC package.
</DL>
<P>
<PRE>
<B>bool_t xdr_pmap(XDR *</B><I>xdrs</I><B>, struct pmap *</B><I>regs</I><B>);</B>
</PRE>
<DL COMPACT>
<DT id="80"><DD>
Used for describing parameters to various
<B>portmap</B>
procedures, externally.
This routine is useful for users who wish to generate
these parameters without using the
<B>pmap</B>
interface.
</DL>
<P>
<PRE>
<B>bool_t xdr_pmaplist(XDR *</B><I>xdrs</I><B>, struct pmaplist **</B><I>rp</I><B>);</B>
</PRE>
<DL COMPACT>
<DT id="81"><DD>
Used for describing a list of port mappings, externally.
This routine is useful for users who wish to generate
these parameters without using the
<B>pmap</B>
interface.
</DL>
<P>
<PRE>
<B>bool_t xdr_rejected_reply(XDR *</B><I>xdrs</I><B>, struct rejected_reply *</B><I>rr</I><B>);</B>
</PRE>
<DL COMPACT>
<DT id="82"><DD>
Used for describing RPC reply messages.
This routine is useful for users who wish to generate
RPC-style messages without using the RPC package.
</DL>
<P>
<PRE>
<B>bool_t xdr_replymsg(XDR *</B><I>xdrs</I><B>, struct rpc_msg *</B><I>rmsg</I><B>);</B>
</PRE>
<DL COMPACT>
<DT id="83"><DD>
Used for describing RPC reply messages.
This routine is useful for users who wish to generate
RPC style messages without using the RPC package.
</DL>
<P>
<PRE>
<B>void xprt_register(SVCXPRT *</B><I>xprt</I><B>);</B>
</PRE>
<DL COMPACT>
<DT id="84"><DD>
After RPC service transport handles are created,
they should register themselves with the RPC service package.
This routine modifies the global variable
<I>svc_fds</I>.
Service implementors usually do not need this routine.
</DL>
<P>
<PRE>
<B>void xprt_unregister(SVCXPRT *</B><I>xprt</I><B>);</B>
</PRE>
<DL COMPACT>
<DT id="85"><DD>
Before an RPC service transport handle is destroyed,
it should unregister itself with the RPC service package.
This routine modifies the global variable
<I>svc_fds</I>.
Service implementors usually do not need this routine.
</DL>
<A NAME="lbAD">&nbsp;</A>
<H2>ATTRIBUTES</H2>
For an explanation of the terms used in this section, see
<B><A HREF="/cgi-bin/man/man2html?7+attributes">attributes</A></B>(7).
<TABLE BORDER>
<TR VALIGN=top><TD><B>Interface</B></TD><TD><B>Attribute</B></TD><TD><B>Value</B><BR></TD></TR>
<TR VALIGN=top><TD>
<B>auth_destroy</B>(),
<B>authnone_create</B>(),
<BR>
<B>authunix_create</B>(),
<BR>
<B>authunix_create_default</B>(),
<BR>
<B>callrpc</B>(),
<B>clnt_broadcast</B>(),
<BR>
<B>clnt_call</B>(),
<B>clnt_destroy</B>(),
<BR>
<B>clnt_create</B>(),
<B>clnt_control</B>(),
<BR>
<B>clnt_freeres</B>(),
<B>clnt_geterr</B>(),
<BR>
<B>clnt_pcreateerror</B>(),
<B>clnt_perrno</B>(),
<BR>
<B>clnt_perror</B>(),
<BR>
<B>clnt_spcreateerror</B>(),
<BR>
<B>clnt_sperrno</B>(),
<B>clnt_sperror</B>(),
<BR>
<B>clntraw_create</B>(),
<B>clnttcp_create</B>(),
<BR>
<B>clntudp_create</B>(),
<BR>
<B>clntudp_bufcreate</B>(),
<BR>
<B>get_myaddress</B>(),
<B>pmap_getmaps</B>(),
<BR>
<B>pmap_getport</B>(),
<B>pmap_rmtcall</B>(),
<BR>
<B>pmap_set</B>(),
<B>pmap_unset</B>(),
<BR>
<B>registerrpc</B>(),
<B>svc_destroy</B>(),
<BR>
<B>svc_freeargs</B>(),
<B>svc_getargs</B>(),
<BR>
<B>svc_getcaller</B>(),
<B>svc_getreqset</B>(),
<BR>
<B>svc_getreq</B>(),
<B>svc_register</B>(),
<BR>
<B>svc_run</B>(),
<B>svc_sendreply</B>(),
<BR>
<B>svc_unregister</B>(),
<B>svcerr_auth</B>(),
<BR>
<B>svcerr_decode</B>(),
<B>svcerr_noproc</B>(),
<BR>
<B>svcerr_noprog</B>(),
<B>svcerr_progvers</B>(),
<BR>
<B>svcerr_systemerr</B>(),
<B>svcerr_weakauth</B>(),
<BR>
<B>svcfd_create</B>(),
<B>svcraw_create</B>(),
<BR>
<B>svctcp_create</B>(),
<BR>
<B>svcudp_bufcreate</B>(),
<BR>
<B>svcudp_create</B>(),
<B>xdr_accepted_reply</B>(),
<BR>
<B>xdr_authunix_parms</B>(),
<BR>
<B>xdr_callhdr</B>(),
<BR>
<B>xdr_callmsg</B>(),
<B>xdr_opaque_auth</B>(),
<BR>
<B>xdr_pmap</B>(),
<B>xdr_pmaplist</B>(),
<BR>
<B>xdr_rejected_reply</B>(),
<BR>
<B>xdr_replymsg</B>(),
<BR>
<B>xprt_register</B>(),
<B>xprt_unregister</B>()
</TD><TD>Thread safety</TD><TD>MT-Safe<BR></TD></TR>
</TABLE>
<A NAME="lbAE">&nbsp;</A>
<H2>SEE ALSO</H2>
<B><A HREF="/cgi-bin/man/man2html?3+xdr">xdr</A></B>(3)
<P>
The following manuals:
<DL COMPACT><DT id="86"><DD>
Remote Procedure Calls: Protocol Specification
<BR>
Remote Procedure Call Programming Guide
<BR>
rpcgen Programming Guide
<BR>
</DL>
<P>
<I>RPC: Remote Procedure Call Protocol Specification</I>,
RFC&nbsp;1050, Sun Microsystems, Inc.,
USC-ISI.
<A NAME="lbAF">&nbsp;</A>
<H2>COLOPHON</H2>
This page is part of release 5.05 of the Linux
<I>man-pages</I>
project.
A description of the project,
information about reporting bugs,
and the latest version of this page,
can be found at
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="87"><A HREF="#lbAB">NAME</A><DD>
<DT id="88"><A HREF="#lbAC">SYNOPSIS AND DESCRIPTION</A><DD>
<DT id="89"><A HREF="#lbAD">ATTRIBUTES</A><DD>
<DT id="90"><A HREF="#lbAE">SEE ALSO</A><DD>
<DT id="91"><A HREF="#lbAF">COLOPHON</A><DD>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:05:54 GMT, March 31, 2021
</BODY>
</HTML>