186d7f5d3SJohn Marino.\" @(#)rpc_clnt_calls.3n 1.30 93/08/31 SMI; from SVr4 286d7f5d3SJohn Marino.\" Copyright 1989 AT&T 386d7f5d3SJohn Marino.\" @(#)rpc_clnt_calls 1.4 89/07/20 SMI; 486d7f5d3SJohn Marino.\" Copyright (c) 1988 Sun Microsystems, Inc. - All Rights Reserved. 586d7f5d3SJohn Marino.\" $FreeBSD: src/lib/libc/rpc/rpc_clnt_calls.3,v 1.8 2005/02/09 18:03:14 ru Exp $ 686d7f5d3SJohn Marino.Dd May 7, 1993 786d7f5d3SJohn Marino.Dt RPC_CLNT_CALLS 3 886d7f5d3SJohn Marino.Os 986d7f5d3SJohn Marino.Sh NAME 1086d7f5d3SJohn Marino.Nm rpc_clnt_calls , 1186d7f5d3SJohn Marino.Nm clnt_call , 1286d7f5d3SJohn Marino.Nm clnt_freeres , 1386d7f5d3SJohn Marino.Nm clnt_geterr , 1486d7f5d3SJohn Marino.Nm clnt_perrno , 1586d7f5d3SJohn Marino.Nm clnt_perror , 1686d7f5d3SJohn Marino.Nm clnt_sperrno , 1786d7f5d3SJohn Marino.Nm clnt_sperror , 1886d7f5d3SJohn Marino.Nm rpc_broadcast , 1986d7f5d3SJohn Marino.Nm rpc_broadcast_exp , 2086d7f5d3SJohn Marino.Nm rpc_call 2186d7f5d3SJohn Marino.Nd library routines for client side calls 2286d7f5d3SJohn Marino.Sh LIBRARY 2386d7f5d3SJohn Marino.Lb libc 2486d7f5d3SJohn Marino.Sh SYNOPSIS 2586d7f5d3SJohn Marino.In rpc/rpc.h 2686d7f5d3SJohn Marino.Ft "enum clnt_stat" 2786d7f5d3SJohn Marino.Fn clnt_call "CLIENT *clnt" "const rpcproc_t procnum" "const xdrproc_t inproc" "const caddr_t in" "const xdrproc_t outproc" "caddr_t out" "const struct timeval tout" 2886d7f5d3SJohn Marino.Ft bool_t 2986d7f5d3SJohn Marino.Fn clnt_freeres "CLIENT *clnt" "const xdrproc_t outproc" "caddr_t out" 3086d7f5d3SJohn Marino.Ft void 3186d7f5d3SJohn Marino.Fn clnt_geterr "const CLIENT * clnt" "struct rpc_err * errp" 3286d7f5d3SJohn Marino.Ft void 3386d7f5d3SJohn Marino.Fn clnt_perrno "const enum clnt_stat stat" 3486d7f5d3SJohn Marino.Ft void 3586d7f5d3SJohn Marino.Fn clnt_perror "CLIENT *clnt" "const char *s" 3686d7f5d3SJohn Marino.Ft "char *" 3786d7f5d3SJohn Marino.Fn clnt_sperrno "const enum clnt_stat stat" 3886d7f5d3SJohn Marino.Ft "char *" 3986d7f5d3SJohn Marino.Fn clnt_sperror "CLIENT *clnt" "const char * s" 4086d7f5d3SJohn Marino.Ft "enum clnt_stat" 4186d7f5d3SJohn Marino.Fo rpc_broadcast 4286d7f5d3SJohn Marino.Fa "const rpcprog_t prognum" "const rpcvers_t versnum" 4386d7f5d3SJohn Marino.Fa "const rpcproc_t procnum" "const xdrproc_t inproc" 4486d7f5d3SJohn Marino.Fa "const caddr_t in" "const xdrproc_t outproc" "caddr_t out" 4586d7f5d3SJohn Marino.Fa "const resultproc_t eachresult" "const char *nettype" 4686d7f5d3SJohn Marino.Fc 4786d7f5d3SJohn Marino.Ft "enum clnt_stat" 4886d7f5d3SJohn Marino.Fo rpc_broadcast_exp 4986d7f5d3SJohn Marino.Fa "const rpcprog_t prognum" "const rpcvers_t versnum" 5086d7f5d3SJohn Marino.Fa "const rpcproc_t procnum" "const xdrproc_t xargs" 5186d7f5d3SJohn Marino.Fa "caddr_t argsp" "const xdrproc_t xresults" 5286d7f5d3SJohn Marino.Fa "caddr_t resultsp" "const resultproc_t eachresult" 5386d7f5d3SJohn Marino.Fa "const int inittime" "const int waittime" 5486d7f5d3SJohn Marino.Fa "const char * nettype" 5586d7f5d3SJohn Marino.Fc 5686d7f5d3SJohn Marino.Ft "enum clnt_stat" 5786d7f5d3SJohn Marino.Fo rpc_call 5886d7f5d3SJohn Marino.Fa "const char *host" "const rpcprog_t prognum" 5986d7f5d3SJohn Marino.Fa "const rpcvers_t versnum" "const rpcproc_t procnum" 6086d7f5d3SJohn Marino.Fa "const xdrproc_t inproc" "const char *in" 6186d7f5d3SJohn Marino.Fa "const xdrproc_t outproc" "char *out" "const char *nettype" 6286d7f5d3SJohn Marino.Fc 6386d7f5d3SJohn Marino.Sh DESCRIPTION 6486d7f5d3SJohn MarinoRPC library routines allow C language programs to make procedure 6586d7f5d3SJohn Marinocalls on other machines across the network. 6686d7f5d3SJohn MarinoFirst, the client calls a procedure to send a request to the server. 6786d7f5d3SJohn MarinoUpon receipt of the request, the server calls a dispatch routine 6886d7f5d3SJohn Marinoto perform the requested service, and then sends back a reply. 6986d7f5d3SJohn Marino.Pp 7086d7f5d3SJohn MarinoThe 7186d7f5d3SJohn Marino.Fn clnt_call , 7286d7f5d3SJohn Marino.Fn rpc_call , 7386d7f5d3SJohn Marinoand 7486d7f5d3SJohn Marino.Fn rpc_broadcast 7586d7f5d3SJohn Marinoroutines handle the client side of the procedure call. 7686d7f5d3SJohn MarinoThe remaining routines deal with error handling in the case of errors. 7786d7f5d3SJohn Marino.Pp 7886d7f5d3SJohn MarinoSome of the routines take a 7986d7f5d3SJohn Marino.Vt CLIENT 8086d7f5d3SJohn Marinohandle as one of the arguments. 8186d7f5d3SJohn MarinoA 8286d7f5d3SJohn Marino.Vt CLIENT 8386d7f5d3SJohn Marinohandle can be created by an RPC creation routine such as 8486d7f5d3SJohn Marino.Fn clnt_create 8586d7f5d3SJohn Marino(see 8686d7f5d3SJohn Marino.Xr rpc_clnt_create 3 ) . 8786d7f5d3SJohn Marino.Pp 8886d7f5d3SJohn MarinoThese routines are safe for use in multithreaded applications. 8986d7f5d3SJohn Marino.Vt CLIENT 9086d7f5d3SJohn Marinohandles can be shared between threads, however in this implementation 9186d7f5d3SJohn Marinorequests by different threads are serialized (that is, the first request will 9286d7f5d3SJohn Marinoreceive its results before the second request is sent). 9386d7f5d3SJohn Marino.Sh Routines 9486d7f5d3SJohn MarinoSee 9586d7f5d3SJohn Marino.Xr rpc 3 9686d7f5d3SJohn Marinofor the definition of the 9786d7f5d3SJohn Marino.Vt CLIENT 9886d7f5d3SJohn Marinodata structure. 9986d7f5d3SJohn Marino.Bl -tag -width XXXXX 10086d7f5d3SJohn Marino.It Fn clnt_call 10186d7f5d3SJohn MarinoA function macro that calls the remote procedure 10286d7f5d3SJohn Marino.Fa procnum 10386d7f5d3SJohn Marinoassociated with the client handle, 10486d7f5d3SJohn Marino.Fa clnt , 10586d7f5d3SJohn Marinowhich is obtained with an RPC 10686d7f5d3SJohn Marinoclient creation routine such as 10786d7f5d3SJohn Marino.Fn clnt_create 10886d7f5d3SJohn Marino(see 10986d7f5d3SJohn Marino.Xr rpc_clnt_create 3 ) . 11086d7f5d3SJohn MarinoThe 11186d7f5d3SJohn Marino.Fa inproc 11286d7f5d3SJohn Marinoargument 11386d7f5d3SJohn Marinois the XDR function used to encode the procedure's arguments, and 11486d7f5d3SJohn Marino.Fa outproc 11586d7f5d3SJohn Marinois the XDR function used to decode the procedure's results; 11686d7f5d3SJohn Marino.Fa in 11786d7f5d3SJohn Marinois the address of the procedure's argument(s), and 11886d7f5d3SJohn Marino.Fa out 11986d7f5d3SJohn Marinois the address of where to place the result(s). 12086d7f5d3SJohn MarinoThe 12186d7f5d3SJohn Marino.Fa tout 12286d7f5d3SJohn Marinoargument 12386d7f5d3SJohn Marinois the time allowed for results to be returned, which is overridden by 12486d7f5d3SJohn Marinoa time-out set explicitly through 12586d7f5d3SJohn Marino.Fn clnt_control , 12686d7f5d3SJohn Marinosee 12786d7f5d3SJohn Marino.Xr rpc_clnt_create 3 . 12886d7f5d3SJohn MarinoIf the remote call succeeds, the status returned is 12986d7f5d3SJohn Marino.Dv RPC_SUCCESS , 13086d7f5d3SJohn Marinootherwise an appropriate status is returned. 13186d7f5d3SJohn Marino.It Fn clnt_freeres 13286d7f5d3SJohn MarinoA function macro that frees any data allocated by the 13386d7f5d3SJohn MarinoRPC/XDR system when it decoded the results of an RPC call. 13486d7f5d3SJohn MarinoThe 13586d7f5d3SJohn Marino.Fa out 13686d7f5d3SJohn Marinoargument 13786d7f5d3SJohn Marinois the address of the results, and 13886d7f5d3SJohn Marino.Fa outproc 13986d7f5d3SJohn Marinois the XDR routine describing the results. 14086d7f5d3SJohn MarinoThis routine returns 1 if the results were successfully freed, 14186d7f5d3SJohn Marinoand 0 otherwise. 14286d7f5d3SJohn Marino.It Fn clnt_geterr 14386d7f5d3SJohn MarinoA function macro that copies the error structure out of the client 14486d7f5d3SJohn Marinohandle to the structure at address 14586d7f5d3SJohn Marino.Fa errp . 14686d7f5d3SJohn Marino.It Fn clnt_perrno 14786d7f5d3SJohn MarinoPrint a message to standard error corresponding 14886d7f5d3SJohn Marinoto the condition indicated by 14986d7f5d3SJohn Marino.Fa stat . 15086d7f5d3SJohn MarinoA newline is appended. 15186d7f5d3SJohn MarinoNormally used after a procedure call fails for a routine 15286d7f5d3SJohn Marinofor which a client handle is not needed, for instance 15386d7f5d3SJohn Marino.Fn rpc_call . 15486d7f5d3SJohn Marino.It Fn clnt_perror 15586d7f5d3SJohn MarinoPrint a message to the standard error indicating why an 15686d7f5d3SJohn MarinoRPC call failed; 15786d7f5d3SJohn Marino.Fa clnt 15886d7f5d3SJohn Marinois the handle used to do the call. 15986d7f5d3SJohn MarinoThe message is prepended with string 16086d7f5d3SJohn Marino.Fa s 16186d7f5d3SJohn Marinoand a colon. 16286d7f5d3SJohn MarinoA newline is appended. 16386d7f5d3SJohn MarinoNormally used after a remote procedure call fails 16486d7f5d3SJohn Marinofor a routine which requires a client handle, 16586d7f5d3SJohn Marinofor instance 16686d7f5d3SJohn Marino.Fn clnt_call . 16786d7f5d3SJohn Marino.It Fn clnt_sperrno 16886d7f5d3SJohn MarinoTake the same arguments as 16986d7f5d3SJohn Marino.Fn clnt_perrno , 17086d7f5d3SJohn Marinobut instead of sending a message to the standard error 17186d7f5d3SJohn Marinoindicating why an RPC 17286d7f5d3SJohn Marinocall failed, return a pointer to a string which contains the message. 17386d7f5d3SJohn MarinoThe 17486d7f5d3SJohn Marino.Fn clnt_sperrno 17586d7f5d3SJohn Marinofunction 17686d7f5d3SJohn Marinois normally used instead of 17786d7f5d3SJohn Marino.Fn clnt_perrno 17886d7f5d3SJohn Marinowhen the program does not have a standard error (as a program 17986d7f5d3SJohn Marinorunning as a server quite likely does not), or if the programmer 18086d7f5d3SJohn Marinodoes not want the message to be output with 18186d7f5d3SJohn Marino.Fn printf 18286d7f5d3SJohn Marino(see 18386d7f5d3SJohn Marino.Xr printf 3 ) , 18486d7f5d3SJohn Marinoor if a message format different than that supported by 18586d7f5d3SJohn Marino.Fn clnt_perrno 18686d7f5d3SJohn Marinois to be used. 18786d7f5d3SJohn MarinoNote: 18886d7f5d3SJohn Marinounlike 18986d7f5d3SJohn Marino.Fn clnt_sperror 19086d7f5d3SJohn Marinoand 19186d7f5d3SJohn Marino.Fn clnt_spcreateerror 19286d7f5d3SJohn Marino(see 19386d7f5d3SJohn Marino.Xr rpc_clnt_create 3 ) , 19486d7f5d3SJohn Marino.Fn clnt_sperrno 19586d7f5d3SJohn Marinodoes not return pointer to static data so the 19686d7f5d3SJohn Marinoresult will not get overwritten on each call. 19786d7f5d3SJohn Marino.It Fn clnt_sperror 19886d7f5d3SJohn MarinoLike 19986d7f5d3SJohn Marino.Fn clnt_perror , 20086d7f5d3SJohn Marinoexcept that (like 20186d7f5d3SJohn Marino.Fn clnt_sperrno ) 20286d7f5d3SJohn Marinoit returns a string instead of printing to standard error. 20386d7f5d3SJohn MarinoHowever, 20486d7f5d3SJohn Marino.Fn clnt_sperror 20586d7f5d3SJohn Marinodoes not append a newline at the end of the message. 20686d7f5d3SJohn MarinoWarning: 20786d7f5d3SJohn Marinoreturns pointer to a buffer that is overwritten 20886d7f5d3SJohn Marinoon each call. 20986d7f5d3SJohn Marino.It Fn rpc_broadcast 21086d7f5d3SJohn MarinoLike 21186d7f5d3SJohn Marino.Fn rpc_call , 21286d7f5d3SJohn Marinoexcept the call message is broadcast to 21386d7f5d3SJohn Marinoall the connectionless transports specified by 21486d7f5d3SJohn Marino.Fa nettype . 21586d7f5d3SJohn MarinoIf 21686d7f5d3SJohn Marino.Fa nettype 21786d7f5d3SJohn Marinois 21886d7f5d3SJohn Marino.Dv NULL , 21986d7f5d3SJohn Marinoit defaults to 22086d7f5d3SJohn Marino.Qq netpath . 22186d7f5d3SJohn MarinoEach time it receives a response, 22286d7f5d3SJohn Marinothis routine calls 22386d7f5d3SJohn Marino.Fn eachresult , 22486d7f5d3SJohn Marinowhose form is: 22586d7f5d3SJohn Marino.Ft bool_t 22686d7f5d3SJohn Marino.Fn eachresult "caddr_t out" "const struct netbuf * addr" "const struct netconfig * netconf" 22786d7f5d3SJohn Marinowhere 22886d7f5d3SJohn Marino.Fa out 22986d7f5d3SJohn Marinois the same as 23086d7f5d3SJohn Marino.Fa out 23186d7f5d3SJohn Marinopassed to 23286d7f5d3SJohn Marino.Fn rpc_broadcast , 23386d7f5d3SJohn Marinoexcept that the remote procedure's output is decoded there; 23486d7f5d3SJohn Marino.Fa addr 23586d7f5d3SJohn Marinopoints to the address of the machine that sent the results, and 23686d7f5d3SJohn Marino.Fa netconf 23786d7f5d3SJohn Marinois the netconfig structure of the transport on which the remote 23886d7f5d3SJohn Marinoserver responded. 23986d7f5d3SJohn MarinoIf 24086d7f5d3SJohn Marino.Fn eachresult 24186d7f5d3SJohn Marinoreturns 0, 24286d7f5d3SJohn Marino.Fn rpc_broadcast 24386d7f5d3SJohn Marinowaits for more replies; 24486d7f5d3SJohn Marinootherwise it returns with appropriate status. 24586d7f5d3SJohn MarinoWarning: 24686d7f5d3SJohn Marinobroadcast file descriptors are limited in size to the 24786d7f5d3SJohn Marinomaximum transfer size of that transport. 24886d7f5d3SJohn MarinoFor Ethernet, this value is 1500 bytes. 24986d7f5d3SJohn MarinoThe 25086d7f5d3SJohn Marino.Fn rpc_broadcast 25186d7f5d3SJohn Marinofunction 25286d7f5d3SJohn Marinouses 25386d7f5d3SJohn Marino.Dv AUTH_SYS 25486d7f5d3SJohn Marinocredentials by default (see 25586d7f5d3SJohn Marino.Xr rpc_clnt_auth 3 ) . 25686d7f5d3SJohn Marino.It Fn rpc_broadcast_exp 25786d7f5d3SJohn MarinoLike 25886d7f5d3SJohn Marino.Fn rpc_broadcast , 25986d7f5d3SJohn Marinoexcept that the initial timeout, 26086d7f5d3SJohn Marino.Fa inittime 26186d7f5d3SJohn Marinoand the maximum timeout, 26286d7f5d3SJohn Marino.Fa waittime 26386d7f5d3SJohn Marinoare specified in milliseconds. 26486d7f5d3SJohn MarinoThe 26586d7f5d3SJohn Marino.Fa inittime 26686d7f5d3SJohn Marinoargument 26786d7f5d3SJohn Marinois the initial time that 26886d7f5d3SJohn Marino.Fn rpc_broadcast_exp 26986d7f5d3SJohn Marinowaits before resending the request. 27086d7f5d3SJohn MarinoAfter the first resend, the re-transmission interval 27186d7f5d3SJohn Marinoincreases exponentially until it exceeds 27286d7f5d3SJohn Marino.Fa waittime . 27386d7f5d3SJohn Marino.It Fn rpc_call 27486d7f5d3SJohn MarinoCall the remote procedure associated with 27586d7f5d3SJohn Marino.Fa prognum , 27686d7f5d3SJohn Marino.Fa versnum , 27786d7f5d3SJohn Marinoand 27886d7f5d3SJohn Marino.Fa procnum 27986d7f5d3SJohn Marinoon the machine, 28086d7f5d3SJohn Marino.Fa host . 28186d7f5d3SJohn MarinoThe 28286d7f5d3SJohn Marino.Fa inproc 28386d7f5d3SJohn Marinoargument 28486d7f5d3SJohn Marinois used to encode the procedure's arguments, and 28586d7f5d3SJohn Marino.Fa outproc 28686d7f5d3SJohn Marinois used to decode the procedure's results; 28786d7f5d3SJohn Marino.Fa in 28886d7f5d3SJohn Marinois the address of the procedure's argument(s), and 28986d7f5d3SJohn Marino.Fa out 29086d7f5d3SJohn Marinois the address of where to place the result(s). 29186d7f5d3SJohn MarinoThe 29286d7f5d3SJohn Marino.Fa nettype 29386d7f5d3SJohn Marinoargument 29486d7f5d3SJohn Marinocan be any of the values listed on 29586d7f5d3SJohn Marino.Xr rpc 3 . 29686d7f5d3SJohn MarinoThis routine returns 29786d7f5d3SJohn Marino.Dv RPC_SUCCESS 29886d7f5d3SJohn Marinoif it succeeds, 29986d7f5d3SJohn Marinoor an appropriate status is returned. 30086d7f5d3SJohn MarinoUse the 30186d7f5d3SJohn Marino.Fn clnt_perrno 30286d7f5d3SJohn Marinoroutine to translate failure status into error messages. 30386d7f5d3SJohn MarinoWarning: 30486d7f5d3SJohn Marino.Fn rpc_call 30586d7f5d3SJohn Marinouses the first available transport belonging 30686d7f5d3SJohn Marinoto the class 30786d7f5d3SJohn Marino.Fa nettype , 30886d7f5d3SJohn Marinoon which it can create a connection. 30986d7f5d3SJohn MarinoYou do not have control of timeouts or authentication 31086d7f5d3SJohn Marinousing this routine. 31186d7f5d3SJohn Marino.El 31286d7f5d3SJohn Marino.Sh SEE ALSO 31386d7f5d3SJohn Marino.Xr printf 3 , 31486d7f5d3SJohn Marino.Xr rpc 3 , 31586d7f5d3SJohn Marino.Xr rpc_clnt_auth 3 , 31686d7f5d3SJohn Marino.Xr rpc_clnt_create 3 317