1 .\" @(#)rpc.3n 2.4 88/08/08 4.0 RPCSRC; from 1.19 88/06/24 SMI
2 .\" $FreeBSD: src/lib/libc/rpc/rpc.3,v 1.11.2.5 2001/12/14 18:33:56 ru Exp $
3 .\" $DragonFly: src/lib/libc/rpc/rpc.3,v 1.8 2008/05/01 22:06:06 swildner Exp $
10 .Nd "library routines for remote procedure calls"
18 for function declarations.
20 These routines allow C programs to make procedure
21 calls on other machines across the network.
22 First, the client calls a procedure to send a
23 data packet to the server.
24 Upon receipt of the packet, the server calls a dispatch routine
25 to perform the requested service, and then sends back a
27 Finally, the procedure call returns to the client.
29 Routines that are used for Secure
31 authentication) are described in
37 encryption is available.
39 .Bl -tag -width indent -compact
44 .Fn auth_destroy "AUTH *auth"
47 A macro that destroys the authentication information associated with
49 Destruction usually involves deallocation of private data
53 is undefined after calling
65 authentication handle that passes nonusable authentication
66 information with each remote procedure call.
68 default authentication used by
75 .Fn authunix_create "char *host" "int uid" "int gid" "int len" "int *aup_gids"
80 authentication handle that contains
82 authentication information.
85 is the name of the machine on which the information was
88 is the user's user ID;
90 is the user's current group ID;
94 refer to a counted array of groups to which the user belongs.
95 It is easy to impersonate a user.
101 .Fn authunix_create_default
106 with the appropriate parameters.
115 .Fa "xdrproc_t inproc"
117 .Fa "xdrproc_t outproc"
122 Call the remote procedure associated with
131 is the address of the procedure's argument(s), and
133 is the address of where to place the result(s);
135 is used to encode the procedure's parameters, and
137 is used to decode the procedure's results.
138 This routine returns zero if it succeeds, or the value of
140 cast to an integer if it fails.
143 is handy for translating failure statuses into messages.
145 Warning: calling remote procedures with this routine
151 You do not have control of timeouts or authentication using
162 .Fa "xdrproc_t inproc"
164 .Fa "xdrproc_t outproc"
166 .Fa "bool_t (*eachresult)(caddr_t, struct sockaddr_in *)
172 except the call message is broadcast to all locally
173 connected broadcast nets.
174 Each time it receives a
175 response, this routine calls
178 .Bd -ragged -offset indent
180 .Fn eachresult "caddr_t out" "struct sockaddr_in *addr"
189 except that the remote procedure's output is decoded there;
191 points to the address of the machine that sent the results.
196 waits for more replies; otherwise it returns with appropriate
199 Warning: broadcast sockets are limited in size to the
200 maximum transfer unit of the data link.
202 this value is 1500 bytes.
211 .Fa "xdrproc_t inproc"
213 .Fa "xdrproc_t outproc"
215 .Fa "struct timeval tout"
219 A macro that calls the remote procedure
221 associated with the client handle,
223 which is obtained with an
225 client creation routine such as
229 is the address of the procedure's argument(s), and
231 is the address of where to place the result(s);
233 is used to encode the procedure's parameters, and
235 is used to decode the procedure's results;
237 is the time allowed for results to come back.
241 .Fn clnt_destroy "CLIENT *clnt"
244 A macro that destroys the client's
247 Destruction usually involves deallocation
248 of private data structures, including
253 is undefined after calling
257 library opened the associated socket, it will close it also.
258 Otherwise, the socket remains open.
264 .Fn clnt_create "const char *host" "u_long prog" "u_long vers" "const char *proto"
267 Generic client creation routine.
269 identifies the name of the remote host where the server
272 indicates which kind of transport protocol to use.
274 currently supported values for this field are
278 Default timeouts are set, but can be modified using
283 has its shortcomings.
287 messages can only hold up to 8 Kbytes of encoded data,
288 this transport cannot be used for procedures that take
289 large arguments or return huge results.
295 .Fn clnt_control "CLIENT *cl" "u_int req" "char *info"
298 A macro used to change or retrieve various information
299 about a client object.
301 indicates the type of operation, and
303 is a pointer to the information.
308 the supported values of
310 and their argument types and what they do are:
311 .Bl -column "CLSET_RETRY_TIMEOUT" "struct sockaddr_in"
312 .It Dv CLSET_TIMEOUT Ta Xo
313 .Vt "struct timeval" Ta "set total timeout"
315 .It Dv CLGET_TIMEOUT Ta Xo
316 .Vt "struct timeval" Ta "get total timeout"
320 Note: if you set the timeout using
322 the timeout parameter passed to
324 will be ignored in all future calls.
325 .Bl -column "CLSET_RETRY_TIMEOUT" "struct sockaddr_in"
326 .It Dv CLGET_SERVER_ADDR Ta Xo
327 .Vt "struct sockaddr_in" Ta "get server's address"
331 The following operations are valid for
334 .Bl -column "CLSET_RETRY_TIMEOUT" "struct sockaddr_in"
335 .It Dv CLSET_RETRY_TIMEOUT Ta Xo
336 .Vt "struct timeval" Ta "set the retry timeout"
338 .It Dv CLGET_RETRY_TIMEOUT Ta Xo
339 .Vt "struct timeval" Ta "get the retry timeout"
341 .It Dv CLSET_CONNECT Ta Vt "int" Ta use Xr connect 2
344 The retry timeout is the time that
346 waits for the server to reply before
347 retransmitting the request.
351 .Fn clnt_freeres "CLIENT *clnt" "xdrproc_t outproc" "char *out"
354 A macro that frees any data allocated by the
356 system when it decoded the results of an
361 is the address of the results, and
365 routine describing the results.
366 This routine returns one if the results were successfully
374 .Fn clnt_geterr "CLIENT *clnt" "struct rpc_err *errp"
377 A macro that copies the error structure out of the client
379 to the structure at address
386 .Fn clnt_pcreateerror "const char *s"
389 prints a message to standard error indicating
392 handle could not be created.
393 The message is prepended with string
408 .Fn clnt_perrno "enum clnt_stat stat"
411 Print a message to standard error corresponding
412 to the condition indicated by
419 .Fn clnt_perror "CLIENT *clnt" "const char *s"
422 Print a message to standard error indicating why an
426 is the handle used to do the call.
427 The message is prepended with string
437 .Fn clnt_spcreateerror "const char *s"
441 .Fn clnt_pcreateerror ,
442 except that it returns a string
443 instead of printing to the standard error.
445 Bugs: returns pointer to static data that is overwritten
452 .Fn clnt_sperrno "enum clnt_stat stat"
455 Take the same arguments as
457 but instead of sending a message to the standard error
460 call failed, return a pointer to a string which contains
462 The string ends with a newline
468 if the program does not have a standard error (as a program
469 running as a server quite likely does not), or if the
471 does not want the message to be output with
473 or if a message format different from that supported by
480 .Fn clnt_spcreateerror ,
482 returns pointer to static data, but the
483 result will not get overwritten on each call.
489 .Fn clnt_sperror "CLIENT *rpch" "const char *s"
496 it returns a string instead of printing to standard error.
498 Bugs: returns pointer to static data that is overwritten
505 .Fn clntraw_create "u_long prognum" "u_long versnum"
508 This routine creates a toy
510 client for the remote program
514 The transport used to pass messages to the service is
515 actually a buffer within the process's address space, so the
518 server should live in the same address space; see
520 This allows simulation of
524 overheads, such as round trip times, without any
535 .Fa "struct sockaddr_in *addr"
544 This routine creates an
546 client for the remote program
553 The remote program is located at Internet
558 is zero, then it is set to the actual port that the remote
559 program is listening on (the remote
561 service is consulted for this information).
564 is a socket; if it is
566 then this routine opens a new one and sets
573 the user may specify the size of the send and receive buffers
578 values of zero choose suitable defaults.
588 .Fa "struct sockaddr_in *addr"
591 .Fa "struct timeval wait"
596 This routine creates an
598 client for the remote program
605 The remote program is located at Internet
610 is zero, then it is set to actual port that the remote
611 program is listening on (the remote
613 service is consulted for this information).
616 is a socket; if it is
618 then this routine opens a new one and sets
622 transport resends the call message in intervals of
624 time until a response is received or until the call times
626 The total time for the call to time out is specified by
632 messages can only hold up to 8 Kbytes
633 of encoded data, this transport cannot be used for procedures
634 that take large arguments or return huge results.
640 .Fo clntudp_bufcreate
641 .Fa "struct sockaddr_in *addr"
644 .Fa "struct timeval wait"
646 .Fa "unsigned int sendsize"
647 .Fa "unsigned int recosize"
651 This routine creates an
653 client for the remote program
660 The remote program is located at Internet
665 is zero, then it is set to actual port that the remote
666 program is listening on (the remote
668 service is consulted for this information).
671 is a socket; if it is
673 then this routine opens a new one and sets
677 transport resends the call message in intervals of
679 time until a response is received or until the call times
681 The total time for the call to time out is specified by
684 This allows the user to specify the maximum packet size
685 for sending and receiving
694 .Fn get_myaddress "struct sockaddr_in *addr"
701 without consulting the library routines that deal with
703 The port number is always set to
705 Returns zero on success, non-zero on failure.
708 .Ft "struct pmaplist *"
711 .Fn pmap_getmaps "struct sockaddr_in *addr"
714 A user interface to the
716 service, which returns a list of the current
718 program\-to\-port mappings
719 on the host located at
723 This routine can return
734 .Fa "struct sockaddr_in *addr"
737 .Fa "u_long protocol"
741 A user interface to the
743 service, which returns the port number
744 on which waits a service that supports program number
748 and speaks the transport protocol associated with
756 A return value of zero means that the mapping does not exist
760 system failed to contact the remote
763 In the latter case, the global variable
774 .Fa "struct sockaddr_in *addr"
778 .Fa "xdrproc_t inproc"
780 .Fa "xdrproc_t outproc"
782 .Fa "struct timeval tout"
787 A user interface to the
789 service, which instructs
797 call on your behalf to a procedure on that host.
800 will be modified to the program's port number if the
803 The definitions of other parameters are discussed
808 This procedure should be used for a
817 .Fn pmap_set "u_long prognum" "u_long versnum" "u_long protocol" "u_short port"
820 A user interface to the
822 service, which establishes a mapping between the triple
823 .Pq Fa prognum , versnum , protocol
835 This routine returns one if it succeeds, zero otherwise.
836 Automatically done by
841 .Fn pmap_unset "u_long prognum" "u_long versnum"
844 A user interface to the
846 service, which destroys all mapping between the triple
847 .Pq Fa prognum , versnum , *
853 This routine returns one if it succeeds, zero
862 .Fa "char *(*procname)(void)"
863 .Fa "xdrproc_t inproc"
864 .Fa "xdrproc_t outproc"
873 If a request arrives for program
880 is called with a pointer to its parameter(s);
882 should return a pointer to its static result(s);
884 is used to decode the parameters while
886 is used to encode the results.
887 This routine returns zero if the registration succeeded, \-1
890 Warning: remote procedures registered in this form
891 are accessed using the
898 .Vt "struct rpc_createerr" rpc_createerr ;
901 A global variable whose value is set by any
903 client creation routine
904 that does not succeed.
906 .Fn clnt_pcreateerror
907 to print the reason why.
911 .Fn svc_destroy "SVCXPRT * xprt"
914 A macro that destroys the
916 service transport handle,
918 Destruction usually involves deallocation
919 of private data structures, including
924 is undefined after calling this routine.
927 .Vt fd_set svc_fdset ;
930 A global variable reflecting the
933 read file descriptor bit mask; it is suitable as a template parameter
937 This is only of interest
938 if a service implementor does not call
940 but rather does his own asynchronous event processing.
941 This variable is read\-only (do not pass its address to
943 yet it may change after calls to
945 or any creation routines.
946 As well, note that if the process has descriptor limits
947 which are extended beyond
949 this variable will only be usable for the first
959 but limited to 32 descriptors.
961 interface is obsoleted by
966 .Fn svc_freeargs "SVCXPRT *xprt" "xdrproc_t inproc" "char *in"
969 A macro that frees any data allocated by the
971 system when it decoded the arguments to a service procedure
974 This routine returns 1 if the results were successfully
980 .Fn svc_getargs "SVCXPRT *xprt" "xdrproc_t inproc" "char *in"
983 A macro that decodes the arguments of an
988 service transport handle,
992 is the address where the arguments will be placed;
996 routine used to decode the arguments.
997 This routine returns one if decoding succeeds, and zero
1001 .Ft "struct sockaddr_in *"
1004 .Fn svc_getcaller "SVCXPRT *xprt"
1007 The approved way of getting the network address of the caller
1008 of a procedure associated with the
1010 service transport handle,
1015 .Fn svc_getreqset "fd_set *rdfds"
1018 This routine is only of interest if a service implementor
1021 but instead implements custom asynchronous event processing.
1022 It is called when the
1024 system call has determined that an
1026 request has arrived on some
1030 is the resultant read file descriptor bit mask.
1031 The routine returns when all sockets associated with the
1038 .Fn svc_getreq "int rdfds"
1043 but limited to 32 descriptors.
1044 This interface is obsoleted by
1051 .Fa "u_long prognum"
1052 .Fa "u_long versnum"
1053 .Fa "void (*dispatch)(struct svc_req *, SVCXPRT *)"
1062 with the service dispatch procedure,
1066 is zero, the service is not registered with the
1071 is non-zero, then a mapping of the triple
1072 .Pq Fa prognum , versnum , protocol
1075 is established with the local
1085 has the following form:
1086 .Bd -ragged -offset indent
1088 .Fn dispatch "struct svc_req *request" "SVCXPRT *xprt"
1093 routine returns one if it succeeds, and zero otherwise.
1099 This routine never returns.
1102 requests to arrive, and calls the appropriate service
1106 This procedure is usually waiting for a
1108 system call to return.
1112 .Fn svc_sendreply "SVCXPRT *xprt" "xdrproc_t outproc" "char *out"
1117 service's dispatch routine to send the results of a
1118 remote procedure call.
1121 is the request's associated transport handle;
1125 routine which is used to encode the results; and
1127 is the address of the results.
1128 This routine returns one if it succeeds, zero otherwise.
1134 .Fn svc_unregister "u_long prognum" "u_long versnum"
1137 Remove all mapping of the double
1138 .Pq Fa prognum , versnum
1139 to dispatch routines, and of the triple
1140 .Pq Fa prognum , versnum , *
1147 .Fn svcerr_auth "SVCXPRT *xprt" "enum auth_stat why"
1150 Called by a service dispatch routine that refuses to perform
1151 a remote procedure call due to an authentication error.
1157 .Fn svcerr_decode "SVCXPRT *xprt"
1160 Called by a service dispatch routine that cannot successfully
1161 decode its parameters.
1169 .Fn svcerr_noproc "SVCXPRT *xprt"
1172 Called by a service dispatch routine that does not implement
1173 the procedure number that the caller requests.
1179 .Fn svcerr_noprog "SVCXPRT *xprt"
1182 Called when the desired program is not registered with the
1185 Service implementors usually do not need this routine.
1191 .Fn svcerr_progvers "SVCXPRT *xprt" "u_long low_vers" "u_long high_vers"
1194 Called when the desired version of a program is not registered
1198 Service implementors usually do not need this routine.
1204 .Fn svcerr_systemerr "SVCXPRT *xprt"
1207 Called by a service dispatch routine when it detects a system
1209 not covered by any particular protocol.
1210 For example, if a service can no longer allocate storage,
1211 it may call this routine.
1217 .Fn svcerr_weakauth "SVCXPRT *xprt"
1220 Called by a service dispatch routine that refuses to perform
1221 a remote procedure call due to insufficient
1222 authentication parameters.
1224 .Fn svcerr_auth xprt AUTH_TOOWEAK .
1230 .Fn svcraw_create void
1233 This routine creates a toy
1235 service transport, to which it returns a pointer.
1237 is really a buffer within the process's address space,
1238 so the corresponding
1240 client should live in the same
1243 .Fn clntraw_create .
1244 This routine allows simulation of
1248 overheads (such as round trip times), without any kernel
1250 This routine returns
1258 .Fn svctcp_create "int sock" "u_int send_buf_size" "u_int recv_buf_size"
1261 This routine creates a
1262 .Tn TCP/IP Ns \-based
1264 service transport, to which it returns a pointer.
1265 The transport is associated with the socket
1269 in which case a new socket is created.
1270 If the socket is not bound to a local
1272 port, then this routine binds it to an arbitrary port.
1275 is the transport's socket descriptor, and
1277 is the transport's port number.
1278 This routine returns
1286 users may specify the size of buffers; values of zero
1287 choose suitable defaults.
1293 .Fn svcfd_create "int fd" "u_int sendsize" "u_int recvsize"
1296 Create a service on top of any open descriptor.
1299 descriptor is a connected socket for a stream protocol such
1305 indicate sizes for the send and receive buffers.
1307 zero, a reasonable default is chosen.
1313 .Fn svcudp_bufcreate "int sock" "u_int sendsize" "u_int recvsize"
1316 This routine creates a
1317 .Tn UDP/IP Ns \-based
1319 service transport, to which it returns a pointer.
1320 The transport is associated with the socket
1324 in which case a new socket is created.
1325 If the socket is not bound to a local
1327 port, then this routine binds it to an arbitrary port.
1331 is the transport's socket descriptor, and
1333 is the transport's port number.
1334 This routine returns
1338 This allows the user to specify the maximum packet size for sending and
1346 .Fn xdr_accepted_reply "XDR *xdrs" "struct accepted_reply *ar"
1352 This routine is useful for users who
1355 messages without using the
1361 .Fn xdr_authunix_parms "XDR *xdrs" "struct authunix_parms *aupp"
1367 This routine is useful for users
1368 who wish to generate these credentials without using the
1370 authentication package.
1377 .Fn xdr_callhdr "XDR *xdrs" "struct rpc_msg *chdr"
1382 call header messages.
1383 This routine is useful for users who wish to generate
1385 messages without using the
1391 .Fn xdr_callmsg "XDR *xdrs" "struct rpc_msg *cmsg"
1397 This routine is useful for users who wish to generate
1399 messages without using the
1405 .Fn xdr_opaque_auth "XDR *xdrs" "struct opaque_auth *ap"
1410 authentication information messages.
1411 This routine is useful for users who wish to generate
1413 messages without using the
1422 .Fn xdr_pmap "XDR *xdrs" "struct pmap *regs"
1425 Used for describing parameters to various
1427 procedures, externally.
1428 This routine is useful for users who wish to generate
1429 these parameters without using the
1435 .Fn xdr_pmaplist "XDR *xdrs" "struct pmaplist **rp"
1438 Used for describing a list of port mappings, externally.
1439 This routine is useful for users who wish to generate
1440 these parameters without using the
1446 .Fn xdr_rejected_reply "XDR *xdrs" "struct rejected_reply *rr"
1452 This routine is useful for users who wish to generate
1454 messages without using the
1460 .Fn xdr_replymsg "XDR *xdrs" "struct rpc_msg *rmsg"
1466 This routine is useful for users who wish to generate
1468 style messages without using the
1476 .Fn xprt_register "SVCXPRT *xprt"
1481 service transport handles are created,
1482 they should register themselves with the
1485 This routine modifies the global variable
1487 Service implementors usually do not need this routine.
1493 .Fn xprt_unregister "SVCXPRT *xprt"
1498 service transport handle is destroyed,
1499 it should unregister itself with the
1502 This routine modifies the global variable
1504 Service implementors usually do not need this routine.
1510 .%T "Remote Procedure Calls: Protocol Specification"
1513 .%T "Remote Procedure Call Programming Guide"
1516 .%T "rpcgen Programming Guide"
1519 .%T "RPC: Remote Procedure Call Protocol Specification"
1521 .%Q "Sun Microsystems, Inc., USC-ISI"