1 .\" @(#)rpc.3n 2.4 88/08/08 4.0 RPCSRC; from 1.19 88/06/24 SMI
4 rpc \- library routines for remote procedure calls
5 .SH "SYNOPSIS AND DESCRIPTION"
6 These routines allow C programs to make procedure
7 calls on other machines across the network.
8 First, the client calls a procedure to send a
9 data packet to the server.
10 Upon receipt of the packet, the server calls a dispatch routine
11 to perform the requested service, and then sends back a
13 Finally, the procedure call returns to the client.
15 Routines that are used for Secure RPC (DES authentication) are described in
17 Secure RPC can be used only if DES encryption is available.
37 A macro that destroys the authentication information associated with
39 Destruction usually involves deallocation of private data
40 structures. The use of
42 is undefined after calling
57 authentication handle that passes nonusable authentication
58 information with each remote procedure call. This is the
59 default authentication used by
67 authunix_create(host, uid, gid, len, aup_gids)
69 int uid, gid, len, *aup.gids;
75 authentication handle that contains
77 authentication information.
80 is the name of the machine on which the information was
86 is the user's current group
91 refer to a counted array of groups to which the user belongs.
92 It is easy to impersonate a user.
100 authunix_create_default()
106 with the appropriate parameters.
113 callrpc(host, prognum, versnum, procnum, inproc, in, outproc, out)
115 u_long prognum, versnum, procnum;
117 xdrproc_t inproc, outproc;
121 Call the remote procedure associated with
130 is the address of the procedure's argument(s), and
132 is the address of where to place the result(s);
134 is used to encode the procedure's parameters, and
136 is used to decode the procedure's results.
137 This routine returns zero if it succeeds, or the value of
139 cast to an integer if it fails.
142 is handy for translating failure statuses into messages.
144 Warning: calling remote procedures with this routine
150 You do not have control of timeouts or authentication using
159 clnt_broadcast(prognum, versnum, procnum, inproc, in, outproc, out, eachresult)
160 u_long prognum, versnum, procnum;
162 xdrproc_t inproc, outproc;
163 resultproc_t eachresult;
169 except the call message is broadcast to all locally
170 connected broadcast nets. Each time it receives a
171 response, this routine calls
178 eachresult(out, addr)
180 struct sockaddr_in *addr;
190 .BR clnt_broadcast() ,
191 except that the remote procedure's output is decoded there;
193 points to the address of the machine that sent the results.
198 waits for more replies; otherwise it returns with appropriate
201 Warning: broadcast sockets are limited in size to the
202 maximum transfer unit of the data link. For ethernet,
203 this value is 1500 bytes.
211 clnt_call(clnt, procnum, inproc, in, outproc, out, tout)
215 xdrproc_t inproc, outproc;
221 A macro that calls the remote procedure
223 associated with the client handle,
225 which is obtained with an
227 client creation routine such as
231 is the address of the procedure's argument(s), and
233 is the address of where to place the result(s);
235 is used to encode the procedure's parameters, and
237 is used to decode the procedure's results;
239 is the time allowed for results to come back.
251 A macro that destroys the client's
253 handle. Destruction usually involves deallocation
254 of private data structures, including
258 is undefined after calling
262 library opened the associated socket, it will close it also.
263 Otherwise, the socket remains open.
271 clnt_create(host, prog, vers, proto)
278 Generic client creation routine.
280 identifies the name of the remote host where the server
283 indicates which kind of transport protocol to use. The
284 currently supported values for this field are \(lqudp\(rq
286 Default timeouts are set, but can be modified using
291 has its shortcomings. Since
294 messages can only hold up to 8 Kbytes of encoded data,
295 this transport cannot be used for procedures that take
296 large arguments or return huge results.
304 clnt_control(cl, req, info)
310 A macro used to change or retrieve various information
311 about a client object.
313 indicates the type of operation, and
315 is a pointer to the information. For both
319 the supported values of
321 and their argument types and what they do are:
324 .ta +2.0i +2.0i +2.0i
325 .SM CLSET_TIMEOUT\s0 struct timeval set total timeout
326 .SM CLGET_TIMEOUT\s0 struct timeval get total timeout
329 Note: if you set the timeout using
331 the timeout parameter passed to
333 will be ignored in all future calls.
336 .SM CLGET_SERVER_ADDR\s0 struct sockaddr_in get server's address
340 The following operations are valid for
345 .ta +2.0i +2.0i +2.0i
346 .SM CLSET_RETRY_TIMEOUT\s0 struct timeval set the retry timeout
347 .SM CLGET_RETRY_TIMEOUT\s0 struct timeval get the retry timeout
351 The retry timeout is the time that
353 waits for the server to reply before
354 retransmitting the request.
361 clnt_freeres(clnt, outproc, out)
368 A macro that frees any data allocated by the
370 system when it decoded the results of an
375 is the address of the results, and
379 routine describing the results.
380 This routine returns one if the results were successfully
390 clnt_geterr(clnt, errp)
392 struct rpc_err *errp;
396 A macro that copies the error structure out of the client
398 to the structure at address
412 Print a message to standard error indicating
415 handle could not be created.
416 The message is prepended with string
421 .BR clntraw_create() ,
422 .BR clnttcp_create() ,
438 Print a message to standard error corresponding
439 to the condition indicated by
455 Print a message to standard error indicating why an
459 is the handle used to do the call.
460 The message is prepended with string
478 .BR clnt_pcreateerror() ,
479 except that it returns a string
480 instead of printing to the standard error.
482 Bugs: returns pointer to static data that is overwritten
496 Take the same arguments as
498 but instead of sending a message to the standard error
501 call failed, return a pointer to a string which contains
502 the message. The string ends with a
508 if the program does not have a standard error (as a program
509 running as a server quite likely does not), or if the
511 does not want the message to be output with
513 or if a message format different than that supported by
519 .BR clnt_spcreaterror() ,
521 returns pointer to static data, but the
522 result will not get overwritten on each call.
530 clnt_sperror(rpch, s)
540 it returns a string instead of printing to standard error.
542 Bugs: returns pointer to static data that is overwritten
551 clntraw_create(prognum, versnum)
552 u_long prognum, versnum;
556 This routine creates a toy
558 client for the remote program
562 The transport used to pass messages to the service is
563 actually a buffer within the process's address space, so the
566 server should live in the same address space; see
567 .BR svcraw_create() .
568 This allows simulation of
572 overheads, such as round trip times, without any
573 kernel interference. This routine returns
583 clnttcp_create(addr, prognum, versnum, sockp, sendsz, recvsz)
584 struct sockaddr_in *addr;
585 u_long prognum, versnum;
587 u_int sendsz, recvsz;
591 This routine creates an
593 client for the remote program
599 as a transport. The remote program is located at Internet
603 .\"The following in-line font conversion is necessary for the hyphen indicator
604 \fB\%addr\->sin_port\fR
605 is zero, then it is set to the actual port that the remote
606 program is listening on (the remote
608 service is consulted for this information). The parameter
610 is a socket; if it is
611 .BR \s-1RPC_ANYSOCK\s0 ,
612 then this routine opens a new one and sets
619 the user may specify the size of the send and receive buffers
624 values of zero choose suitable defaults.
635 clntudp_create(addr, prognum, versnum, wait, sockp)
636 struct sockaddr_in *addr;
637 u_long prognum, versnum;
643 This routine creates an
645 client for the remote program
651 as a transport. The remote program is located at Internet
655 \fB\%addr\->sin_port\fR
656 is zero, then it is set to actual port that the remote
657 program is listening on (the remote
659 service is consulted for this information). The parameter
661 is a socket; if it is
662 .BR \s-1RPC_ANYSOCK\s0 ,
663 then this routine opens a new one and sets
667 transport resends the call message in intervals of
669 time until a response is received or until the call times
671 The total time for the call to time out is specified by
677 messages can only hold up to 8 Kbytes
678 of encoded data, this transport cannot be used for procedures
679 that take large arguments or return huge results.
687 clntudp_bufcreate(addr, prognum, versnum, wait, sockp, sendsize, recosize)
688 struct sockaddr_in *addr;
689 u_long prognum, versnum;
692 unsigned int sendsize;
693 unsigned int recosize;
697 This routine creates an
699 client for the remote program
705 as a transport. The remote program is located at Internet
709 \fB\%addr\->sin_port\fR
710 is zero, then it is set to actual port that the remote
711 program is listening on (the remote
713 service is consulted for this information). The parameter
715 is a socket; if it is
716 .BR \s-1RPC_ANYSOCK\s0 ,
717 then this routine opens a new one and sets
721 transport resends the call message in intervals of
723 time until a response is received or until the call times
725 The total time for the call to time out is specified by
728 This allows the user to specify the maximum packet size for sending and receiving
740 struct sockaddr_in *addr;
748 without consulting the library routines that deal with
750 The port number is always set to
751 .BR htons(\s-1PMAPPORT\s0) .
760 struct sockaddr_in *addr;
764 A user interface to the
766 service, which returns a list of the current
768 program-to-port mappings
769 on the host located at
773 This routine can return
776 .RB ` "rpcinfo \-p" '
785 pmap_getport(addr, prognum, versnum, protocol)
786 struct sockaddr_in *addr;
787 u_long prognum, versnum, protocol;
791 A user interface to the
793 service, which returns the port number
794 on which waits a service that supports program number
798 and speaks the transport protocol associated with
806 .BR \s-1IPPROTO_TCP\s0 .
807 A return value of zero means that the mapping does not exist
811 system failed to contact the remote
813 service. In the latter case, the global variable
825 pmap_rmtcall(addr, prognum, versnum, procnum, inproc, in, outproc, out, tout, portp)
826 struct sockaddr_in *addr;
827 u_long prognum, versnum, procnum;
829 xdrproc_t inproc, outproc;
835 A user interface to the
837 service, which instructs
845 call on your behalf to a procedure on that host.
848 will be modified to the program's port number if the
850 succeeds. The definitions of other parameters are discussed
855 This procedure should be used for a \(lqping\(rq and nothing
858 .BR clnt_broadcast() .
865 pmap_set(prognum, versnum, protocol, port)
866 u_long prognum, versnum, protocol;
871 A user interface to the
873 service, which establishes a mapping between the triple
874 .RI [ prognum , versnum , protocol\fR]
879 service. The value of
885 .BR \s-1IPPROTO_TCP\s0 .
886 This routine returns one if it succeeds, zero otherwise.
887 Automatically done by
895 pmap_unset(prognum, versnum)
896 u_long prognum, versnum;
900 A user interface to the
902 service, which destroys all mapping between the triple
903 .RI [ prognum , versnum , *\fR]
908 service. This routine returns one if it succeeds, zero
916 registerrpc(prognum, versnum, procnum, procname, inproc, outproc)
917 u_long prognum, versnum, procnum;
918 char *(*procname) () ;
919 xdrproc_t inproc, outproc;
927 service package. If a request arrives for program
934 is called with a pointer to its parameter(s);
936 should return a pointer to its static result(s);
938 is used to decode the parameters while
940 is used to encode the results.
941 This routine returns zero if the registration succeeded, \-1
944 Warning: remote procedures registered in this form
945 are accessed using the
956 struct rpc_createerr rpc_createerr;
960 A global variable whose value is set by any
962 client creation routine
963 that does not succeed. Use the routine
964 .B clnt_pcreateerror()
965 to print the reason why.
977 A macro that destroys the
979 service transport handle,
981 Destruction usually involves deallocation
982 of private data structures, including
986 is undefined after calling this routine.
997 A global variable reflecting the
1000 read file descriptor bit mask; it is suitable as a parameter
1003 system call. This is only of interest
1004 if a service implementor does not call
1006 but rather does his own asynchronous event processing.
1007 This variable is read-only (do not pass its address to
1009 yet it may change after calls to
1011 or any creation routines.
1024 but limited to 32 descriptors. This
1025 interface is obsoleted by
1033 svc_freeargs(xprt, inproc, in)
1034 \s-1SVCXPRT\s0 *xprt;
1040 A macro that frees any data allocated by the
1042 system when it decoded the arguments to a service procedure
1045 This routine returns 1 if the results were successfully
1054 svc_getargs(xprt, inproc, in)
1055 \s-1SVCXPRT\s0 *xprt;
1061 A macro that decodes the arguments of an
1066 service transport handle,
1070 is the address where the arguments will be placed;
1074 routine used to decode the arguments.
1075 This routine returns one if decoding succeeds, and zero
1083 struct sockaddr_in *
1085 \s-1SVCXPRT\s0 *xprt;
1089 The approved way of getting the network address of the caller
1090 of a procedure associated with the
1092 service transport handle,
1100 svc_getreqset(rdfds)
1105 This routine is only of interest if a service implementor
1108 but instead implements custom asynchronous event processing.
1109 It is called when the
1111 system call has determined that an
1113 request has arrived on some
1117 is the resultant read file descriptor bit mask.
1118 The routine returns when all sockets associated with the
1134 .BR svc_getreqset() ,
1135 but limited to 32 descriptors. This interface is obsoleted by
1136 .BR svc_getreqset() .
1143 svc_register(xprt, prognum, versnum, dispatch, protocol)
1144 \s-1SVCXPRT\s0 *xprt;
1145 u_long prognum, versnum;
1146 void (*dispatch) ();
1155 with the service dispatch procedure,
1159 is zero, the service is not registered with the
1163 is non-zero, then a mapping of the triple
1164 .RI [ prognum , versnum , protocol\fR]
1166 \fB\%xprt\->xp_port\fR
1167 is established with the local
1180 has the following form:
1184 dispatch(request, xprt)
1185 struct svc_req *request;
1186 \s-1SVCXPRT\s0 *xprt;
1193 routine returns one if it succeeds, and zero otherwise.
1204 This routine never returns. It waits for
1206 requests to arrive, and calls the appropriate service
1209 when one arrives. This procedure is usually waiting for a
1211 system call to return.
1218 svc_sendreply(xprt, outproc, out)
1219 \s-1SVCXPRT\s0 *xprt;
1227 service's dispatch routine to send the results of a
1228 remote procedure call. The parameter
1230 is the request's associated transport handle;
1234 routine which is used to encode the results; and
1236 is the address of the results.
1237 This routine returns one if it succeeds, zero otherwise.
1245 svc_unregister(prognum, versnum)
1246 u_long prognum, versnum;
1250 Remove all mapping of the double
1251 .RI [ prognum , versnum ]
1252 to dispatch routines, and of the triple
1253 .RI [ prognum , versnum , *\fR]
1262 svcerr_auth(xprt, why)
1263 \s-1SVCXPRT\s0 *xprt;
1268 Called by a service dispatch routine that refuses to perform
1269 a remote procedure call due to an authentication error.
1278 \s-1SVCXPRT\s0 *xprt;
1282 Called by a service dispatch routine that cannot successfully
1283 decode its parameters. See also
1293 \s-1SVCXPRT\s0 *xprt;
1297 Called by a service dispatch routine that does not implement
1298 the procedure number that the caller requests.
1307 \s-1SVCXPRT\s0 *xprt;
1311 Called when the desired program is not registered with the
1313 package. Service implementors usually do not need this routine.
1321 svcerr_progvers(xprt)
1322 \s-1SVCXPRT\s0 *xprt;
1326 Called when the desired version of a program is not registered
1329 package. Service implementors usually do not need this routine.
1337 svcerr_systemerr(xprt)
1338 \s-1SVCXPRT\s0 *xprt;
1342 Called by a service dispatch routine when it detects a system
1344 not covered by any particular protocol.
1345 For example, if a service can no longer allocate storage,
1346 it may call this routine.
1354 svcerr_weakauth(xprt)
1355 \s-1SVCXPRT\s0 *xprt;
1359 Called by a service dispatch routine that refuses to perform
1360 a remote procedure call due to insufficient
1361 authentication parameters. The routine calls
1362 .BR "svcerr_auth(xprt, \s-1AUTH_TOOWEAK\s0)" .
1370 svcfd_create(fd, sendsize, recvsize)
1377 Create a service on top of any open descriptor. Typically,
1379 descriptor is a connected socket for a stream protocol such
1385 indicate sizes for the send and receive buffers. If they are
1386 zero, a reasonable default is chosen.
1398 This routine creates a toy
1400 service transport, to which it returns a pointer. The
1402 is really a buffer within the process's address space,
1403 so the corresponding
1405 client should live in the same
1408 .BR clntraw_create() .
1409 This routine allows simulation of
1413 overheads (such as round trip times), without any kernel
1415 This routine returns
1425 svctcp_create(sock, send_buf_size, recv_buf_size)
1427 u_int send_buf_size, recv_buf_size;
1431 This routine creates a
1434 service transport, to which it returns a pointer.
1435 The transport is associated with the socket
1438 .BR \s-1RPC_ANYSOCK\s0 ,
1439 in which case a new socket is created.
1440 If the socket is not bound to a local
1442 port, then this routine binds it to an arbitrary port. Upon
1444 \fB\%xprt\->xp_sock\fR
1445 is the transport's socket descriptor, and
1446 \fB\%xprt\->xp_port\fR
1447 is the transport's port number.
1448 This routine returns
1455 users may specify the size of buffers; values of zero
1456 choose suitable defaults.
1464 svcudp_bufcreate(sock, sendsize, recosize)
1469 This routine creates a
1472 service transport, to which it returns a pointer.
1473 The transport is associated with the socket
1476 .BR \s-1RPC_ANYSOCK\s0 ,
1477 in which case a new socket is created.
1478 If the socket is not bound to a local
1480 port, then this routine binds it to an arbitrary port. Upon
1482 \fB\%xprt\->xp_sock\fR
1483 is the transport's socket descriptor, and
1484 \fB\%xprt\->xp_port\fR
1485 is the transport's port number.
1486 This routine returns
1490 This allows the user to specify the maximum packet size for sending and
1506 This call is equivalent to
1507 \fIsvcudp_bufcreate(sock,SZ,SZ)\fP
1508 for some default size \fISZ\fP.
1515 xdr_accepted_reply(xdrs, ar)
1517 struct accepted_reply *ar;
1523 reply messages. This routine is useful for users who
1526 messages without using the
1535 xdr_authunix_parms(xdrs, aupp)
1537 struct authunix_parms *aupp;
1543 credentials. This routine is useful for users
1544 who wish to generate these credentials without using the
1546 authentication package.
1554 xdr_callhdr(xdrs, chdr)
1556 struct rpc_msg *chdr;
1562 call header messages.
1563 This routine is useful for users who wish to generate
1565 messages without using the
1574 xdr_callmsg(xdrs, cmsg)
1576 struct rpc_msg *cmsg;
1583 This routine is useful for users who wish to generate
1585 messages without using the
1594 xdr_opaque_auth(xdrs, ap)
1596 struct opaque_auth *ap;
1602 authentication information messages.
1603 This routine is useful for users who wish to generate
1605 messages without using the
1614 xdr_pmap(xdrs, regs)
1620 Used for describing parameters to various
1622 procedures, externally.
1623 This routine is useful for users who wish to generate
1624 these parameters without using the
1633 xdr_pmaplist(xdrs, rp)
1635 struct pmaplist **rp;
1639 Used for describing a list of port mappings, externally.
1640 This routine is useful for users who wish to generate
1641 these parameters without using the
1650 xdr_rejected_reply(xdrs, rr)
1652 struct rejected_reply *rr;
1659 This routine is useful for users who wish to generate
1661 messages without using the
1670 xdr_replymsg(xdrs, rmsg)
1672 struct rpc_msg *rmsg;
1679 This routine is useful for users who wish to generate
1681 style messages without using the
1692 \s-1SVCXPRT\s0 *xprt;
1698 service transport handles are created,
1699 they should register themselves with the
1702 This routine modifies the global variable
1704 Service implementors usually do not need this routine.
1712 xprt_unregister(xprt)
1713 \s-1SVCXPRT\s0 *xprt;
1719 service transport handle is destroyed,
1720 it should unregister itself with the
1723 This routine modifies the global variable
1725 Service implementors usually do not need this routine.
1730 The following manuals:
1733 Remote Procedure Calls: Protocol Specification
1735 Remote Procedure Call Programming Guide
1737 rpcgen Programming Guide
1741 .IR "\s-1RPC\s0: Remote Procedure Call Protocol Specification" ,
1742 .SM RFC1050, Sun Microsystems, Inc.,