1 .\" @(#)rpc.3n 2.4 88/08/08 4.0 RPCSRC; from 1.19 88/06/24 SMI
2 .\" $NetBSD: rpc_soc.3,v 1.2 2000/06/07 13:39:43 simonb Exp $
3 .\" $FreeBSD: src/lib/libc/rpc/rpc_soc.3,v 1.12 2003/02/06 11:04:47 charnier Exp $
13 .Nm authunix_create_default ,
22 .Nm clnt_pcreateerror ,
25 .Nm clnt_spcreateerror ,
30 .Nm clntudp_bufcreate ,
57 .Nm svcerr_systemerr ,
60 .Nm svcunixfd_create ,
63 .Nm xdr_accepted_reply ,
64 .Nm xdr_authunix_parms ,
70 .Nm xdr_rejected_reply ,
74 .Nd "library routines for remote procedure calls"
80 for function declarations.
87 functions described in this page are the old, TS-RPC
88 interface to the XDR and RPC library, and exist for backward compatibility.
89 The new interface is described in the pages
94 These routines allow C programs to make procedure
95 calls on other machines across the network.
96 First, the client calls a procedure to send a
97 data packet to the server.
98 Upon receipt of the packet, the server calls a dispatch routine
99 to perform the requested service, and then sends back a
101 Finally, the procedure call returns to the client.
103 Routines that are used for Secure
105 authentication) are described in
111 encryption is available.
112 .Bl -tag -width indent -compact
118 .Fn auth_destroy "AUTH *auth"
121 A macro that destroys the authentication information associated with
123 Destruction usually involves deallocation of private data
127 is undefined after calling
139 authentication handle that passes nonusable authentication
140 information with each remote procedure call.
142 default authentication used by
149 .Fn authunix_create "char *host" "int uid" "int gid" "int len" "int *aup_gids"
154 authentication handle that contains
156 authentication information.
160 is the name of the machine on which the information was
163 is the user's user ID;
165 is the user's current group ID;
169 refer to a counted array of groups to which the user belongs.
170 It is easy to impersonate a user.
176 .Fn authunix_create_default
181 with the appropriate arguments.
190 .Fa "xdrproc_t inproc"
192 .Fa "xdrproc_t outproc"
197 Call the remote procedure associated with
207 is the address of the procedure's argument(s), and
209 is the address of where to place the result(s);
211 is used to encode the procedure's arguments, and
213 is used to decode the procedure's results.
214 This routine returns zero if it succeeds, or the value of
216 cast to an integer if it fails.
219 is handy for translating failure statuses into messages.
221 Warning: calling remote procedures with this routine
227 You do not have control of timeouts or authentication using
238 .Fa "xdrproc_t inproc"
240 .Fa "xdrproc_t outproc"
242 .Fa "bool_t (*eachresult)(caddr_t, struct sockaddr_in *)"
248 except the call message is broadcast to all locally
249 connected broadcast nets.
250 Each time it receives a
251 response, this routine calls
254 .Bd -ragged -offset indent
256 .Fn eachresult "caddr_t out" "struct sockaddr_in *addr"
265 except that the remote procedure's output is decoded there;
267 points to the address of the machine that sent the results.
272 waits for more replies; otherwise it returns with appropriate
275 Warning: broadcast sockets are limited in size to the
276 maximum transfer unit of the data link.
278 this value is 1500 bytes.
287 .Fa "xdrproc_t inproc"
289 .Fa "xdrproc_t outproc"
291 .Fa "struct timeval tout"
295 A macro that calls the remote procedure
297 associated with the client handle,
299 which is obtained with an
301 client creation routine such as
306 is the address of the procedure's argument(s), and
308 is the address of where to place the result(s);
310 is used to encode the procedure's arguments, and
312 is used to decode the procedure's results;
314 is the time allowed for results to come back.
318 .Fn clnt_destroy "CLIENT *clnt"
321 A macro that destroys the client's
324 Destruction usually involves deallocation
325 of private data structures, including
330 is undefined after calling
334 library opened the associated socket, it will close it also.
335 Otherwise, the socket remains open.
341 .Fn clnt_create "char *host" "u_long prog" "u_long vers" "char *proto"
344 Generic client creation routine.
348 identifies the name of the remote host where the server
353 indicates which kind of transport protocol to use.
355 currently supported values for this field are
359 Default timeouts are set, but can be modified using
364 has its shortcomings.
368 messages can only hold up to 8 Kbytes of encoded data,
369 this transport cannot be used for procedures that take
370 large arguments or return huge results.
376 .Fn clnt_control "CLIENT *cl" "u_int req" "char *info"
379 A macro used to change or retrieve various information
380 about a client object.
384 indicates the type of operation, and
386 is a pointer to the information.
391 the supported values of
393 and their argument types and what they do are:
394 .Bl -column "CLSET_RETRY_TIMEOUT" "struct sockaddr_in"
395 .It Dv CLSET_TIMEOUT Ta Xo
396 .Vt "struct timeval" Ta "set total timeout"
398 .It Dv CLGET_TIMEOUT Ta Xo
399 .Vt "struct timeval" Ta "get total timeout"
403 Note: if you set the timeout using
405 the timeout argument passed to
407 will be ignored in all future calls.
408 .Bl -column "CLSET_RETRY_TIMEOUT" "struct sockaddr_in"
409 .It Dv CLGET_SERVER_ADDR Ta Xo
410 .Vt "struct sockaddr_in" Ta "get server's address"
414 The following operations are valid for
417 .Bl -column "CLSET_RETRY_TIMEOUT" "struct sockaddr_in"
418 .It Dv CLSET_RETRY_TIMEOUT Ta Xo
419 .Vt "struct timeval" Ta "set the retry timeout"
421 .It Dv CLGET_RETRY_TIMEOUT Ta Xo
422 .Vt "struct timeval" Ta "get the retry timeout"
426 The retry timeout is the time that
428 waits for the server to reply before
429 retransmitting the request.
433 .Fn clnt_freeres "CLIENT *clnt" "xdrproc_t outproc" "char *out"
436 A macro that frees any data allocated by the
438 system when it decoded the results of an
444 is the address of the results, and
448 routine describing the results.
449 This routine returns one if the results were successfully
457 .Fn clnt_geterr "CLIENT *clnt" "struct rpc_err *errp"
460 A macro that copies the error structure out of the client
462 to the structure at address
469 .Fn clnt_pcreateerror "char *s"
472 prints a message to standard error indicating
475 handle could not be created.
476 The message is prepended with string
479 A newline is appended at the end of the message.
492 .Fn clnt_perrno "enum clnt_stat stat"
495 Print a message to standard error corresponding
496 to the condition indicated by
498 A newline is appended at the end of the message.
504 .Fn clnt_perror "CLIENT *clnt" "char *s"
507 Print a message to standard error indicating why an
511 is the handle used to do the call.
512 The message is prepended with string
515 A newline is appended at the end of the message.
523 .Fn clnt_spcreateerror "char *s"
527 .Fn clnt_pcreateerror ,
528 except that it returns a string
529 instead of printing to the standard error.
531 Bugs: returns pointer to static data that is overwritten
538 .Fn clnt_sperrno "enum clnt_stat stat"
541 Take the same arguments as
543 but instead of sending a message to the standard error
546 call failed, return a pointer to a string which contains
554 if the program does not have a standard error (as a program
555 running as a server quite likely does not), or if the
557 does not want the message to be output with
559 or if a message format different from that supported by
566 .Fn clnt_spcreateerror ,
568 returns pointer to static data, but the
569 result will not get overwritten on each call.
575 .Fn clnt_sperror "CLIENT *rpch" "char *s"
582 it returns a string instead of printing to standard error.
584 Bugs: returns pointer to static data that is overwritten
591 .Fn clntraw_create "u_long prognum" "u_long versnum"
594 This routine creates a toy
596 client for the remote program
600 The transport used to pass messages to the service is
601 actually a buffer within the process's address space, so the
604 server should live in the same address space; see
606 This allows simulation of
610 overheads, such as round trip times, without any
621 .Fa "struct sockaddr_in *addr"
630 This routine creates an
632 client for the remote program
639 The remote program is located at Internet
644 is zero, then it is set to the actual port that the remote
645 program is listening on (the remote
647 service is consulted for this information).
651 is a socket; if it is
653 then this routine opens a new one and sets
660 the user may specify the size of the send and receive buffers
666 values of zero choose suitable defaults.
676 .Fa "struct sockaddr_in *addr"
679 .Fa "struct timeval wait"
684 This routine creates an
686 client for the remote program
693 The remote program is located at Internet
698 is zero, then it is set to actual port that the remote
699 program is listening on (the remote
701 service is consulted for this information).
705 is a socket; if it is
707 then this routine opens a new one and sets
711 transport resends the call message in intervals of
713 time until a response is received or until the call times
715 The total time for the call to time out is specified by
721 messages can only hold up to 8 Kbytes
722 of encoded data, this transport cannot be used for procedures
723 that take large arguments or return huge results.
729 .Fo clntudp_bufcreate
730 .Fa "struct sockaddr_in *addr"
733 .Fa "struct timeval wait"
735 .Fa "unsigned int sendsize"
736 .Fa "unsigned int recosize"
740 This routine creates an
742 client for the remote program
749 The remote program is located at Internet
754 is zero, then it is set to actual port that the remote
755 program is listening on (the remote
757 service is consulted for this information).
761 is a socket; if it is
763 then this routine opens a new one and sets
767 transport resends the call message in intervals of
769 time until a response is received or until the call times
771 The total time for the call to time out is specified by
774 This allows the user to specify the maximum packet size
775 for sending and receiving
785 .Fa "struct sockaddr_un *raddr"
794 This routine creates an
803 sockets as a transport.
804 The local program is located at the
809 is a socket; if it is
811 then this routine opens a new one and sets
818 the user may specify the size of the send and receive buffers
824 values of zero choose suitable defaults.
833 .Fn get_myaddress "struct sockaddr_in *addr"
840 without consulting the library routines that deal with
842 The port number is always set to
844 Returns zero on success, non-zero on failure.
847 .Ft "struct pmaplist *"
850 .Fn pmap_getmaps "struct sockaddr_in *addr"
853 A user interface to the
855 service, which returns a list of the current
857 program\-to\-port mappings
858 on the host located at
862 This routine can return
873 .Fa "struct sockaddr_in *addr"
876 .Fa "u_long protocol"
880 A user interface to the
882 service, which returns the port number
883 on which waits a service that supports program number
887 and speaks the transport protocol associated with
895 A return value of zero means that the mapping does not exist
899 system failed to contact the remote
902 In the latter case, the global variable
913 .Fa "struct sockaddr_in *addr"
917 .Fa "xdrproc_t inproc"
919 .Fa "xdrproc_t outproc"
921 .Fa "struct timeval tout"
926 A user interface to the
928 service, which instructs
936 call on your behalf to a procedure on that host.
940 will be modified to the program's port number if the
943 The definitions of other arguments are discussed
948 This procedure should be used for a
957 .Fn pmap_set "u_long prognum" "u_long versnum" "u_long protocol" "u_short port"
960 A user interface to the
962 service, which establishes a mapping between the triple
963 .Pq Fa prognum , versnum , protocol
975 This routine returns one if it succeeds, zero otherwise.
976 Automatically done by
981 .Fn pmap_unset "u_long prognum" "u_long versnum"
984 A user interface to the
986 service, which destroys all mapping between the triple
987 .Pq Fa prognum , versnum , *
993 This routine returns one if it succeeds, zero
1000 .Fa "u_long versnum"
1001 .Fa "u_long procnum"
1002 .Fa "char *(*procname)(void)"
1003 .Fa "xdrproc_t inproc"
1004 .Fa "xdrproc_t outproc"
1013 If a request arrives for program
1020 is called with a pointer to its argument(s);
1022 should return a pointer to its static result(s);
1024 is used to decode the arguments while
1026 is used to encode the results.
1027 This routine returns zero if the registration succeeded, \-1
1030 Warning: remote procedures registered in this form
1031 are accessed using the
1038 .Vt "struct rpc_createerr" rpc_createerr ;
1041 A global variable whose value is set by any
1043 client creation routine
1044 that does not succeed.
1046 .Fn clnt_pcreateerror
1047 to print the reason why.
1051 .Fn svc_destroy "SVCXPRT * xprt"
1054 A macro that destroys the
1056 service transport handle,
1058 Destruction usually involves deallocation
1059 of private data structures, including
1064 is undefined after calling this routine.
1067 .Vt fd_set svc_fdset ;
1070 A global variable reflecting the
1073 read file descriptor bit mask; it is suitable as a template argument
1077 This is only of interest
1078 if a service implementor does not call
1080 but rather does his own asynchronous event processing.
1081 This variable is read\-only (do not pass its address to
1083 yet it may change after calls to
1085 or any creation routines.
1086 As well, note that if the process has descriptor limits
1087 which are extended beyond
1089 this variable will only be usable for the first
1099 but limited to 32 descriptors.
1101 interface is obsoleted by
1106 .Fn svc_freeargs "SVCXPRT *xprt" "xdrproc_t inproc" "char *in"
1109 A macro that frees any data allocated by the
1111 system when it decoded the arguments to a service procedure
1114 This routine returns 1 if the results were successfully
1120 .Fn svc_getargs "SVCXPRT *xprt" "xdrproc_t inproc" "char *in"
1123 A macro that decodes the arguments of an
1128 service transport handle,
1133 is the address where the arguments will be placed;
1137 routine used to decode the arguments.
1138 This routine returns one if decoding succeeds, and zero
1142 .Ft "struct sockaddr_in *"
1145 .Fn svc_getcaller "SVCXPRT *xprt"
1148 The approved way of getting the network address of the caller
1149 of a procedure associated with the
1151 service transport handle,
1156 .Fn svc_getreqset "fd_set *rdfds"
1159 This routine is only of interest if a service implementor
1162 but instead implements custom asynchronous event processing.
1163 It is called when the
1165 system call has determined that an
1167 request has arrived on some
1171 is the resultant read file descriptor bit mask.
1172 The routine returns when all sockets associated with the
1179 .Fn svc_getreq "int rdfds"
1184 but limited to 32 descriptors.
1185 This interface is obsoleted by
1192 .Fa "u_long prognum"
1193 .Fa "u_long versnum"
1194 .Fa "void (*dispatch)(struct svc_req *, SVCXPRT *)"
1203 with the service dispatch procedure,
1207 is zero, the service is not registered with the
1212 is non-zero, then a mapping of the triple
1213 .Pq Fa prognum , versnum , protocol
1216 is established with the local
1226 has the following form:
1227 .Bd -ragged -offset indent
1229 .Fn dispatch "struct svc_req *request" "SVCXPRT *xprt"
1234 routine returns one if it succeeds, and zero otherwise.
1240 This routine never returns.
1243 requests to arrive, and calls the appropriate service
1247 This procedure is usually waiting for a
1249 system call to return.
1253 .Fn svc_sendreply "SVCXPRT *xprt" "xdrproc_t outproc" "char *out"
1258 service's dispatch routine to send the results of a
1259 remote procedure call.
1263 is the request's associated transport handle;
1267 routine which is used to encode the results; and
1269 is the address of the results.
1270 This routine returns one if it succeeds, zero otherwise.
1276 .Fn svc_unregister "u_long prognum" "u_long versnum"
1279 Remove all mapping of the double
1280 .Pq Fa prognum , versnum
1281 to dispatch routines, and of the triple
1282 .Pq Fa prognum , versnum , *
1289 .Fn svcerr_auth "SVCXPRT *xprt" "enum auth_stat why"
1292 Called by a service dispatch routine that refuses to perform
1293 a remote procedure call due to an authentication error.
1299 .Fn svcerr_decode "SVCXPRT *xprt"
1302 Called by a service dispatch routine that cannot successfully
1303 decode its arguments.
1311 .Fn svcerr_noproc "SVCXPRT *xprt"
1314 Called by a service dispatch routine that does not implement
1315 the procedure number that the caller requests.
1321 .Fn svcerr_noprog "SVCXPRT *xprt"
1324 Called when the desired program is not registered with the
1327 Service implementors usually do not need this routine.
1333 .Fn svcerr_progvers "SVCXPRT *xprt" "u_long low_vers" "u_long high_vers"
1336 Called when the desired version of a program is not registered
1340 Service implementors usually do not need this routine.
1346 .Fn svcerr_systemerr "SVCXPRT *xprt"
1349 Called by a service dispatch routine when it detects a system
1351 not covered by any particular protocol.
1352 For example, if a service can no longer allocate storage,
1353 it may call this routine.
1359 .Fn svcerr_weakauth "SVCXPRT *xprt"
1362 Called by a service dispatch routine that refuses to perform
1363 a remote procedure call due to insufficient
1364 authentication arguments.
1366 .Fn svcerr_auth xprt AUTH_TOOWEAK .
1372 .Fn svcraw_create void
1375 This routine creates a toy
1377 service transport, to which it returns a pointer.
1379 is really a buffer within the process's address space,
1380 so the corresponding
1382 client should live in the same
1385 .Fn clntraw_create .
1386 This routine allows simulation of
1390 overheads (such as round trip times), without any kernel
1392 This routine returns
1400 .Fn svctcp_create "int sock" "u_int send_buf_size" "u_int recv_buf_size"
1403 This routine creates a
1404 .Tn TCP/IP Ns \-based
1406 service transport, to which it returns a pointer.
1407 The transport is associated with the socket
1411 in which case a new socket is created.
1412 If the socket is not bound to a local
1414 port, then this routine binds it to an arbitrary port.
1417 is the transport's socket descriptor, and
1419 is the transport's port number.
1420 This routine returns
1428 users may specify the size of buffers; values of zero
1429 choose suitable defaults.
1435 .Fn svcunix_create "int sock" "u_int send_buf_size" "u_int recv_buf_size" "char *path"
1438 This routine creates a
1441 service transport, to which it returns a pointer.
1442 The transport is associated with the socket
1446 in which case a new socket is created.
1450 is a variable-length file system pathname of
1451 at most 104 characters.
1454 removed when the socket is closed.
1457 system call must be used to remove the file.
1460 is the transport's socket descriptor.
1461 This routine returns
1469 users may specify the size of buffers; values of zero
1470 choose suitable defaults.
1476 .Fn svcunixfd_create "int fd" "u_int sendsize" "u_int recvsize"
1479 Create a service on top of any open descriptor.
1485 indicate sizes for the send and receive buffers.
1487 zero, a reasonable default is chosen.
1493 .Fn svcfd_create "int fd" "u_int sendsize" "u_int recvsize"
1496 Create a service on top of any open descriptor.
1499 descriptor is a connected socket for a stream protocol such
1507 indicate sizes for the send and receive buffers.
1509 zero, a reasonable default is chosen.
1515 .Fn svcudp_bufcreate "int sock" "u_int sendsize" "u_int recvsize"
1518 This routine creates a
1519 .Tn UDP/IP Ns \-based
1521 service transport, to which it returns a pointer.
1522 The transport is associated with the socket
1526 in which case a new socket is created.
1527 If the socket is not bound to a local
1529 port, then this routine binds it to an arbitrary port.
1533 is the transport's socket descriptor, and
1535 is the transport's port number.
1536 This routine returns
1540 This allows the user to specify the maximum packet size for sending and
1548 .Fn xdr_accepted_reply "XDR *xdrs" "struct accepted_reply *ar"
1554 This routine is useful for users who
1557 messages without using the
1563 .Fn xdr_authunix_parms "XDR *xdrs" "struct authunix_parms *aupp"
1569 This routine is useful for users
1570 who wish to generate these credentials without using the
1572 authentication package.
1579 .Fn xdr_callhdr "XDR *xdrs" "struct rpc_msg *chdr"
1584 call header messages.
1585 This routine is useful for users who wish to generate
1587 messages without using the
1593 .Fn xdr_callmsg "XDR *xdrs" "struct rpc_msg *cmsg"
1599 This routine is useful for users who wish to generate
1601 messages without using the
1607 .Fn xdr_opaque_auth "XDR *xdrs" "struct opaque_auth *ap"
1612 authentication information messages.
1613 This routine is useful for users who wish to generate
1615 messages without using the
1624 .Fn xdr_pmap "XDR *xdrs" "struct pmap *regs"
1627 Used for describing arguments to various
1629 procedures, externally.
1630 This routine is useful for users who wish to generate
1631 these arguments without using the
1637 .Fn xdr_pmaplist "XDR *xdrs" "struct pmaplist **rp"
1640 Used for describing a list of port mappings, externally.
1641 This routine is useful for users who wish to generate
1642 these arguments without using the
1648 .Fn xdr_rejected_reply "XDR *xdrs" "struct rejected_reply *rr"
1654 This routine is useful for users who wish to generate
1656 messages without using the
1662 .Fn xdr_replymsg "XDR *xdrs" "struct rpc_msg *rmsg"
1668 This routine is useful for users who wish to generate
1670 style messages without using the
1678 .Fn xprt_register "SVCXPRT *xprt"
1683 service transport handles are created,
1684 they should register themselves with the
1687 This routine modifies the global variable
1689 Service implementors usually do not need this routine.
1695 .Fn xprt_unregister "SVCXPRT *xprt"
1700 service transport handle is destroyed,
1701 it should unregister itself with the
1704 This routine modifies the global variable
1706 Service implementors usually do not need this routine.
1709 These functions are part of libtirpc.
1714 .%T "Remote Procedure Calls: Protocol Specification"
1717 .%T "Remote Procedure Call Programming Guide"
1720 .%T "rpcgen Programming Guide"
1723 .%T "RPC: Remote Procedure Call Protocol Specification"
1725 .%Q "Sun Microsystems, Inc., USC-ISI"