rpc_clnt_calls(3N) LIBRARY FUNCTIONS rpc_clnt_calls(3N)
NAME
rpcclntcalls: clntcall, clntfreeres, clntgeterr,
clntperrno, clntperror, clntsperrno, clntsperror,
rpcbroadcast, rpccall - library routines for client side
calls
DESCRIPTION
RPC library routines allow C language programs to make pro-
cedure 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. The clntcall, rpccall and
rpcbroadcast routines handle the client side of the pro-
cedure call. The remaining routines deal with error han-
dling in the case of errors.
Routines
See rpc(3N) for the definition of the CLIENT data structure.
#include <rpc/rpc.h>
enum clntstat
clntcall(CLIENT *clnt, const ulong procnum, const xdrproct inproc,
caddrt in, const xdrproct outproc, caddrt out,
const struct timeval tout);
A function macro that calls the remote procedure proc-
num associated with the client handle, clnt, which is
obtained with an RPC client creation routine such as
clntcreate [see rpc_clnt_create(3N)]. The parameter
in is the address of the procedure's argument(s), and
out is the address of where to place the result(s);
inproc is used to encode the procedure's parameters,
and outproc is used to decode the procedure's results;
tout is the time allowed for results to be returned.
If the remote call succeeds, the status is returned in
RPCSUCCESS, otherwise an appropriate status is
returned.
int clntfreeres(CLIENT *clnt, const xdrproct outproc, caddrt out);
A function macro that frees any data allocated by the
RPC/XDR system when it decoded the results of an RPC
call. The parameter out is the address of the results,
and outproc is the XDR routine describing the results.
This routine returns 1 if the results were successfully
freed, and 0 otherwise.
void
clntgeterr(const CLIENT *clnt, struct rpcerr *errp);
A function macro that copies the error structure out of
the client handle to the structure at address errp.
void
1
rpc_clnt_calls(3N) LIBRARY FUNCTIONS rpc_clnt_calls(3N)
clntperrno(const enum clntstat stat);
Print a message to standard error corresponding to the
condition indicated by stat. A newline is appended at
the end of the message. Normally used after a pro-
cedure call fails, for instance rpccall.
void
clntperror(const CLIENT *clnt, const char *s);
Print a message to standard error indicating why an RPC
call failed; clnt is the handle used to do the call.
The message is prepended with string s and a colon. A
newline is appended at the end of the message. Nor-
mally used after a procedure call fails, for instance
clntcall.
char *
clntsperrno(const enum clntstat stat);
Take the same arguments as clntperrno, 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.
clntsperrno is normally used instead of clntperrno
when 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 out-
put with printf [see printf(3S)], or if a message for-
mat different than that supported by clntperrno is to
be used. Note: unlike clntsperror and
clntspcreaterror [see rpc_clnt_create(3N)],
clntsperrno does not return pointer to static data so
the result will not get overwritten on each call.
char *
clntsperror(const CLIENT *clnt, const char *s);
Like clntperror, except that (like clntsperrno) it
returns a string instead of printing to standard error.
However, clntsperror does not append a newline at the
end of the message.
Warning: returns pointer to static data that is
overwritten on each call.
enum clntstat
rpcbroadcast(const ulong prognum, const ulong versnum,
const ulong procnum, const xdrproct inproc, caddrt in,
const xdrproct outproc, caddrt out, const resultproct eachresult,
const char *nettype);
Like rpccall, except the call message is broadcast to
the connectionless network specified by nettype. If
nettype is NULL, it defaults to netpath. Each time it
2
rpc_clnt_calls(3N) LIBRARY FUNCTIONS rpc_clnt_calls(3N)
receives a response, this routine calls eachresult,
whose form is:
boolt
eachresult(const caddrt out, const struct netbuf *addr,
struct netconfig *netconf);
where out is the same as out passed to rpcbroadcast,
except that the remote procedure's output is decoded
there; addr points to the address of the machine that
sent the results, and netconf is the netconfig struc-
ture of the transport on which the remote server
responded. If eachresult returns 0, rpcbroadcast
waits for more replies; otherwise it returns with
appropriate status.
Warning: broadcast file descriptors are limited in
size to the maximum transfer size of that transport.
For Ethernet, this value is 1500 bytes.
enum clntstat
rpccall(const char *host, const ulong prognum,
const ulong versnum, const ulong procnum,
const xdrproct inproc, const xdrproct outproc,
const char *in, char *out, const char *nettype);
Call the remote procedure associated with prognum,
versnum, and procnum on the machine, host. The parame-
ter in is the address of the procedure's argument(s),
and out is the address of where to place the result(s);
inproc is used to encode the procedure's parameters,
and outproc is used to decode the procedure's results.
nettype can be any of the values listed on rpc(3N). If
nettype is NULL, it defaults to netpath. This routine
returns 0 if it succeeds, or the value of enum
clntstat cast to an integer if it fails. Use the
clntperrno routine to translate failure statuses into
messages.
Warning: rpccall uses the first available transport
belonging to the class nettype, on which it can create
a connection. You do not have control of timeouts or
authentication using this routine. There is also no
way to destroy the client handle.
SEE ALSO
printf(3S), rpc(3N), rpcclntauth(3N), rpcclntcreate(3N).
3