NAME | FEATURES | DESCRIPTION | RESTRICTIONS | ATTRIBUTES | SEE ALSO
POSIX_SOCKETS
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 sends back a reply. Finally, the procedure call returns to the client.
#include <rpc/rpc.h>
void auth_destroy(auth) AUTH *auth;
The macro above destroys the authentication information associated with auth. Destruction usually involves deallocation of private data structures. The effect of using auth after calling auth_destroy() is undefined.
AUTH * authnone_create()
The code above creates and returns an RPC authentication handle that passes non usable authentication information with each remote procedure call. This is the default authentication used by RPC.
AUTH * authunix_create(host, uid, gid, len, aup_gids) char *host; int uid, gid, len, *aup.gids;
The code above creates and returns an RPC authentication handle that contains authentication information. The host parameter is the name of the machine on which the information was created; uid is the user's user ID; gid is the user's current group ID; len and aup_gids refer to a counted array of groups to which the user belongs. Note that it is easy to impersonate a user.
AUTH * authunix_create_default()
The code above calls authunix_create() with the appropriate parameters.
callrpc(host, prognum, versnum, procnum, inproc, in, outproc, out) char *host; u_long prognum, versnum, procnum; char *in, *out; xdrproc_t inproc, outproc;
The code above calls the remote procedure associated with prognum, versnum, and procnum on the host system. The parameter in is the address of the procedure arguments, and out is the address to which the results are to be returned. The inproc argument is used to encode the procedure's parameters, and outproc is used to decode the procedure's results. This routine returns zero if sucessful, or the value of enum clnt_stat cast to an int
if it fails. The clnt_perrno routine is useful for translating
failure statuses into messages.
Caution: Calling remote procedures with this routine uses UDP/IP as a transport; see clntudp_create() for restrictions. You do not have control of timeouts or authentication using this routine.
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;
The code illustrated above is similar to callrpc(), except the call message is broadcast to all locally connected broadcast nets. Each time it receives a response, this routine calls eachresult(), whose form is:
eachresult(out, addr) char *out; struct sockaddr_in *addr;
where out is similar to the out passed to clnt_broadcast(), except that the remote procedure's output is decoded there. The addr pointer indicates the address of the machine that sent the results. If eachresult() returns zero, clnt_broadcast() waits for more replies; otherwise, it returns with the appropriate status.
Caution: Broadcast sockets are limited in size to the maximum transfer unit of the data link. For Ethernet, this value is 1500 bytes.
enum clnt_stat clnt_call(clnt, procnum, inproc, in, outproc, out, tout) CLIENT *clnt; u_long procnum; xdrproc_t inproc, outproc; char *in, *out; struct timeval tout;
The macro illustrated above calls the remote procedure procnum associated with the client handle, clnt, which is obtained with an RPC client creation routine such as clnt_create(). The parameter in is the address of the procedure's argument(s), and out is the address to which the results are returned. The inproc argument 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 come back.
clnt_destroy(clnt) CLIENT *clnt;
The macro illustrated above destroys the client's RPC handle. Destruction usually involves deallocation of private data structures, including clnt itself. The effect of using clnt after calling clnt_destroy() is undefined. If the RPC library opened the associated socket, it will also close it. Otherwise, the socket remains open.
CLIENT * clnt_create(host, prog, vers, proto) char *host; u_long prog, vers; char *proto;
The code above is a generic client creation routine. The host parameter identifies the name of the remote host where the server is located. The proto parameter indicates which kind of transport protocol to use. The values currently supported for this field are udp and tcp. Default timeouts are set, but can be modified using clnt_control.
Caution: Using UDP has its shortcomings. Since UDP-based RPC messages can only hold up to 8 K bytes of encoded data, this transport cannot be used for procedures that take large arguments or return huge results.
bool_t clnt_control(cl, req, info) CLIENT *cl; char *info;
The macro illustrated above is used to change or retrieve a variety of information about a client object. The req parameter indicates the type of operation, and info is a pointer to the information. For both UDP and TCP, the supported values of req, their argument types, and what they do are the following:
CLSET_TIMEOUT struct timeval set total timeout CLGET_TIMEOUT struct timeval get total timeout
If you set the timeout using clnt_control(), the timeout parameter passed to clnt_call() will be ignored in all future calls.
CLGET_SERVER_ADDR struct sockaddr_in get server's address
The following operations are valid only for UDP:
CLSET_RETRY_TIMEOUT struct timeval set the retry CLGET_RETRY_TIMEOUT struct timeval get the retry
The retry timeout is the time that UDP and RPC wait for the server to reply before retransmitting the request.
clnt_freeres(clnt, outproc, out) CLIENT *clnt; xdrproc_t outproc; char *out;
The macro above frees any data allocated by the RPC/XDR system when it decoded the results of an RPC call. The out parameter is the address of the results, and outproc is the XDR routine describing the results. This routine returns one if the results were successfully freed, and zero otherwise.
void clnt_geterr(clnt, errp) CLIENT *clnt; struct rpc_err *errp;
The macro above copies the error structure from the client handle to the structure at address errp.
void clnt_pcreateerror(s) char *s;
The code above prints a message to standard error indicating why a client RPC handle could not be created. The message is prepended with the string s and a colon. Used when a clnt_create(), clntraw_create(), clnttcp_create(), or clntudp_create() call fails.
void clnt_perrno(stat) enum clnt_stat stat;
The code above prints a message to standard error corresponding to the condition indicated by stat. Used after callrpc().
clnt_perror(clnt, s) CLIENT *clnt; char *s;
The code above prints a message to standard error indicating why an RPC call failed; clnt is the handle used to perform the call. The message is prepended with the string s and a colon. Used after clnt_call().
char * clnt_spcreateerror char *s;
The code illustrated above performs in a similar way to clnt_pcreateerror(), except that it returns a string instead of printing to the standard error.
Bugs: it returns a pointer to static data which is overwritten on each call.
char * clnt_sperrno(stat) enum clnt_stat stat;
The code illustrated above takes the same arguments as clnt_perrno(), but instead of sending a message to the standard error indicating why an RPC call failed, it returns a pointer to a string which contains the message. The string ends with a NEWLINE
.
The clnt_sperrno() function is used instead of clnt_perrno() if the program does not have a standard error (programs running as servers quite often do not), or if the programmer does not want the message to be output using printf(), or if a message format different from the one supported by clnt_perrno() is to be used. Note: unlike clnt_sperror() and clnt_spcreaterror(), clnt_sperrno() returns a pointer to static data, but the result is not overwritten on each call.
char * clnt_sperror(rpch, s) CLIENT *rpch; char *s;
The code illustrated above performs in a similar way toclnt_perror(), except that (like clnt_sperrno()) it returns a string instead of printing to standard error.
Bugs: It returns a pointer to static data which is overwritten on each call.
CLIENT * clntraw_create(prognum, versnum) u_long prognum, versnum;
This routine creates a toy RPC client for the remote program prognum, version versnum. The transport used to pass messages to the service is actually a buffer within the process's address space, the corresponding RPC server should therefore be located in the same address space (see svcraw_create()). 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.
CLIENT * clnttcp_create(addr, prognum, versnum, sockp, sendsz, recvsz) struct sockaddr_in *addr; u_long prognum, versnum; int *sockp; u_int sendsz, recvsz;
This routine creates an RPC client for the remote program prognum, version versnum. The client uses TCP/IP as a transport. The remote program is located at the Internet address *addr. If addr->sin_port is zero, then it is set to the actual port that the remote program is listening on (the remote portmap service is consulted for this information). The parameter sockp is a socket; if it is RPC_ANYSOCK, this routine opens a new one and sets sockp. As TCP-based RPC uses buffered I/O, the user may specify the size of the send and receive buffers using the sendsz and recvsz parameters. Zero values set suitable defaults. This routine returns NULL
if it fails.
CLIENT * clntudp_create(addr, prognum, versnum, wait, sockp) struct sockaddr_in *addr; u_long prognum, versnum; struct timeval wait; int *sockp;
This routine creates an RPC client for the remote program prognum, version versnum. The client uses UDP/IP as a transport. The remote program is located at the Internet address addr. If addr->sin_port is zero, then it is set to the actual port that the remote program is listening on (the remote portmap service is consulted for this information). The sockp parameter is a socket; if it is RPC_ANYSOCK, this routine opens a new one and sets sockp. The UDP transport resends the call message at intervals of 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 clnt_call().
Caution: UDP-based RPC messages can only hold up to 8 Kbytes of encoded data, so this transport cannot be used for procedures that take large arguments or return large results.
CLIENT * clntudp_bufcreate(addr, prognum, versnum, wait, sockp, sendsize, recosize) struct sockaddr_in *addr; u_long prognum, versnum; struct timeval wait; int *sockp; unsigned int sendsize; unsigned int recosize;
This routine creates an RPC client for the remote program prognum, on versnum. The client uses UDP/IP as a transport. The remote program is located at the Internet address addr. If addr->sin_port is zero, then it is set to the actual port that the remote program is listening on (the remote portmap service is consulted for this information). The sockp parameter is a socket; if it is RPC_ANYSOCK, this routine opens a new one and sets sockp. The UDP transport resends the call message at intervals of 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 clnt_call(). This allows the user to specify the maximun packet size for sending and receiving UDP-based RPC messages.
int get_myaddress(addr) struct sockaddr_in *addr;
This routine puts the machine's IP address into *addr, without consulting the library routines that deal with /etc/hosts. The port number is always set to htons(PMAPPORT). On top of ChorusOS, this primitive returns 0 when a port number and an IP address are found, and addr is filled with a valid sockaddr_in structure. Otherwise, a non zero value is returned, and addr is left unchanged.
struct pmaplist * pmap_getmaps(addr) struct sockaddr_in *addr;
This is a user interface to the portmap service, which returns a list of the current RPC program-to-port mappings on the host located at IP address *addr. This routine can return NULL
. The rpcinfo -p command uses this routine.
u_short pmap_getport(addr, prognum, versnum, protocol) struct sockaddr_in *addr; u_long prognum, versnum, protocol;
This is a user interface to the portmap service, which returns the port number on which a service is waiting. The service supports program number prognum, version versnum, and can use the transport protocol associated with protocol. The value of protocol will usually be IPPROTO_UDP or IPPROTO_TCP. A return value of zero means that the mapping does not exist, or that the RPC system failed to contact the remote portmap service. In the latter case, the global variable rpc_createerr contains the RPC status.
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;
This is a user interface to the portmap service, which instructs portmap on the host at IP address *addr to make an RPC call on your behalf to a procedure on that host. The *portp parameter will be modified to the program's port number if the procedure succeeds. The definitions of other parameters are discussed in callrpc() and clnt_call(). This procedure should be used for a ping and nothing else. See also clnt_broadcast().
pmap_set(prognum, versnum, protocol, port) u_long prognum, versnum, protocol; u_short port;
This is a user interface to the portmap service, which establishes a mapping between the triple [prognum,versnum,protocol] and port on the system's portmap service. The value of protocol will usually be IPPROTO_UDP or IPPROTO_TCP. This routine returns one if it succeeds, zero otherwise. The mapping is automatically done by svc_register().
pmap_unset(prognum, versnum) u_long prognum, versnum;
This is a user interface to the portmap service, which destroys all mapping between the triple [prognum,versnum,*] and ports on the system's portmap service. This routine returns one if it succeeds, zero otherwise.
registerrpc(prognum, versnum, procnum, procname, inproc, outproc) u_long prognum, versnum, procnum; char *(*procname) () ; xdrproc_t inproc, outproc;
The above routine registers the procedure procname with the RPC service package. If a request arrives for program prognum, version versnum, and procedure procnum, procname is called with a pointer to its parameter(s). The progname argument should return a pointer to its static result(s). inproc is used to decode the parameters, and outproc is used to encode the results. This routine returns zero if the registration succeeded, -1 otherwise.
Caution: Remote procedures registered in this form are accessed using the UDP/IP transport; see svcudp_create for restrictions.
struct rpc_createerr rpc_createerr;
This is a global variable whose value is set by any RPC client creation routine that does not succeed. Use the clnt_pcreateerror() routine to print the reason.
svc_destroy(xprt) SVCXPRT * xprt;
This is a macro that destroys the RPC service transport handle, xprt. Destruction usually involves deallocation of private data structures, including xprt itself. Use of xprt is undefined after calling this routine.
fd_set svc_fdset;
This is a global variable which reflects the RPC service side's read file descriptor bit mask. It can be used as a parameter to the select() system call. This is only of use if a service implementor does its own asynchronous event processing and does not call svc_run() . This variable is read-only (does not pass its address to select()!), but it may change after calls to svc_getreqset() or any other creation routines.
int svc_fds;
This interfqce is similar to svc_fdset(), but limited to 32 descriptors. This interface is rendered obsolete by svc_fdset().
svc_freeargs(xprt, inproc, in) SVCXPRT *xprt; xdrproc_t inproc; char *in;
This is a macro that frees any data allocated by the RPC/XDR system when it decoded the arguments to a service procedure using svc_getargs(). This routine returns 1 if the results were successfully freed, and 0 otherwise.
svc_getargs(xprt, inproc, in) SVCXPRT *xprt; xdrproc_t inproc; char *in;
This is a macro that decodes the arguments of an RPC request associated with the RPC service transport handle, xprt. The in parameter is the address where the arguments will be placed; inproc() is the XDR routine used to decode the arguments. This routine returns 1 if decoding succeeds, and 0 otherwise.
struct sockaddr_in * svc_getcaller(xprt) SVCXPRT *xprt;
This is the approved way of getting the network address of the caller of a procedure associated with the RPC service transport handle, xprt.
svc_getreqset(rdfds) fd_set *rdfds;
This routine is only of use if a service implementor does not call svc_run(), but instead implements custom asynchronous event processing. It is called when the select() system call has determined that an RPC request has arrived on RPC socket(s); rdfds is the resultant read file descriptor bit mask. The routine returns when all sockets associated with the value of rdfds have been serviced.
svc_getreq(rdfds) int rdfds;
This interface is similar to svc_getreqset(), but limited to 32 descriptors. This interface is rendered obsolete by svc_getreqset().
svc_register(xprt, prognum, versnum, dispatch, protocol) SVCXPRT *xprt; u_long prognum, versnum; void (*dispatch) (); u_long protocol;
This routine associates prognum and versnum with the service dispatch procedure, dispatch. If protocol is zero, the service is not registered with the portmap service. If protocol is non-zero, a mapping of the triple [prognum,versnum,protocol] to xprt->xp_port is established with the local portmap service (protocol is usually zero, IPPROTO_UDP or IPPROTO_TCP ). The dispatch procedure has the following form:
dispatch(request, xprt) struct svc_req *request; SVCXPRT *xprt;
The svc_register() routine returns 1 if it succeeds, and 0 otherwise.
svc_run()
This routine never returns. It waits for RPC requests to arrive, and calls the appropriate service procedure using svc_getreq() when one arrives. This procedure is usually waiting for a select() system call to return.
svc_sendreply(xprt, outproc, out) SVCXPRT *xprt; xdrproc_t outproc; char *out;
This is called by an RPC service's dispatch routine to send the results of a remote procedure call. The xprt parameter is the request's associated transport handle. outproc() is the XDR routine which is used to encode the results, and out is the address of the results. This routine returns 1 if it succeeds, and 0 otherwise.
void svc_unregister(prognum, versnum) u_long prognum, versnum;
This function removes all mapping of the double [prognum,versnum] to dispatch routines, and of the triple [prognum,versnum,*] to port numbers.
void svcerr_auth(xprt, why) SVCXPRT *xprt; enum auth_stat why;
This is called by a service dispatch routine that cannot perform a remote procedure call due to an authentication error.
void svcerr_decode(xprt) SVCXPRT *xprt;
This is called by a service dispatch routine that cannot decode its parameters successfully. See also svc_getargs.
void svcerr_noproc(xprt) SVCXPRT *xprt;
This is called by a service dispatch routine that does not implement the procedure number requested by the caller.
void svcerr_noprog(xprt) SVCXPRT *xprt;
This is called when the desired program is not registered with the RPC package. Service implementors do not usually need this routine.
void svcerr_progvers(xprt) SVCXPRT *xprt;
This is called when the desired version of a program is not registered with the RPC package. Service implementors do not usually need this routine.
void svcerr_systemerr(xprt) SVCXPRT *xprt;
This is 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.
void svcerr_weakauth(xprt) SVCXPRT *xprt;
This is called by a service dispatch routine that cannot perform a remote procedure call due to insufficient authentication parameters. The routine calls svcerr_auth(xprt, AUTH_TOOWEAK).
SVCXPRT * svcraw_create()
This routine creates a dummy RPC service transport, to which it returns a pointer. The transport is really a buffer within the process's address space. The corresponding RPC client should therefore be located in the same address space (see 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 NULL
if it fails.
SVCXPRT * svctcp_create(sock, send_buf_size, recv_buf_size) int sock; u_int send_buf_size, recv_buf_size;
This routine creates a TCP/IP-based RPC service transport, to which it returns a pointer. The transport is associated with the socket sock, which may be RPC_ANYSOCK, in which case a new socket is created. If the socket is not bound to a local TCP port, this routine binds it to an arbitrary port. Upon completion, xprt->xp_sock is the transport's socket descriptor, and xprt->xp_port is the transport's port number. This routine returns NULL
if it fails. TCP-based RPC uses buffered I/O, therefore
users may specify the size of buffers. Zero values set suitable defaults.
SVCXPRT * svcfd_create(fd, sendsize, recvsize) int fd; u_int sendsize; u_int recvsize;
This routine creates a service on top of any open descriptor. Typically, this descriptor is a connected socket for a stream protocol such as TCP. The sendsize and recvsize parameters indicate sizes for the send and receive buffers. If they are zero, a reasonable default is chosen.
SVCXPRT * svcudp_bufcreate(sock, sendsize, recosize) int sock;
This routine creates a UDP/IP-based RPC service transport, to which it returns a pointer. The transport is associated with the socket sock, which may be RPC_ANYSOCK, in which case a new socket is created. If the socket is not bound to a local UDP port, this routine binds it to an arbitrary port. Upon completion, xprt->xp_sock is the transport's socket descriptor, and xprt->xp_port is the transport's port number. This routine returns NULL
if it fails. This allows the user to specify the maximun packet size for sending and receiving UDP-based RPC messages.
xdr_accepted_reply(xdrs, ar) XDR *xdrs; struct accepted_reply *ar;
This routine is used to encode RPC reply messages. It is useful for users who wish to generate RPC-style messages without using the RPC package.
xdr_authunix_parms(xdrs, aupp) XDR *xdrs; struct authunix_parms *aupp;
This routine is used to describe UNIX credentials. It is useful for users who wish to generate these credentials without using the RPC authentication package.
void xdr_callhdr(xdrs, chdr) XDR *xdrs; struct rpc_msg *chdr;
This routine is used to describe RPC call header messages. It is useful for users who wish to generate RPC-style messages without using the RPC package.
xdr_callmsg(xdrs, cmsg) XDR *xdrs; struct rpc_msg *cmsg;
This routine is used to describe RPC call messages. It is useful for users who wish to generate RPC-style messages without using the RPC package.
xdr_opaque_auth(xdrs, ap) XDR *xdrs; struct opaque_auth *ap;
This routine is used to describe RPC authentication information messages. It is useful for users who wish to generate RPC-style messages without using the RPC package.
xdr_pmap(xdrs, regs) XDR *xdrs; struct pmap *regs;
This routine is used to describe parameters to various portmap procedures externally. It is useful for users who wish to generate these parameters without using the pmap interface.
xdr_pmaplist(xdrs, rp) XDR *xdrs; struct pmaplist **rp;
This routine is used to describe a list of port mappings, externally. It is useful for users who wish to generate these parameters without using the pmap interface.
xdr_rejected_reply(xdrs, rr) XDR *xdrs; struct rejected_reply *rr;
This routine is used to describe RPC reply messages. It is useful for users who wish to generate RPC-style messages without using the RPC package.
xdr_replymsg(xdrs, rmsg) XDR *xdrs; struct rpc_msg *rmsg;
This routine is used to describe RPC reply messages. It is useful for users who wish to generate RPC-style messages without using the RPC package.
void xprt_register(xprt) SVCXPRT *xprt;
After RPC service transport handles are created, they should be registered with the RPC service package using this routine, which modifies the global variable svc_fds(). Service implementors do not usually need this routine.
void xprt_unregister(xprt) SVCXPRT *xprt;
Before an RPC service transport handle is destroyed, it should be unregistered with the RPC service package using this routine, which modifies the global variable svc_fds(). Service implementors do not usually need this routine.
These library calls do not support multi-threaded applications.
See attributes(5) for descriptions of the following attributes:
ATTRIBUTE TYPE | ATTRIBUTE VALUE |
---|---|
Interface Stability | Evolving |
NAME | FEATURES | DESCRIPTION | RESTRICTIONS | ATTRIBUTES | SEE ALSO