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 $
14 .Nm authunix_create_default ,
23 .Nm clnt_pcreateerror ,
26 .Nm clnt_spcreateerror ,
31 .Nm clntudp_bufcreate ,
58 .Nm svcerr_systemerr ,
61 .Nm svcunixfd_create ,
64 .Nm xdr_accepted_reply ,
65 .Nm xdr_authunix_parms ,
71 .Nm xdr_rejected_reply ,
75 .Nd "library routines for remote procedure calls"
83 for function declarations.
90 functions described in this page are the old, TS-RPC
91 interface to the XDR and RPC library, and exist for backward compatibility.
92 The new interface is described in the pages
97 These routines allow C programs to make procedure
98 calls on other machines across the network.
99 First, the client calls a procedure to send a
100 data packet to the server.
101 Upon receipt of the packet, the server calls a dispatch routine
102 to perform the requested service, and then sends back a
104 Finally, the procedure call returns to the client.
106 Routines that are used for Secure
108 authentication) are described in
114 encryption is available.
116 .Bl -tag -width indent -compact
121 .Fn auth_destroy "AUTH *auth"
124 A macro that destroys the authentication information associated with
126 Destruction usually involves deallocation of private data
130 is undefined after calling
142 authentication handle that passes nonusable authentication
143 information with each remote procedure call.
145 default authentication used by
152 .Fn authunix_create "char *host" "int uid" "int gid" "int len" "int *aup_gids"
157 authentication handle that contains
159 authentication information.
163 is the name of the machine on which the information was
166 is the user's user ID;
168 is the user's current group ID;
172 refer to a counted array of groups to which the user belongs.
173 It is easy to impersonate a user.
179 .Fn authunix_create_default
184 with the appropriate arguments.
193 .Fa "xdrproc_t inproc"
195 .Fa "xdrproc_t outproc"
200 Call the remote procedure associated with
210 is the address of the procedure's argument(s), and
212 is the address of where to place the result(s);
214 is used to encode the procedure's arguments, and
216 is used to decode the procedure's results.
217 This routine returns zero if it succeeds, or the value of
219 cast to an integer if it fails.
222 is handy for translating failure statuses into messages.
224 Warning: calling remote procedures with this routine
230 You do not have control of timeouts or authentication using
241 .Fa "xdrproc_t inproc"
243 .Fa "xdrproc_t outproc"
245 .Fa "bool_t (*eachresult)(caddr_t, struct sockaddr_in *)"
251 except the call message is broadcast to all locally
252 connected broadcast nets.
253 Each time it receives a
254 response, this routine calls
257 .Bd -ragged -offset indent
259 .Fn eachresult "caddr_t out" "struct sockaddr_in *addr"
268 except that the remote procedure's output is decoded there;
270 points to the address of the machine that sent the results.
275 waits for more replies; otherwise it returns with appropriate
278 Warning: broadcast sockets are limited in size to the
279 maximum transfer unit of the data link.
281 this value is 1500 bytes.
290 .Fa "xdrproc_t inproc"
292 .Fa "xdrproc_t outproc"
294 .Fa "struct timeval tout"
298 A macro that calls the remote procedure
300 associated with the client handle,
302 which is obtained with an
304 client creation routine such as
309 is the address of the procedure's argument(s), and
311 is the address of where to place the result(s);
313 is used to encode the procedure's arguments, and
315 is used to decode the procedure's results;
317 is the time allowed for results to come back.
321 .Fn clnt_destroy "CLIENT *clnt"
324 A macro that destroys the client's
327 Destruction usually involves deallocation
328 of private data structures, including
333 is undefined after calling
337 library opened the associated socket, it will close it also.
338 Otherwise, the socket remains open.
344 .Fn clnt_create "const char *host" "u_long prog" "u_long vers" "const char *proto"
347 Generic client creation routine.
351 identifies the name of the remote host where the server
356 indicates which kind of transport protocol to use.
358 currently supported values for this field are
362 Default timeouts are set, but can be modified using
367 has its shortcomings.
371 messages can only hold up to 8 Kbytes of encoded data,
372 this transport cannot be used for procedures that take
373 large arguments or return huge results.
379 .Fn clnt_control "CLIENT *cl" "u_int req" "char *info"
382 A macro used to change or retrieve various information
383 about a client object.
387 indicates the type of operation, and
389 is a pointer to the information.
394 the supported values of
396 and their argument types and what they do are:
397 .Bl -column "CLSET_RETRY_TIMEOUT" "struct sockaddr_in"
398 .It Dv CLSET_TIMEOUT Ta Xo
399 .Vt "struct timeval" Ta "set total timeout"
401 .It Dv CLGET_TIMEOUT Ta Xo
402 .Vt "struct timeval" Ta "get total timeout"
406 Note: if you set the timeout using
408 the timeout argument passed to
410 will be ignored in all future calls.
411 .Bl -column "CLSET_RETRY_TIMEOUT" "struct sockaddr_in"
412 .It Dv CLGET_SERVER_ADDR Ta Xo
413 .Vt "struct sockaddr_in" Ta "get server's address"
417 The following operations are valid for
420 .Bl -column "CLSET_RETRY_TIMEOUT" "struct sockaddr_in"
421 .It Dv CLSET_RETRY_TIMEOUT Ta Xo
422 .Vt "struct timeval" Ta "set the retry timeout"
424 .It Dv CLGET_RETRY_TIMEOUT Ta Xo
425 .Vt "struct timeval" Ta "get the retry timeout"
429 The retry timeout is the time that
431 waits for the server to reply before
432 retransmitting the request.
436 .Fn clnt_freeres "CLIENT *clnt" "xdrproc_t outproc" "char *out"
439 A macro that frees any data allocated by the
441 system when it decoded the results of an
447 is the address of the results, and
451 routine describing the results.
452 This routine returns one if the results were successfully
460 .Fn clnt_geterr "CLIENT *clnt" "struct rpc_err *errp"
463 A macro that copies the error structure out of the client
465 to the structure at address
472 .Fn clnt_pcreateerror "const char *s"
475 prints a message to standard error indicating
478 handle could not be created.
479 The message is prepended with string
482 A newline is appended at the end of the message.
495 .Fn clnt_perrno "enum clnt_stat stat"
498 Print a message to standard error corresponding
499 to the condition indicated by
501 A newline is appended at the end of the message.
507 .Fn clnt_perror "CLIENT *clnt" "const char *s"
510 Print a message to standard error indicating why an
514 is the handle used to do the call.
515 The message is prepended with string
518 A newline is appended at the end of the message.
526 .Fn clnt_spcreateerror "const char *s"
530 .Fn clnt_pcreateerror ,
531 except that it returns a string
532 instead of printing to the standard error.
534 Bugs: returns pointer to static data that is overwritten
541 .Fn clnt_sperrno "enum clnt_stat stat"
544 Take the same arguments as
546 but instead of sending a message to the standard error
549 call failed, return a pointer to a string which contains
557 if the program does not have a standard error (as a program
558 running as a server quite likely does not), or if the
560 does not want the message to be output with
562 or if a message format different from that supported by
569 .Fn clnt_spcreateerror ,
571 returns pointer to static data, but the
572 result will not get overwritten on each call.
578 .Fn clnt_sperror "CLIENT *rpch" "const char *s"
585 it returns a string instead of printing to standard error.
587 Bugs: returns pointer to static data that is overwritten
594 .Fn clntraw_create "u_long prognum" "u_long versnum"
597 This routine creates a toy
599 client for the remote program
603 The transport used to pass messages to the service is
604 actually a buffer within the process's address space, so the
607 server should live in the same address space; see
609 This allows simulation of
613 overheads, such as round trip times, without any
624 .Fa "struct sockaddr_in *addr"
633 This routine creates an
635 client for the remote program
642 The remote program is located at Internet
647 is zero, then it is set to the actual port that the remote
648 program is listening on (the remote
650 service is consulted for this information).
654 is a socket; if it is
656 then this routine opens a new one and sets
663 the user may specify the size of the send and receive buffers
669 values of zero choose suitable defaults.
679 .Fa "struct sockaddr_in *addr"
682 .Fa "struct timeval wait"
687 This routine creates an
689 client for the remote program
696 The remote program is located at Internet
701 is zero, then it is set to actual port that the remote
702 program is listening on (the remote
704 service is consulted for this information).
708 is a socket; if it is
710 then this routine opens a new one and sets
714 transport resends the call message in intervals of
716 time until a response is received or until the call times
718 The total time for the call to time out is specified by
724 messages can only hold up to 8 Kbytes
725 of encoded data, this transport cannot be used for procedures
726 that take large arguments or return huge results.
732 .Fo clntudp_bufcreate
733 .Fa "struct sockaddr_in *addr"
736 .Fa "struct timeval wait"
738 .Fa "unsigned int sendsize"
739 .Fa "unsigned int recosize"
743 This routine creates an
745 client for the remote program
752 The remote program is located at Internet
757 is zero, then it is set to actual port that the remote
758 program is listening on (the remote
760 service is consulted for this information).
764 is a socket; if it is
766 then this routine opens a new one and sets
770 transport resends the call message in intervals of
772 time until a response is received or until the call times
774 The total time for the call to time out is specified by
777 This allows the user to specify the maximum packet size
778 for sending and receiving
788 .Fa "struct sockaddr_un *raddr"
797 This routine creates an
806 sockets as a transport.
807 The local program is located at the
812 is a socket; if it is
814 then this routine opens a new one and sets
821 the user may specify the size of the send and receive buffers
827 values of zero choose suitable defaults.
836 .Fn get_myaddress "struct sockaddr_in *addr"
843 without consulting the library routines that deal with
845 The port number is always set to
847 Returns zero on success, non-zero on failure.
850 .Ft "struct pmaplist *"
853 .Fn pmap_getmaps "struct sockaddr_in *addr"
856 A user interface to the
858 service, which returns a list of the current
860 program\-to\-port mappings
861 on the host located at
865 This routine can return
876 .Fa "struct sockaddr_in *addr"
879 .Fa "u_long protocol"
883 A user interface to the
885 service, which returns the port number
886 on which waits a service that supports program number
890 and speaks the transport protocol associated with
898 A return value of zero means that the mapping does not exist
902 system failed to contact the remote
905 In the latter case, the global variable
916 .Fa "struct sockaddr_in *addr"
920 .Fa "xdrproc_t inproc"
922 .Fa "xdrproc_t outproc"
924 .Fa "struct timeval tout"
929 A user interface to the
931 service, which instructs
939 call on your behalf to a procedure on that host.
943 will be modified to the program's port number if the
946 The definitions of other arguments are discussed
951 This procedure should be used for a
960 .Fn pmap_set "u_long prognum" "u_long versnum" "u_long protocol" "u_short port"
963 A user interface to the
965 service, which establishes a mapping between the triple
966 .Pq Fa prognum , versnum , protocol
978 This routine returns one if it succeeds, zero otherwise.
979 Automatically done by
984 .Fn pmap_unset "u_long prognum" "u_long versnum"
987 A user interface to the
989 service, which destroys all mapping between the triple
990 .Pq Fa prognum , versnum , *
996 This routine returns one if it succeeds, zero
1002 .Fa "u_long prognum"
1003 .Fa "u_long versnum"
1004 .Fa "u_long procnum"
1005 .Fa "char *(*procname)(void)"
1006 .Fa "xdrproc_t inproc"
1007 .Fa "xdrproc_t outproc"
1016 If a request arrives for program
1023 is called with a pointer to its argument(s);
1025 should return a pointer to its static result(s);
1027 is used to decode the arguments while
1029 is used to encode the results.
1030 This routine returns zero if the registration succeeded, \-1
1033 Warning: remote procedures registered in this form
1034 are accessed using the
1041 .Vt "struct rpc_createerr" rpc_createerr ;
1044 A global variable whose value is set by any
1046 client creation routine
1047 that does not succeed.
1049 .Fn clnt_pcreateerror
1050 to print the reason why.
1054 .Fn svc_destroy "SVCXPRT * xprt"
1057 A macro that destroys the
1059 service transport handle,
1061 Destruction usually involves deallocation
1062 of private data structures, including
1067 is undefined after calling this routine.
1070 .Vt fd_set svc_fdset ;
1073 A global variable reflecting the
1076 read file descriptor bit mask; it is suitable as a template argument
1080 This is only of interest
1081 if a service implementor does not call
1083 but rather does his own asynchronous event processing.
1084 This variable is read\-only (do not pass its address to
1086 yet it may change after calls to
1088 or any creation routines.
1089 As well, note that if the process has descriptor limits
1090 which are extended beyond
1092 this variable will only be usable for the first
1102 but limited to 32 descriptors.
1104 interface is obsoleted by
1109 .Fn svc_freeargs "SVCXPRT *xprt" "xdrproc_t inproc" "char *in"
1112 A macro that frees any data allocated by the
1114 system when it decoded the arguments to a service procedure
1117 This routine returns 1 if the results were successfully
1123 .Fn svc_getargs "SVCXPRT *xprt" "xdrproc_t inproc" "char *in"
1126 A macro that decodes the arguments of an
1131 service transport handle,
1136 is the address where the arguments will be placed;
1140 routine used to decode the arguments.
1141 This routine returns one if decoding succeeds, and zero
1145 .Ft "struct sockaddr_in *"
1148 .Fn svc_getcaller "SVCXPRT *xprt"
1151 The approved way of getting the network address of the caller
1152 of a procedure associated with the
1154 service transport handle,
1159 .Fn svc_getreqset "fd_set *rdfds"
1162 This routine is only of interest if a service implementor
1165 but instead implements custom asynchronous event processing.
1166 It is called when the
1168 system call has determined that an
1170 request has arrived on some
1174 is the resultant read file descriptor bit mask.
1175 The routine returns when all sockets associated with the
1182 .Fn svc_getreq "int rdfds"
1187 but limited to 32 descriptors.
1188 This interface is obsoleted by
1195 .Fa "u_long prognum"
1196 .Fa "u_long versnum"
1197 .Fa "void (*dispatch)(struct svc_req *, SVCXPRT *)"
1206 with the service dispatch procedure,
1210 is zero, the service is not registered with the
1215 is non-zero, then a mapping of the triple
1216 .Pq Fa prognum , versnum , protocol
1219 is established with the local
1229 has the following form:
1230 .Bd -ragged -offset indent
1232 .Fn dispatch "struct svc_req *request" "SVCXPRT *xprt"
1237 routine returns one if it succeeds, and zero otherwise.
1243 This routine never returns.
1246 requests to arrive, and calls the appropriate service
1250 This procedure is usually waiting for a
1252 system call to return.
1256 .Fn svc_sendreply "SVCXPRT *xprt" "xdrproc_t outproc" "char *out"
1261 service's dispatch routine to send the results of a
1262 remote procedure call.
1266 is the request's associated transport handle;
1270 routine which is used to encode the results; and
1272 is the address of the results.
1273 This routine returns one if it succeeds, zero otherwise.
1279 .Fn svc_unregister "u_long prognum" "u_long versnum"
1282 Remove all mapping of the double
1283 .Pq Fa prognum , versnum
1284 to dispatch routines, and of the triple
1285 .Pq Fa prognum , versnum , *
1292 .Fn svcerr_auth "SVCXPRT *xprt" "enum auth_stat why"
1295 Called by a service dispatch routine that refuses to perform
1296 a remote procedure call due to an authentication error.
1302 .Fn svcerr_decode "SVCXPRT *xprt"
1305 Called by a service dispatch routine that cannot successfully
1306 decode its arguments.
1314 .Fn svcerr_noproc "SVCXPRT *xprt"
1317 Called by a service dispatch routine that does not implement
1318 the procedure number that the caller requests.
1324 .Fn svcerr_noprog "SVCXPRT *xprt"
1327 Called when the desired program is not registered with the
1330 Service implementors usually do not need this routine.
1336 .Fn svcerr_progvers "SVCXPRT *xprt" "u_long low_vers" "u_long high_vers"
1339 Called when the desired version of a program is not registered
1343 Service implementors usually do not need this routine.
1349 .Fn svcerr_systemerr "SVCXPRT *xprt"
1352 Called by a service dispatch routine when it detects a system
1354 not covered by any particular protocol.
1355 For example, if a service can no longer allocate storage,
1356 it may call this routine.
1362 .Fn svcerr_weakauth "SVCXPRT *xprt"
1365 Called by a service dispatch routine that refuses to perform
1366 a remote procedure call due to insufficient
1367 authentication arguments.
1369 .Fn svcerr_auth xprt AUTH_TOOWEAK .
1375 .Fn svcraw_create void
1378 This routine creates a toy
1380 service transport, to which it returns a pointer.
1382 is really a buffer within the process's address space,
1383 so the corresponding
1385 client should live in the same
1388 .Fn clntraw_create .
1389 This routine allows simulation of
1393 overheads (such as round trip times), without any kernel
1395 This routine returns
1403 .Fn svctcp_create "int sock" "u_int send_buf_size" "u_int recv_buf_size"
1406 This routine creates a
1407 .Tn TCP/IP Ns \-based
1409 service transport, to which it returns a pointer.
1410 The transport is associated with the socket
1414 in which case a new socket is created.
1415 If the socket is not bound to a local
1417 port, then this routine binds it to an arbitrary port.
1420 is the transport's socket descriptor, and
1422 is the transport's port number.
1423 This routine returns
1431 users may specify the size of buffers; values of zero
1432 choose suitable defaults.
1438 .Fn svcunix_create "int sock" "u_int send_buf_size" "u_int recv_buf_size" "char *path"
1441 This routine creates a
1444 service transport, to which it returns a pointer.
1445 The transport is associated with the socket
1449 in which case a new socket is created.
1453 is a variable-length file system pathname of
1454 at most 104 characters.
1457 removed when the socket is closed.
1460 system call must be used to remove the file.
1463 is the transport's socket descriptor.
1464 This routine returns
1472 users may specify the size of buffers; values of zero
1473 choose suitable defaults.
1479 .Fn svcunixfd_create "int fd" "u_int sendsize" "u_int recvsize"
1482 Create a service on top of any open descriptor.
1488 indicate sizes for the send and receive buffers.
1490 zero, a reasonable default is chosen.
1496 .Fn svcfd_create "int fd" "u_int sendsize" "u_int recvsize"
1499 Create a service on top of any open descriptor.
1502 descriptor is a connected socket for a stream protocol such
1510 indicate sizes for the send and receive buffers.
1512 zero, a reasonable default is chosen.
1518 .Fn svcudp_bufcreate "int sock" "u_int sendsize" "u_int recvsize"
1521 This routine creates a
1522 .Tn UDP/IP Ns \-based
1524 service transport, to which it returns a pointer.
1525 The transport is associated with the socket
1529 in which case a new socket is created.
1530 If the socket is not bound to a local
1532 port, then this routine binds it to an arbitrary port.
1536 is the transport's socket descriptor, and
1538 is the transport's port number.
1539 This routine returns
1543 This allows the user to specify the maximum packet size for sending and
1551 .Fn xdr_accepted_reply "XDR *xdrs" "struct accepted_reply *ar"
1557 This routine is useful for users who
1560 messages without using the
1566 .Fn xdr_authunix_parms "XDR *xdrs" "struct authunix_parms *aupp"
1572 This routine is useful for users
1573 who wish to generate these credentials without using the
1575 authentication package.
1582 .Fn xdr_callhdr "XDR *xdrs" "struct rpc_msg *chdr"
1587 call header messages.
1588 This routine is useful for users who wish to generate
1590 messages without using the
1596 .Fn xdr_callmsg "XDR *xdrs" "struct rpc_msg *cmsg"
1602 This routine is useful for users who wish to generate
1604 messages without using the
1610 .Fn xdr_opaque_auth "XDR *xdrs" "struct opaque_auth *ap"
1615 authentication information messages.
1616 This routine is useful for users who wish to generate
1618 messages without using the
1627 .Fn xdr_pmap "XDR *xdrs" "struct pmap *regs"
1630 Used for describing arguments to various
1632 procedures, externally.
1633 This routine is useful for users who wish to generate
1634 these arguments without using the
1640 .Fn xdr_pmaplist "XDR *xdrs" "struct pmaplist **rp"
1643 Used for describing a list of port mappings, externally.
1644 This routine is useful for users who wish to generate
1645 these arguments without using the
1651 .Fn xdr_rejected_reply "XDR *xdrs" "struct rejected_reply *rr"
1657 This routine is useful for users who wish to generate
1659 messages without using the
1665 .Fn xdr_replymsg "XDR *xdrs" "struct rpc_msg *rmsg"
1671 This routine is useful for users who wish to generate
1673 style messages without using the
1681 .Fn xprt_register "SVCXPRT *xprt"
1686 service transport handles are created,
1687 they should register themselves with the
1690 This routine modifies the global variable
1692 Service implementors usually do not need this routine.
1698 .Fn xprt_unregister "SVCXPRT *xprt"
1703 service transport handle is destroyed,
1704 it should unregister itself with the
1707 This routine modifies the global variable
1709 Service implementors usually do not need this routine.
1715 .%T "Remote Procedure Calls: Protocol Specification"
1718 .%T "Remote Procedure Call Programming Guide"
1721 .%T "rpcgen Programming Guide"
1724 .%T "RPC: Remote Procedure Call Protocol Specification"
1726 .%Q "Sun Microsystems, Inc., USC-ISI"