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.13 2009/01/11 02:46:29 christos Exp $
3 .\" Converted to mdoc by Thomas Klausner <wiz@NetBSD.org>
13 .Nm authunix_create_default ,
22 .Nm clnt_pcreateerror ,
25 .Nm clnt_spcreateerror ,
30 .Nm clntudp_bufcreate ,
47 .Nm svc_getrpccaller ,
57 .Nm svcerr_systemerr ,
61 .Nm xdr_accepted_reply ,
62 .Nm xdr_authunix_parms ,
68 .Nm xdr_rejected_reply ,
72 .Nd library routines for remote procedure calls
76 .Fn auth_destroy "AUTH *auth"
78 .Fn authnone_create "void"
80 .Fn authunix_create "char *host" "int uid" "int gid" "int len" "int *aup_gids"
82 .Fn authunix_create_default "void"
84 .Fn callrpc "char *host" "u_long prognum" "u_long versnum" \
85 "u_long procnum" "xdrproc_t inproc" "char *in" "xdrproc_t outproc" "char *out"
87 .Fn clnt_broadcast "u_long prognum" "u_long versnum" "u_long procnum" \
88 "xdrproc_t inproc" "char *in" "xdrproc_t outproc" "char *out" \
89 "resultproc_t eachresult"
91 .Fn clnt_call "CLIENT *clnt" "u_long procnum" "xdrproc_t inproc" \
92 "char *in" "xdrproc_t outproc" "char *out" "struct timeval tout"
94 .Fn clnt_destroy "CLIENT *clnt"
96 .Fn clnt_create "char *host" "u_long prog" "u_long vers" "char *proto"
98 .Fn clnt_control "CLIENT *cl" "u_int req" "char *info"
100 .Fn clnt_freeres "CLIENT *clnt" "xdrproc_t outproc" "char *out"
102 .Fn clnt_geterr "CLIENT *clnt" "struct rpc_err errp"
104 .Fn clnt_pcreateerror "char *s"
106 .Fn clnt_perrno "enum clnt_stat stat"
108 .Fn clnt_perror "CLIENT *clnt" "char *s"
110 .Fn clnt_spcreateerror "const char *s"
112 .Fn clnt_sperrno "enum clnt_stat stat"
114 .Fn clnt_sperror "CLIENT *rpch" "char *s"
116 .Fn clntraw_create "u_long prognum" "u_long versnum"
118 .Fn clnttcp_create "struct sockaddr_in *addr" "u_long prognum" \
119 "u_long versnum" "int *sockp" "u_int sendsz" "u_int recvsz"
121 .Fn clntudp_create "struct sockaddr_in *addr" "u_long prognum" \
122 "u_long versnum" "struct timeval wait" "int *sockp"
124 .Fn clntudp_bufcreate "struct sockaddr_in *addr" "u_long prognum" \
125 "u_long versnum" "struct timeval wait" "int *sockp" \
126 "unsigned int sendsize" "unsigned int recosize"
128 .Fn get_myaddress "struct sockaddr_in *addr"
129 .Ft struct pmaplist *
130 .Fn pmap_getmaps "struct sockaddr_in *addr"
132 .Fn pmap_getport "struct sockaddr_in *addr" "u_long prognum" \
133 "u_long versnum" "u_long protocol"
136 .Fa "struct sockaddr_in *addr"
140 .Fa "xdrproc_t inproc"
142 .Fa "xdrpoc_t outproc"
144 .Fa "struct timeval tout"
148 .Fn pmap_set "u_long prognum" "u_long versnum" "int protocol" \
151 .Fn pmap_unset "u_long prognum" "u_long versnum"
153 .Fn registerrpc "u_long prognum" "u_long versnum" "u_long procnum" \
154 "char *(*procname)()" "xdrproc_t inproc" "xdrproc_t outproc"
155 .Fd struct rpc_createerr rpc_createerr;
157 .Fn svc_destroy "SVCXPRT *xprt"
158 .Fd fd_set svc_fdset;
161 .Fn svc_freeargs "SVCXPRT *xprt" "xdrproc_t inproc" "char *in"
163 .Fn svc_getargs "SVCXPRT *xprt" "xdrproc_t inproc" "char *in"
164 .Ft struct sockaddr_in *
165 .Fn svc_getcaller "SVCXPRT *xprt"
167 .Fn svc_getreqset "fd_set *rdfds"
169 .Fn svc_getreq "int rdfds"
171 .Fn svc_getrpccaller "SVCXPRT *xprt"
173 .Fn svc_register "SVCXPRT *xprt" "u_long prognum" "u_long versnum" \
174 "void (*dispatch)()" "u_long protocol"
178 .Fn svc_sendreply "SVCXPRT *xprt" "xdrproc_t outproc" "char *out"
180 .Fn svc_unregister "u_long prognum" "u_long versnum"
182 .Fn svcerr_auth "SVCXPRT *xprt" "enum auth_stat why"
184 .Fn svcerr_decode "SVCXPRT *xprt"
186 .Fn svcerr_noproc "SVCXPRT *xprt"
188 .Fn svcerr_noprog "SVCXPRT *xprt"
190 .Fn svcerr_progvers "SVCXPRT *xprt"
192 .Fn svcerr_systemerr "SVCXPRT *xprt"
194 .Fn svcerr_weakauth "SVCXPRT *xprt"
196 .Fn svcraw_create "void"
198 .Fn svctcp_create "int sock" "u_int send_buf_size" \
199 "u_int recv_buf_size"
201 .Fn svcfd_create "int fd" "u_int sendsize" "u_int recvsize"
203 .Fn svcudp_bufcreate "int sock" "u_int sendsize" "u_int recosize"
205 .Fn svcudp_create "int sock"
207 .Fn xdr_accepted_reply "XDR *xdrs" "struct accepted_reply *ar"
209 .Fn xdr_authunix_parms "XDR *xdrs" "struct authunix_parms *aupp"
211 .Fn xdr_callhdr "XDR *xdrs" "struct rpc_msg *chdr"
213 .Fn xdr_callmsg "XDR *xdrs" "struct rpc_msg *cmsg"
215 .Fn xdr_opaque_auth "XDR *xdrs" "struct opaque_auth *ap"
217 .Fn xdr_pmap "XDR *xdrs" "struct pmap *regs"
219 .Fn xdr_pmaplist "XDR *xdrs" "struct pmaplist **rp"
221 .Fn xdr_rejected_reply "XDR *xdrs" "struct rejected_reply *rr"
223 .Fn xdr_replymsg "XDR *xdrs" "struct rpc_msg *rmsg"
225 .Fn xprt_register "SVCXPRT *xprt"
227 .Fn xprt_unregister "SVCXPRT *xprt"
229 .Em "The svc and clnt functions described in this page are the old, TS-RPC"
230 .Em "interface to the XDR and RPC library, and exist for backward compatibility."
231 .Em "The new interface is described in the pages referenced from"
234 These routines allow C programs to make procedure
235 calls on other machines across the network.
236 First, the client calls a procedure to send a
237 data packet to the server.
238 Upon receipt of the packet, the server calls a dispatch routine
239 to perform the requested service, and then sends back a
241 Finally, the procedure call returns to the client.
244 .\"Routines that are used for Secure RPC (DES authentication) are described in
245 .\".Xr rpc_secure 3 .
246 .\"Secure RPC can be used only if DES encryption is available.
250 A macro that destroys the authentication information associated with
252 Destruction usually involves deallocation of private data structures.
255 is undefined after calling
257 .It Fn authnone_create
258 Create and returns an RPC authentication handle that passes nonusable
259 authentication information with each remote procedure call.
260 This is the default authentication used by RPC.
261 .It Fn authunix_create
262 Create and return an RPC authentication handle that contains
264 authentication information.
267 is the name of the machine on which the information was
270 is the user's user ID;
272 is the user's current group id;
276 refer to a counted array of groups to which the user belongs.
277 It is easy to impersonate a user.
278 .It Fn authunix_create_default
281 with the appropriate parameters.
283 Call the remote procedure associated with
292 is the address of the procedure's argument(s), and
294 is the address of where to place the result(s);
296 is used to encode the procedure's parameters, and
298 is used to decode the procedure's results.
299 This routine returns zero if it succeeds, or the value of
301 cast to an integer if it fails.
304 is handy for translating failure statuses into messages.
306 Warning: calling remote procedures with this routine
307 uses UDP/IP as a transport; see
310 You do not have control of timeouts or authentication using
312 .It Fn clnt_broadcast
315 except the call message is broadcast to all locally
316 connected broadcast nets.
317 Each time it receives a response, this routine calls
321 .Fn eachresult "char *out" "struct sockaddr_in *addr"
328 except that the remote procedure's output is decoded there;
330 points to the address of the machine that sent the results.
335 waits for more replies; otherwise it returns with appropriate
338 Warning: broadcast sockets are limited in size to the
339 maximum transfer unit of the data link.
340 For ethernet, this value is 1500 bytes.
342 A macro that calls the remote procedure
344 associated with the client handle,
346 which is obtained with an RPC client creation routine such as
350 is the address of the procedure's argument(s), and
352 is the address of where to place the result(s);
354 is used to encode the procedure's parameters, and
356 is used to decode the procedure's results;
358 is the time allowed for results to come back.
360 A macro that destroys the client's RPC handle.
361 Destruction usually involves deallocation
362 of private data structures, including
367 is undefined after calling
369 If the RPC library opened the associated socket, it will close it
371 Otherwise, the socket remains open.
373 Generic client creation routine.
375 identifies the name of the remote host where the server
378 indicates which kind of transport protocol to use.
379 The currently supported values for this field are
383 Default timeouts are set, but can be modified using
387 Using UDP has its shortcomings.
388 Since UDP-based RPC messages can only hold up to 8 Kbytes of encoded
389 data, this transport cannot be used for procedures that take
390 large arguments or return huge results.
392 A macro used to change or retrieve various information
393 about a client object.
395 indicates the type of operation, and
397 is a pointer to the information.
398 For both UDP and TCP the supported values of
400 and their argument types and what they do are:
401 .Bl -tag -width CLSET_RETRY_TIMEOUTX
409 Note: if you set the timeout using
411 the timeout parameter passed to
413 will be ignored in all future calls.
414 .It CLGET_SERVER_ADDR
415 .Vt struct sockaddr_in ;
416 get server's address.
419 The following operations are valid for UDP only:
420 .Bl -tag -width CLSET_RETRY_TIMEOUT
421 .It CLSET_RETRY_TIMEOUT
423 set the retry timeout.
424 .It CLGET_RETRY_TIMEOUT
426 get the retry timeout.
428 The retry timeout is the time that UDP RPC waits for the server to
429 reply before retransmitting the request.
432 A macro that frees any data allocated by the RPC/XDR system when it
433 decoded the results of an RPC call.
436 is the address of the results, and
438 is the XDR routine describing the results.
439 This routine returns one if the results were successfully freed,
442 A macro that copies the error structure out of the client
443 handle to the structure at address
445 .It Fn clnt_pcreateerror
446 Print a message to standard error indicating why a client RPC handle
447 could not be created.
448 The message is prepended with string
451 A newline character is appended at the end of the message.
460 Print a message to standard error corresponding
461 to the condition indicated by
463 A newline character is appended at the end of the message.
467 Print a message to standard error indicating why an RPC call failed;
469 is the handle used to do the call.
470 The message is prepended with string
473 A newline character is appended at the end of the message.
476 .It Fn clnt_spcreateerror
478 .Fn 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
485 Take the same arguments as
487 but instead of sending a message to the standard error
488 indicating why an RPC call failed, return a pointer to a string which
489 contains the message.
494 if the program does not have a standard error (as a program
495 running as a server quite likely does not), or if the
496 programmer does not want the message to be output with
498 or if a message format different than that supported by
504 .Fn clnt_spcreateerror ,
506 returns a pointer to static data, but the
507 result will not get overwritten on each call.
513 it returns a string instead of printing to standard error.
515 Bugs: returns pointer to static data that is overwritten
517 .It Fn clntraw_create
518 This routine creates a toy RPC client for the remote program
522 The transport used to pass messages to the service is
523 actually a buffer within the process's address space, so the
524 corresponding RPC server should live in the same address space; see
526 This allows simulation of RPC and acquisition of RPC overheads, such
527 as round trip times, without any kernel interference.
531 .It Fn clnttcp_create
532 This routine creates an RPC client for the remote program
536 the client uses TCP/IP as a transport.
537 The remote program is located at Internet address
540 .Fa addr-\*[Gt]sin_port
541 is zero, then it is set to the actual port that the remote
542 program is listening on (the remote
546 service is consulted for this information).
549 is a socket; if it is
551 then this routine opens a new one and sets
553 Since TCP-based RPC uses buffered I/O ,
554 the user may specify the size of the send and receive buffers
559 values of zero choose suitable defaults.
563 .It Fn clntudp_create
564 This routine creates an RPC client for the remote program
568 the client uses UDP/IP as a transport.
569 The remote program is located at Internet address
572 .Fa addr-\*[Gt]sin_port
573 is zero, then it is set to actual port that the remote
574 program is listening on (the remote
578 service is consulted for this information).
581 is a socket; if it is
583 then this routine opens a new one and sets
585 The UDP transport resends the call message in intervals of
587 time until a response is received or until the call times out.
588 The total time for the call to time out is specified by
591 Warning: since UDP-based RPC messages can only hold up to 8 Kbytes
592 of encoded data, this transport cannot be used for procedures
593 that take large arguments or return huge results.
594 .It Fn clntudp_bufcreate
595 This routine creates an RPC client for the remote program
599 the client uses UDP/IP as a transport.
600 The remote program is located at Internet address
603 .Fa addr-\*[Gt]sin_port
604 is zero, then it is set to actual port that the remote
605 program is listening on (the remote
609 service is consulted for this information).
612 is a socket; if it is
614 then this routine opens a new one and sets
616 The UDP transport resends the call message in intervals of
618 time until a response is received or until the call times out.
619 The total time for the call to time out is specified by
622 This allows the user to specify the maximum packet size for sending and
623 receiving UDP-based RPC messages.
625 Stuff the machine's IP address into
627 without consulting the library routines that deal with
629 The port number is always set to
630 .Fn htons "PMAPPORT" .
631 Returns zero on success, non-zero on failure.
633 A user interface to the
635 service, which returns a list of the current RPC program-to-port
636 mappings on the host located at IP address
638 This routine can return
644 A user interface to the
646 service, which returns the port number
647 on which waits a service that supports program number
651 and speaks the transport protocol associated with
659 A return value of zero means that the mapping does not exist
660 or that the RPC system failured to contact the remote
663 In the latter case, the global variable
665 contains the RPC status.
667 A user interface to the
669 service, which instructs
671 on the host at IP address
673 to make an RPC call on your behalf to a procedure on that host.
676 will be modified to the program's port number if the
678 The definitions of other parameters are discussed in
682 This procedure should be used for a
688 A user interface to the
690 service, which establishes a mapping between the triple
705 This routine returns one if it succeeds, zero otherwise.
706 Automatically done by
709 A user interface to the
711 service, which destroys all mapping between the triple
720 This routine returns one if it succeeds, zero otherwise.
724 with the RPC service package.
725 If a request arrives for program
732 is called with a pointer to its parameter(s);
734 should return a pointer to its static result(s);
736 is used to decode the parameters while
738 is used to encode the results.
739 This routine returns zero if the registration succeeded, \-1
742 Warning: remote procedures registered in this form
743 are accessed using the UDP/IP transport; see
746 .It struct rpc_createerr rpc_createerr ;
747 A global variable whose value is set by any RPC
748 client creation routine that does not succeed.
750 .Fn clnt_pcreateerror
751 to print the reason why.
753 A macro that destroys the RPC service transport handle,
755 Destruction usually involves deallocation
756 of private data structures, including
761 is undefined after calling this routine.
762 .It fd_set svc_fdset ;
763 A global variable reflecting the RPC service side's read file
764 descriptor bit mask; it is suitable as a parameter to the
767 This is only of interest if a service implementor does not call
769 but rather does his own asynchronous event processing.
770 This variable is read-only (do not pass its address to
772 yet it may change after calls to
774 or any creation routines.
778 but limited to 32 descriptors.
779 This interface is obsoleted by
782 A macro that frees any data allocated by the RPC/XDR
783 system when it decoded the arguments to a service procedure using
785 This routine returns 1 if the results were successfully freed,
788 A macro that decodes the arguments of an RPC request associated with
789 the RPC service transport handle,
793 is the address where the arguments will be placed;
795 is the XDR routine used to decode the arguments.
796 This routine returns one if decoding succeeds, and zero otherwise.
798 The obsolete way of getting the network address of the caller
799 of a procedure associated with the RPC service transport handle,
802 .Fn svc_getrpccaller .
804 This routine is only of interest if a service implementor
807 but instead implements custom asynchronous event processing.
808 It is called when the
810 system call has determined that an RPC request has arrived on some
813 is the resultant read file descriptor bit mask.
814 The routine returns when all sockets associated with the
821 but limited to 32 descriptors.
822 This interface is obsoleted by
824 .It Fn svc_getrpccaller
825 The approved way of getting the network address of the caller
826 of a procedure associated with the RPC service transport handle,
833 with the service dispatch procedure,
837 is zero, the service is not registered with the
842 is non-zero, then a mapping of the triple
847 .Fa xprt-\*[Gt]xp_port
848 is established with the local
858 has the following form:
860 .Fn dispatch "struct svc_req *request" "SVCXPRT *xprt" .
864 routine returns one if it succeeds, and zero otherwise.
866 This routine never returns.
867 It waits for RPC requests to arrive, and calls the appropriate service
871 This procedure is usually waiting for a
873 system call to return.
875 Called by an RPC service's dispatch routine to send the results of a
876 remote procedure call.
879 is the request's associated transport handle;
881 is the XDR routine which is used to encode the results; and
883 is the address of the results.
884 This routine returns one if it succeeds, zero otherwise.
885 .It Fn svc_unregister
886 Remove all mapping of the double
889 to dispatch routines, and of the triple
895 Called by a service dispatch routine that refuses to perform
896 a remote procedure call due to an authentication error.
898 Called by a service dispatch routine that cannot successfully
899 decode its parameters.
903 Called by a service dispatch routine that does not implement
904 the procedure number that the caller requests.
906 Called when the desired program is not registered with the RPC
908 Service implementors usually do not need this routine.
909 .It Fn svcerr_progvers
910 Called when the desired version of a program is not registered
911 with the RPC package.
912 Service implementors usually do not need this routine.
913 .It Fn svcerr_systemerr
914 Called by a service dispatch routine when it detects a system error
915 not covered by any particular protocol.
916 For example, if a service can no longer allocate storage,
917 it may call this routine.
918 .It Fn svcerr_weakauth
919 Called by a service dispatch routine that refuses to perform
920 a remote procedure call due to insufficient
921 authentication parameters.
923 .Fn svcerr_auth "xprt" "AUTH_TOOWEAK" .
925 This routine creates a toy RPC service transport, to which it returns
927 The transport is really a buffer within the process's address space,
928 so the corresponding RPC client should live in the same address space;
931 This routine allows simulation of RPC and acquisition of RPC overheads
932 (such as round trip times), without any kernel interference.
937 This routine creates a TCP/IP-based RPC service transport, to which it
939 The transport is associated with the socket
943 in which case a new socket is created.
944 If the socket is not bound to a local TCP
945 port, then this routine binds it to an arbitrary port.
947 .Fa xprt-\*[Gt]xp_sock
948 is the transport's socket descriptor, and
949 .Fa xprt-\*[Gt]xp_port
950 is the transport's port number.
954 Since TCP-based RPC uses buffered I/O ,
955 users may specify the size of buffers; values of zero
956 choose suitable defaults.
958 Create a service on top of any open descriptor.
959 Typically, this descriptor is a connected socket
960 for a stream protocol such as TCP.
964 indicate sizes for the send and receive buffers.
965 If they are zero, a reasonable default is chosen.
966 .It Fn svcudp_bufcreate
967 This routine creates a UDP/IP-based RPC
968 service transport, to which it returns a pointer.
969 The transport is associated with the socket
973 in which case a new socket is created.
974 If the socket is not bound to a local UDP
975 port, then this routine binds it to an arbitrary port.
977 .Fa xprt-\*[Gt]xp_sock
978 is the transport's socket descriptor, and
979 .Fa xprt-\*[Gt]xp_port
980 is the transport's port number.
985 This allows the user to specify the maximum packet size for sending and
986 receiving UDP-based RPC messages.
989 .Fn svcudp_bufcreate with
990 predefined sizes for the maximum packet sizes.
991 .It Fn xdr_accepted_reply
992 Used for encoding RPC reply messages.
993 This routine is useful for users who wish to generate RPC-style
994 messages without using the RPC package.
995 .It Fn xdr_authunix_parms
996 Used for describing UNIX credentials.
997 This routine is useful for users who wish to generate these
998 credentials without using the RPC authentication package.
1000 Used for describing RPC call header messages.
1001 This routine is useful for users who wish to generate RPC-style
1002 messages without using the RPC package.
1004 Used for describing RPC call messages.
1005 This routine is useful for users who wish to generate RPC-style
1006 messages without using the RPC package.
1007 .It Fn xdr_opaque_auth
1008 Used for describing RPC authentication information messages.
1009 This routine is useful for users who wish to generate RPC-style
1010 messages without using the RPC package.
1012 Used for describing parameters to various
1014 procedures, externally.
1015 This routine is useful for users who wish to generate
1016 these parameters without using the
1020 Used for describing a list of port mappings, externally.
1021 This routine is useful for users who wish to generate
1022 these parameters without using the
1025 .It Fn xdr_rejected_reply
1026 Used for describing RPC reply messages.
1027 This routine is useful for users who wish to generate RPC-style
1028 messages without using the RPC package.
1030 Used for describing RPC reply messages.
1031 This routine is useful for users who wish to generate RPC-style
1032 messages without using the RPC package.
1033 .It Fn xprt_register
1034 After RPC service transport handles are created,
1035 they should register themselves with the RPC service package.
1036 This routine modifies the global variable
1038 Service implementors usually do not need this routine.
1039 .It Fn xprt_unregister
1040 Before an RPC service transport handle is destroyed,
1041 it should unregister itself with the RPC service package.
1042 This routine modifies the global variable
1044 Service implementors usually do not need this routine.
1047 .\".Xr rpc_secure 3 ,
1050 The following manuals:
1052 .%B Remote Procedure Calls: Protocol Specification
1055 .%B Remote Procedure Call Programming Guide
1058 .%B rpcgen Programming Guide
1062 .%A Sun Microsystems, Inc., USC-ISI
1063 .%T "RPC: Remote Procedure Call Protocol Specification"