xref: /openbsd/lib/libc/rpc/rpc.3 (revision 84b47185)
1.\"	$OpenBSD: rpc.3,v 1.27 2001/09/16 19:12:31 millert Exp $
2.\" Mostly converted to mandoc by Theo de Raadt, Tue Feb 24 04:04:46 MST 1998
3.\"
4.Dd February 16, 1988
5.Dt RPC 3
6.Os
7.Sh NAME
8.Nm callrpc ,
9.Nm clnt_broadcast ,
10.Nm clnt_call ,
11.Nm clnt_control ,
12.Nm clnt_create ,
13.Nm clnt_destroy ,
14.Nm clnt_freeres ,
15.Nm clnt_pcreateerror ,
16.Nm clnt_perrno ,
17.Nm clnt_perror ,
18.Nm clnt_spcreateerror ,
19.Nm clnt_sperrno ,
20.Nm clnt_sperror ,
21.Nm clntraw_create ,
22.Nm clnttcp_create ,
23.Nm clntudp_bufcreate ,
24.Nm clntudp_create ,
25.Nm clntudp_create ,
26.Nm clnt_geterr ,
27.Nm get_myaddress ,
28.Nm pmap_getmaps ,
29.Nm pmap_getport ,
30.Nm pmap_rmtcall ,
31.Nm pmap_set ,
32.Nm pmap_unset ,
33.Nm registerrpc ,
34.Nm rpc_createerr ,
35.Nm svc_fdset ,
36.Nm svc_freeargs ,
37.Nm svc_getargs ,
38.Nm svc_getcaller ,
39.Nm svc_getreq ,
40.Nm svc_getreqset ,
41.Nm svc_getreqset2 ,
42.Nm svc_register ,
43.Nm svc_sendreply ,
44.Nm svc_unregister ,
45.Nm svcerr_auth ,
46.Nm svcerr_decode ,
47.Nm svcerr_noproc ,
48.Nm svcerr_noprog ,
49.Nm svcerr_progvers ,
50.Nm svcerr_systemerr ,
51.Nm svcerr_weakauth ,
52.Nm svcfd_create ,
53.Nm svctcp_create ,
54.Nm svcudp_bufcreate ,
55.Nm xdr_accepted_reply ,
56.Nm xdr_authunix_parms ,
57.Nm xdr_callhdr ,
58.Nm xdr_callmsg ,
59.Nm xdr_opaque_auth ,
60.Nm xdr_pmap ,
61.Nm xdr_pmaplist ,
62.Nm xdr_rejected_reply ,
63.Nm xdr_replymsg ,
64.Nm xprt_register ,
65.Nm xprt_unregister
66.Nd library routines for remote procedure calls
67.Sh SYNOPSIS
68.Fd #include <rpc/rpc.h>
69.Ft int
70.Fn callrpc "char *host" "u_long prognum" "u_long versnum" "u_long procnum" "xdrproc_t inproc" "char *in" "xdrproc_t outproc" "char *out"
71.Ft "enum clnt_stat"
72.Fn clnt_broadcast "u_long prognum" "u_long versnum" "u_long procnum" "xdrproc_t inproc" "char *in" "xdrproc_t outproc" "char *out" "resultproc_t eachresult"
73.Ft "enum clnt_stat"
74.Fn clnt_call "CLIENT *clnt" "u_long procnum" "xdrproc_t inproc" "char *in" "xdrproc_t outproc" "char *out" "struct timeval tout"
75.Ft int
76.Fn clnt_destroy "CLIENT *clnt"
77.Ft CLIENT *
78.Fn clnt_create "char *host" "u_long prog" "u_long vers" "char *proto"
79.Ft bool_t
80.Fn clnt_control "CLIENT *cl" "int req" "char *info"
81.Ft int
82.Fn clnt_freeres "CLIENT *clnt" "xdrproc_t outproc" "char *out"
83.Ft void
84.Fn clnt_geterr "CLIENT *clnt" "struct rpc_err *errp"
85.Ft void
86.Fn clnt_pcreateerror "char *s"
87.Ft void
88.Fn clnt_perrno "enum clnt_stat stat"
89.Ft int
90.Fn clnt_perror "CLIENT *clnt" "char *s"
91.Ft char *
92.Fn clnt_spcreateerror "char *s"
93.Ft char *
94.Fn clnt_sperrno "enum clnt_stat stat"
95.Ft char *
96.Fn clnt_sperror "CLIENT *rpch" "char *s"
97.Ft CLIENT *
98.Fn clntraw_create "u_long prognum" "u_long versnum"
99.Ft CLIENT *
100.Fn clnttcp_create "struct sockaddr_in *addr" "u_long prognum" "u_long versnum" "int *sockp" "u_int sendsz" "u_int recvsz"
101.Ft CLIENT *
102.Fn clntudp_create "struct sockaddr_in *addr" "u_long prognum" "u_long versnum" "struct timeval wait" "int *sockp"
103.Ft CLIENT *
104.Fn clntudp_bufcreate "struct sockaddr_in *addr" "u_long prognum" "u_long versnum" "struct timeval wait" "int *sockp" "unsigned int sendsize" "unsigned int recosize"
105.Ft int
106.Fn get_myaddress "struct sockaddr_in *addr"
107.Ft struct pmaplist *
108.Fn pmap_getmaps "struct sockaddr_in *addr"
109.Ft u_short
110.Fn pmap_getport "struct sockaddr_in *addr" "u_long prognum" "u_long versnum" "u_long protocol"
111.\" XXX the following works around an apparent nroff line length bug.
112.Ft "enum clnt_stat"
113.Fn pmap_rmtcall "struct sockaddr_in *" "u_long prog, vers, proc" "xdrproc_t inp" "char *in" "xdrproc_t outp" "char *out" "struct timeval tv" "u_long *portp"
114.Ft int
115.Fn pmap_set "u_long prognum" "u_long versnum" "u_int protocol" "u_short port"
116.Ft int
117.Fn pmap_unset "u_long prognum" "u_long versnum"
118.Ft int
119.Fn registerrpc "u_long prognum" "u_long versnum" "u_long procnum" "char *(*procname)() " "xdrproc_t inproc" "xdrproc_t outproc"
120.Ft struct rpc_createerr
121.Fa rpc_createerr ;
122.Ft int
123.Fn svc_destroy "SVCXPRT *xprt"
124.Ft fd_set
125.Fa svc_fdset ;
126.Ft fd_set
127.Fa *__svc_fdset ;
128.Ft int
129.Fa __svc_fdsetsize ;
130.Ft int
131.Fa svc_fds ;
132.Ft int
133.Fn svc_freeargs "SVCXPRT *xprt" "xdrproc_t inproc" "char *in"
134.Ft int
135.Fn svc_getargs "SVCXPRT *xprt" "xdrproc_t inproc" "char *in"
136.Ft struct sockaddr_in *
137.Fn svc_getcaller "SVCXPRT *xprt"
138.Ft int
139.Fn svc_getreqset "fd_set *rdfds"
140.Ft int
141.Fn svc_getreqset2 "fd_set *rdfds, int width"
142.Ft int
143.Fn svc_getreq "int rdfds"
144.Ft int
145.Fn svc_register "SVCXPRT *xprt" "u_long prognum" "u_long versnum" "void (*dispatch)()" "u_long protocol"
146.Ft int
147.Fn svc_run "void"
148.Ft int
149.Fn svc_sendreply "SVCXPRT *xprt" "xdrproc_t outproc" "char *out"
150.Ft void
151.Fn svc_unregister "u_long prognum" "u_long versnum"
152.Ft void
153.Fn svcerr_auth "SVCXPRT *xprt" "enum auth_stat why"
154.Ft void
155.Fn svcerr_decode "SVCXPRT *xprt"
156.Ft void
157.Fn svcerr_noproc "SVCXPRT *xprt"
158.Ft void
159.Fn svcerr_noprog "SVCXPRT *xprt"
160.Ft void
161.Fn svcerr_progvers "SVCXPRT *xprt"
162.Ft void
163.Fn svcerr_systemerr "SVCXPRT *xprt"
164.Ft void
165.Fn svcerr_weakauth "SVCXPRT *xprt"
166.Ft SVCXPRT *
167.Fn svcraw_create "void"
168.Ft SVCXPRT *
169.Fn svctcp_create "int sock" "u_int send_buf_size" "u_int recv_buf_size"
170.Ft SVCXPRT *
171.Fn svcfd_create "int fd" "u_int sendsize" "u_int recvsize"
172.Ft SVCXPRT *
173.Fn svcudp_bufcreate "int sock"
174.Ft bool_t
175.Fn xdr_accepted_reply "XDR *xdrs" "struct accepted_reply *ar"
176.Ft bool_t
177.Fn xdr_authunix_parms "XDR *xdrs" "struct authunix_parms *aupp"
178.Ft void
179.Fn xdr_callhdr "XDR *xdrs" "struct rpc_msg *chdr"
180.Ft int
181.Fn xdr_callmsg "XDR *xdrs" "struct rpc_msg *cmsg"
182.Ft int
183.Fn xdr_opaque_auth "XDR *xdrs" "struct opaque_auth *ap"
184.Ft int
185.Fn xdr_pmap "XDR *xdrs" "struct pmap *regs"
186.Ft int
187.Fn xdr_pmaplist "XDR *xdrs" "struct pmaplist **rp"
188.Ft int
189.Fn xdr_rejected_reply "XDR *xdrs" "struct rejected_reply *rr"
190.Ft int
191.Fn xdr_replymsg "XDR *xdrs" "struct rpc_msg *rmsg"
192.Ft void
193.Fn xprt_register "SVCXPRT *xprt"
194.Ft void
195.Fn xprt_unregister "SVCXPRT *xprt"
196.Sh DESCRIPTION
197These routines allow C programs to make procedure
198calls on other machines across the network.
199First, the client calls a procedure to send a
200data packet to the server.
201Upon receipt of the packet, the server calls a dispatch routine
202to perform the requested service, and then sends back a
203reply.
204Finally, the procedure call returns to the client.
205.Pp
206.\"Routines that are used for Secure RPC (DES authentication) are described in
207.\".Xr rpc_secure 3 .
208.\"Secure RPC can be used only if DES encryption is available.
209.Fn callrpc
210calls the remote procedure associated with
211.Fa prognum ,
212.Fa versnum ,
213and
214.Fa procnum
215on the machine,
216.Fa host .
217The parameter
218.Fa in
219is the address of the procedure's argument(s), and
220.Fa out
221is the address of where to place the result(s);
222.Fa inproc
223is used to encode the procedure's parameters, and
224.Fa outproc
225is used to decode the procedure's results.
226This routine returns zero if it succeeds, or the value of
227.Fa enum clnt_stat"
228cast to an integer if it fails.
229The routine
230.Fn clnt_perrno
231is handy for translating failure statuses into messages.
232.Pp
233.Sy Warning:
234calling remote procedures with this routine uses
235.Tn UDP/IP
236as a transport; see
237.Fn clntudp_create
238for restrictions.
239You do not have control of timeouts or authentication using
240this routine.
241.Pp
242.Fn clnt_broadcast
243is like
244.Fn callrpc ,
245except the call message is broadcast to all locally
246connected broadcast nets.
247Each time it receives a response, this routine calls
248.Fa eachresult ,
249whose form is:
250.Bd -literal -offset indent
251.Ft int
252.Fn eachresult "char *out" "struct sockaddr_in *addr"
253.Ed
254.Pp
255where
256.Fa out
257is the same as
258.Fa out
259passed to
260.Fn clnt_broadcast ,
261except that the remote procedure's output is decoded there;
262.Fa addr
263points to the address of the machine that sent the results.
264If
265.Fa eachresult
266returns zero,
267.Fn clnt_broadcast
268waits for more replies; otherwise it returns with appropriate
269status.
270.Pp
271.Sy Warning:
272broadcast sockets are limited in size to the
273maximum transfer unit of the data link.
274For Ethernet, this value is 1500 bytes.
275.Pp
276.Fn clnt_call
277is a macro that calls the remote procedure
278.Fa procnum
279associated with the client handle,
280.Fa clnt ,
281which is obtained with an
282.Tn RPC
283client creation routine such as
284.Fn clnt_create .
285The parameter
286.Fa in
287is the address of the procedure's argument(s), and
288.Fa out
289is the address of where to place the result(s);
290.Fa inproc
291is used to encode the procedure's parameters, and
292.Fa outproc
293is used to decode the procedure's results;
294.Fa tout
295is the time allowed for results to come back.
296.Pp
297.Fn clnt_destroy
298is a macro that destroys the client's
299.Tn RPC
300handle.
301Destruction usually involves deallocation of private data structures, including
302.Fa clnt
303itself.
304Use of
305.Fa clnt
306is undefined after calling
307.Fn clnt_destroy .
308If the
309.Tn RPC
310library opened the associated socket, it will close it also.
311Otherwise, the socket remains open.
312.Pp
313.Fn clnt_create
314is a generic client creation routine.
315.Fa host
316identifies the name of the remote host where the server
317is located.
318.Fa proto
319indicates which kind of transport protocol to use.
320The currently supported values for this field are \(lqudp\(rq
321and \(lqtcp\(rq.
322Default timeouts are set, but can be modified using
323.Fn clnt_control .
324.Pp
325.Sy Warning:
326Using
327.Tn UDP
328has its shortcomings.
329Since
330.Tn UDP-based
331.Tn RPC
332messages can only hold up to 8 Kbytes of encoded data,
333this transport cannot be used for procedures that take
334large arguments or return huge results.
335.Pp
336.Fn clnt_control
337is a macro used to change or retrieve various information
338about a client object.
339.Fa req
340indicates the type of operation, and
341.Fa info
342is a pointer to the information.
343For both
344.Tn UDP
345and
346.Tn TCP ,
347the supported values of
348.Fa req
349and their argument types and what they do are:
350.Pp
351.Bd -literal -offset indent
352.Tn CLSET_TIMEOUT	struct timeval	set total timeout
353.Tn CLGET_TIMEOUT	struct timeval	get total timeout
354.Ed
355.Pp
356.Sy Note:
357if you set the timeout using
358.Fn clnt_control ,
359the timeout parameter passed to
360.Fn clnt_call
361will be ignored in all future calls.
362.Pp
363.Bd -literal -offset indent
364.Tn CLGET_SERVER_ADDR	struct sockaddr_in 	get server's address
365.Ed
366.Pp
367The following operations are valid for
368.Tn UDP
369only:
370.Pp
371.Bd -literal -offset indent
372.Tn CLSET_RETRY_TIMEOUT   struct timeval	set the retry timeout
373.Tn CLGET_RETRY_TIMEOUT   struct timeval	get the retry timeout
374.Ed
375.Pp
376The retry timeout is the time that
377.Tn "UDP RPC"
378waits for the server to reply before
379retransmitting the request.
380.Pp
381.Fn clnt_freeres
382is a macro that frees any data allocated by the
383.Tn RPC/XDR
384system when it decoded the results of an
385.Tn RPC
386call.
387The parameter
388.Fa out
389is the address of the results, and
390.Fa outproc
391is the
392.Tn XDR
393routine describing the results.
394This routine returns one if the results were successfully
395freed,
396and zero otherwise.
397.Pp
398.Fn clnt_geterr
399is a macro that copies the error structure out of the client
400handle
401to the structure at address
402.Fa errp .
403.Pp
404.Fn clnt_pcreateerror
405print a message to standard error indicating
406why a client
407.Tn RPC
408handle could not be created.
409The message is prepended with string
410.Fa s
411and a colon.
412Used when a
413.Fn clnt_create ,
414.Fn clntraw_create ,
415.Fn clnttcp_create ,
416or
417.Fn clntudp_create
418call fails.
419.Pp
420.Fn clnt_perrno
421prints a message to standard error corresponding
422to the condition indicated by
423.Fa stat .
424Used after
425.Fn callrpc .
426.Pp
427.Fn clnt_perror
428prints a message to standard error indicating why an
429.Tn RPC
430call failed;
431.Fa clnt
432is the handle used to do the call.
433The message is prepended with string
434.Fa s
435and a colon.
436Used after
437.Fn clnt_call .
438.Pp
439.Fn clnt_spcreateerror
440is like
441.Fn clnt_pcreateerror ,
442except that it returns a string
443instead of printing to the standard error.
444.Pp
445.Sy Bugs:
446returns pointer to static data that is overwritten
447on each call.
448.Pp
449.Fn clnt_sperrno
450takes the same arguments as
451.Fn clnt_perrno ,
452but instead of sending a message to the standard error
453indicating why an
454.Tn RPC
455call failed, return a pointer to a string which contains
456the message.
457Unlike
458.Fn clnt_perror ,
459it does not append a
460.Tn NEWLINE
461to the end of the message.
462.Pp
463.Fn clnt_sperrno
464is used instead of
465.Fn clnt_perrno
466if the program does not have a standard error (as a program
467running as a server quite likely does not), or if the
468programmer
469does not want the message to be output with
470.Fn printf ,
471or if a message format different than that supported by
472.Fn clnt_perrno
473is to be used.
474.Pp
475.Sy Note:
476unlike
477.Fn clnt_sperror
478and
479.Fn clnt_spcreaterror ,
480.Fn clnt_sperrno
481returns pointer to static data, but the
482result will not get overwritten on each call.
483.Pp
484.Fn clnt_sperror
485is like
486.Fn clnt_perror ,
487except that (like
488.Fn clnt_sperrno )
489it returns a string instead of printing to standard error.
490.Pp
491.Sy Bugs:
492returns pointer to static data that is overwritten
493on each call.
494.Pp
495.Fn clntraw_create
496is a routine which creates a toy
497.Tn RPC
498client for the remote program
499.Fa prognum ,
500version
501.Fa versnum .
502The transport used to pass messages to the service is
503actually a buffer within the process's address space, so the
504corresponding
505.Tn RPC
506server should live in the same address space; see
507.Fn svcraw_create .
508This allows simulation of
509.Tn RPC
510and acquisition of
511.Tn RPC
512overheads, such as round trip times, without any
513kernel interference.
514This routine returns
515.Tn NULL
516if it fails.
517.Pp
518.Fn clnttcp_create
519is a routine which creates an
520.Tn RPC
521client for the remote program
522.Fa prognum ,
523version
524.Fa versnum ;
525the client uses
526.Tn TCP/IP
527as a transport.
528The remote program is located at Internet address
529.Fa *addr .
530If
531.Fa addr\->sin_port
532is zero, then it is set to the actual port that the remote
533program is listening on (the remote
534.Xr portmap 8
535service is consulted for this information).
536The parameter
537.Fa sockp
538is a socket; if it is
539.Fa RPC_ANYSOCK ,
540then this routine opens a new one and sets
541.Fa sockp .
542Since
543.Tn TCP-based
544.Tn RPC
545uses buffered
546.Tn I/O ,
547the user may specify the size of the send and receive buffers
548with the parameters
549.Fa sendsz
550and
551.Fa recvsz ;
552values of zero choose suitable defaults.
553This routine returns
554.Tn NULL
555if it fails.
556.Pp
557.Fn clntudp_create
558is a routine which creates an
559.Tn RPC
560client for the remote program
561.Fa prognum ,
562on
563.Fa versnum ;
564the client uses use
565.Tn UDP/IP
566as a transport.
567The remote program is located at Internet address
568.Fa addr .
569If
570.Fa addr\->sin_port
571is zero, then it is set to actual port that the remote
572program is listening on (the remote
573.Xr portmap 8
574service is consulted for this information).
575The parameter
576.Fa sockp
577is a socket; if it is
578.Fa RPC_ANYSOCK ,
579then this routine opens a new one and sets
580.Fa sockp .
581The
582.Tn UDP
583transport resends the call message in intervals of
584.Fa wait
585time until a response is received or until the call times
586out.
587The total time for the call to time out is specified by
588.Fn clnt_call .
589.Pp
590This allows the user to specify the maximun packet size for sending
591and receiving
592.Tn UDP-based
593.Tn RPC
594messages.
595.Pp
596.Fn get_myaddress
597stuffs the machine's
598.Tn IP
599address into
600.Fa *addr ,
601without consulting the library routines that deal with
602.Pa /etc/hosts .
603The port number is always set to
604.Fa htons(PMAPPORT) .
605Returns zero on success, non-zero on failure.
606.Pp
607.Fn pmap_getmaps
608is a function interface to the
609.Xr portmap 8
610service, which returns a list of the current
611.Tn RPC
612program-to-port mappings
613on the host located at
614.Tn IP
615address
616.Fa *addr .
617This routine can return
618.Tn NULL .
619The command
620.Pa ` "rpcinfo \-p" '
621uses this routine.
622.Pp
623.Fn pmap_getport
624is a user interface to the
625.Xr portmap 8
626service, which returns the port number
627on which waits a service that supports program number
628.Fa prognum ,
629version
630.Fa versnum ,
631and speaks the transport protocol associated with
632.Fa protocol .
633The value of
634.Fa protocol
635is most likely
636.B
637.Tn IPPROTO_UDP
638or
639.Fa IPPROTO_TCP .
640A return value of zero means that the mapping does not exist
641or that
642the
643.Tn RPC
644system failured to contact the remote
645.Xr portmap 8
646service.
647In the latter case, the global variable
648.Fn rpc_createerr
649contains the
650.Tn RPC
651status.
652.Pp
653.Fn pmap_rmtcall
654is a user interface to the
655.Xr portmap 8
656service, which instructs
657.Xr portmap 8
658on the host at
659.Tn IP
660address
661.Fa *addr
662to make an
663.Tn RPC
664call on your behalf to a procedure on that host.
665The parameter
666.Fa *portp
667will be modified to the program's port number if the
668procedure
669succeeds.
670The definitions of other parameters are discussed in
671.Fn callrpc
672and
673.Fn clnt_call .
674This procedure should be used for a \(lqping\(rq and nothing
675else.
676See also
677.Fn clnt_broadcast .
678.Pp
679.Fn pmap_set
680is a user interface to the
681.Xr portmap 8
682service, which establishes a mapping between the triple
683.Fa [ prognum , versnum , protocol]
684and
685.Fa port
686on the machine's
687.Xr portmap 8
688service.
689The value of
690.Fa protocol
691is most likely
692.B
693.Tn IPPROTO_UDP
694or
695.Fa IPPROTO_TCP .
696This routine returns one if it succeeds, zero otherwise.
697Automatically done by
698.Fn svc_register .
699.Pp
700.Fn pmap_unset
701is a user interface to the
702.Xr portmap 8
703service, which destroys all mapping between the triple
704.Fa [ prognum , versnum , *]
705and
706.Fa ports
707on the machine's
708.Xr portmap 8
709service.
710This routine returns one if it succeeds, zero otherwise.
711.Pp
712.Fn registerrpc
713will register a procedure
714.Fa procname
715with the
716.Tn RPC
717service package.
718If a request arrives for program
719.Fa prognum ,
720version
721.Fa versnum ,
722and procedure
723.Fa procnum ,
724.Fa procname
725is called with a pointer to its parameter(s);
726.Fa progname
727should return a pointer to its static result(s);
728.Fa inproc
729is used to decode the parameters while
730.Fa outproc
731is used to encode the results.
732This routine returns zero if the registration succeeded, \-1
733otherwise.
734.Pp
735.Sy Warning:
736remote procedures registered in this form
737are accessed using the
738.Tn UDP/IP
739transport; see
740.Fn svcudp_create
741for restrictions.
742.Pp
743.Fa rpc_createerr
744is a global variable whose value is set by any
745.Tn RPC
746client creation routine
747that does not succeed.
748Use the routine
749.Fn clnt_pcreateerror
750to print the reason why.
751.Pp
752.Fn svc_destroy
753is a macro that destroys the
754.Tn RPC
755service transport handle,
756.Fa xprt .
757Destruction usually involves deallocation
758of private data structures, including
759.Fa xprt
760itself.
761Use of
762.Fa xprt
763is undefined after calling this routine.
764.Pp
765.Fa __svc_fdset
766and
767.Fa __svc_fdsetsize
768are global variables reflecting the
769.Tn RPC
770service side's
771read file descriptor bit mask.
772.Fa __svc_fdsetsize
773is a count of the number of checkable bits in
774.Fa __svc_fdset, and can expand to the full size that
775.Xr select 2
776supports, hence exceeding
777.Fa FD_SETSIZE
778if required.
779These variables are only of interest
780if service implementors do not call
781.Fn svc_run ,
782but rather do their own asynchronous event processing.
783This variable is read-only, and it may change after calls
784to svc_getreqset() or any creation routines.
785Do not pass its address to
786.Xr select 2 !
787Instead, pass the address of a copy.
788.Pp
789.Fa svc_fdset
790is similar to
791.Fa __svc_fdset
792but limited to
793.Fa FD_SETSIZE
794descriptors.
795This is the preferred interface for portability though.
796This is only of interest
797if service implementors do not call
798.Fn svc_run ,
799but rather do their own asynchronous event processing.
800This variable is read-only, and it may change after calls
801to svc_getreqset() or any creation routines.
802Do not pass its address to
803.Xr select 2 !
804Instead, pass the address of a copy.
805.Pp
806As well, note that if the process has descriptor limits
807which are extended beyond
808.Fa FD_SETSIZE ,
809this variable will only be usable for the first
810.Fa FD_SETSIZE
811descriptors.
812.Pp
813.Fa svc_fds
814is similar to
815.Fa svc_fedset ,
816but limited to 32 descriptors.
817This interface is obsoleted by
818.Fa svc_fdset .
819.Pp
820.Fn svc_freeargs
821is a macro that frees any data allocated by the
822.Tn RPC/XDR
823system when it decoded the arguments to a service procedure
824using
825.Fn svc_getargs .
826This routine returns 1 if the results were successfully
827freed,
828and zero otherwise.
829.Pp
830.Fn svc_getargs
831is a macro that decodes the arguments of an
832.Tn RPC
833request
834associated with the
835.Tn RPC
836service transport handle,
837.Fa xprt .
838The parameter
839.Fa in
840is the address where the arguments will be placed;
841.Fa inproc
842is the
843.Tn XDR
844routine used to decode the arguments.
845This routine returns one if decoding succeeds, and zero
846otherwise.
847.Pp
848.Fn svc_getcaller
849is the approved way of getting the network address of the caller
850of a procedure associated with the
851.Tn RPC
852service transport handle,
853.Fa xprt .
854.Pp
855.Fn svc_getreqset
856is a routine which is only of interest if a service implementor
857does not call
858.Fn svc_run ,
859but instead implements custom asynchronous event processing.
860It is called when the
861.Xr select 2
862system call has determined that an
863.Tn RPC
864request has arrived on some
865.Tn RPC
866.Fa socket(s) ;
867.Fa rdfds
868is the resultant read file descriptor bit mask.
869The routine returns when all sockets associated with the
870value of
871.Fa rdfds
872have been serviced.
873.Pp
874.Fn svc_getreqset2
875is a non-standard routine which is only of interest if a service
876implementor does not call
877.Fn svc_run ,
878but instead implements custom asynchronous event processing.
879It is called when the
880.Xr select 2
881system call has determined that an
882.Tn RPC
883request has arrived on some
884.Tn RPC
885.Fa socket(s) ;
886.Fa rdfds
887is the resultant read file descriptor bit mask.
888The routine returns when all sockets associated with the
889value of
890.Fa rdfds
891have been serviced.
892This interface is non-portable, but provided for applications which
893need to deal with large fd_set sizes.
894.Tn RPC
895internals use it.
896.Pp
897.Fn svc_getreq
898is similar to
899.Fa svc_getreqset ,
900but limited to 32 descriptors.
901This interface is obsoleted by
902.Fa svc_getreqset .
903.Pp
904.Fn svc_register
905associates
906.Fa prognum
907and
908.Fa versnum
909with the service dispatch procedure,
910.Fa dispatch .
911If
912.Fa protocol
913is zero, the service is not registered with the
914.Xr portmap 8
915service.
916If
917.Fa protocol
918is non-zero, then a mapping of the triple
919.Fa [ prognum , versnum , protocol]
920to
921.Fa xprt\->xp_port
922is established with the local
923.Xr portmap 8
924service (generally
925.Fa protocol
926is zero,
927.B
928.Tn IPPROTO_UDP
929or
930.B
931.Tn IPPROTO_TCP ) .
932The procedure
933.Fa dispatch
934has the following form:
935.Ft int
936.Fn dispatch "struct svc_req *request" "SVCXPRT *xprt"
937The
938.Fn svc_register
939routine returns one if it succeeds, and zero otherwise.
940.Pp
941.Fn svc_run
942never returns.
943It waits for
944.Tn RPC
945requests to arrive, and calls the appropriate service
946procedure using
947.Fn svc_getreq
948when one arrives.
949This procedure is usually waiting for a
950.Xr select 2
951system call to return.
952.Pp
953.Fn svc_sendreply
954is called by an
955.Tn RPC
956service's dispatch routine to send the results of a
957remote procedure call.
958The parameter
959.Fa xprt
960is the request's associated transport handle;
961.Fa outproc
962is the
963.Tn XDR
964routine which is used to encode the results; and
965.Fa out
966is the address of the results.
967This routine returns one if it succeeds, zero otherwise.
968.Pp
969.Fn svc_unregister
970removes all mapping of the double
971.Fa [ prognum , versnum ]
972to dispatch routines, and of the triple
973.Fa [ prognum , versnum , *]
974to port number.
975.Pp
976.Fn svcerr_auth
977is called by a service dispatch routine that refuses to perform
978a remote procedure call due to an authentication error.
979.Pp
980.Fn svcerr_decode
981is called by a service dispatch routine that cannot successfully
982decode its parameters.
983See also
984.Fn svc_getargs .
985.Pp
986.Fn svcerr_noproc
987is called by a service dispatch routine that does not implement
988the procedure number that the caller requests.
989.Pp
990.Fn svcerr_noprog
991is called when the desired program is not registered with the
992.Tn RPC
993package.
994Service implementors usually do not need this routine.
995.Pp
996.Fn svcerr_progvers
997is called when the desired version of a program is not registered
998with the
999.Tn RPC
1000package.
1001Service implementors usually do not need this routine.
1002.Pp
1003.Fn svcerr_systemerr
1004is called by a service dispatch routine when it detects a system
1005error
1006not covered by any particular protocol.
1007For example, if a service can no longer allocate storage,
1008it may call this routine.
1009.Pp
1010.Fn svcerr_weakauth
1011is called by a service dispatch routine that refuses to perform
1012a remote procedure call due to insufficient
1013authentication parameters.
1014The routine calls
1015.Fa "svcerr_auth(xprt, AUTH_TOOWEAK)" .
1016.Pp
1017.Fn svcraw_create
1018is a routine which creates a toy
1019.Tn RPC
1020service transport, to which it returns a pointer.
1021The transport is really a buffer within the process's address space,
1022so the corresponding
1023.Tn RPC
1024client should live in the same
1025address space;
1026see
1027.Fn clntraw_create .
1028This routine allows simulation of
1029.Tn RPC
1030and acquisition of
1031.Tn RPC
1032overheads (such as round trip times), without any kernel
1033interference.
1034This routine returns
1035.Tn NULL
1036if it fails.
1037.Pp
1038.Fn svctcp_create
1039is a routine which creates a
1040.Tn TCP/IP-based
1041.Tn RPC
1042service transport, to which it returns a pointer.
1043The transport is associated with the socket
1044.Fa sock ,
1045which may be
1046.Fa RPC_ANYSOCK ,
1047in which case a new socket is created.
1048If the socket is not bound to a local
1049.Tn TCP
1050port, then this routine binds it to an arbitrary port.
1051Upon completion,
1052.Fa xprt\->xp_sock
1053is the transport's socket descriptor, and
1054.Fa xprt\->xp_port
1055is the transport's port number.
1056This routine returns
1057.Tn NULL
1058if it fails.
1059Since
1060.Tn TCP-based
1061.Tn RPC
1062uses buffered
1063.Tn I/O ,
1064users may specify the size of buffers; values of zero
1065choose suitable defaults.
1066.Pp
1067.Fn svcfd_create
1068will create a service on top of any open descriptor.
1069Typically, this descriptor is a connected socket for a stream protocol such
1070as
1071.Tn TCP .
1072.Fa sendsize
1073and
1074.Fa recvsize
1075indicate sizes for the send and receive buffers.
1076If they are zero, a reasonable default is chosen.
1077.Pp
1078.Fn svcudp_bufcreate
1079is a routine which creates a
1080.Tn UDP/IP-based
1081.Tn RPC
1082service transport, to which it returns a pointer.
1083The transport is associated with the socket
1084.Fa sock ,
1085which may be
1086.Fa RPC_ANYSOCK ,
1087in which case a new socket is created.
1088If the socket is not bound to a local
1089.Tn UDP
1090port, then this routine binds it to an arbitrary port.
1091Upon completion,
1092.Fa xprt\->xp_sock
1093is the transport's socket descriptor, and
1094.Fa xprt\->xp_port
1095is the transport's port number.
1096This routine returns
1097.Tn NULL
1098if it fails.
1099.Pp
1100This allows the user to specify the maximun packet size for sending and
1101receiving
1102.Tn UDP-based
1103.Tn RPC
1104messages.
1105.Pp
1106.Fn xdr_accepted_reply
1107is used for encoding
1108.Tn RPC
1109reply messages.
1110This routine is useful for users who wish to generate RPC-style
1111messages without using the
1112.Tn RPC
1113package.
1114.Pp
1115.Fn xdr_authunix_parms
1116is used for describing
1117.Tn UNIX
1118credentials.
1119This routine is useful for users
1120who wish to generate these credentials without using the
1121.Tn RPC
1122authentication package.
1123.Pp
1124.Fn xdr_callhdr
1125is used for describing
1126.Tn RPC
1127call header messages.
1128This routine is useful for users who wish to generate
1129.Tn RPC-style
1130messages without using the
1131.Tn RPC
1132package.
1133.Pp
1134.Fn xdr_callmsg
1135is used for describing
1136.Tn RPC
1137call messages.
1138This routine is useful for users who wish to generate
1139.Tn RPC-style
1140messages without using the
1141.Tn RPC
1142package.
1143.Pp
1144.Fn xdr_opaque_auth
1145is used for describing
1146.Tn RPC
1147authentication information messages.
1148This routine is useful for users who wish to generate
1149.Tn RPC-style
1150messages without using the
1151.Tn RPC
1152package.
1153.Pp
1154.Fn xdr_pmap
1155is used for describing parameters to various
1156.Xr portmap 8
1157procedures, externally.
1158This routine is useful for users who wish to generate
1159these parameters without using the pmap interface.
1160.Pp
1161.Fn xdr_pmaplist
1162is used for describing a list of port mappings, externally.
1163This routine is useful for users who wish to generate
1164these parameters without using the pmap interface.
1165.Pp
1166.Fn xdr_rejected_reply
1167is used for describing
1168.Tn RPC
1169reply messages.
1170This routine is useful for users who wish to generate
1171.Tn RPC-style
1172messages without using the
1173.Tn RPC
1174package.
1175.Pp
1176.Fn xdr_replymsg
1177is used for describing
1178.Tn RPC
1179reply messages.
1180This routine is useful for users who wish to generate
1181.Tn RPC
1182style messages without using the
1183.Tn RPC
1184package.
1185.Pp
1186.Fn xprt_register
1187is used to register transport handles.
1188After
1189.Tn RPC
1190service transport handles are created,
1191they should register themselves with the
1192.Tn RPC
1193service package.
1194This routine modifies the global variable
1195.Fa svc_fds .
1196Service implementors usually do not need this routine.
1197.Pp
1198.Fn xprt_unregister
1199is used to unregister a transport handle.
1200Before an
1201.Tn RPC
1202service transport handle is destroyed,
1203it should unregister itself with the
1204.Tn RPC
1205service package.
1206This routine modifies the global variable
1207.Fa svc_fds .
1208Service implementors usually do not need this routine.
1209.Sh SEE ALSO
1210.\"Xr rpc_secure 3 ,
1211.Xr rpcgen 1 ,
1212.Xr select 2 ,
1213.Xr getrpcent 3 ,
1214.Xr getrpcport 3 ,
1215.Xr rpcauth 3 ,
1216.Xr xdr 3 ,
1217.Xr rpc 5 ,
1218.Xr portmap 8
1219.Pp
1220The following manuals:
1221.Rs
1222.%A "Sun Microsystems, Inc."
1223.%T "Remote Procedure Calls: Protocol Specification"
1224.Re
1225.Rs
1226.%A "Sun Microsystems, Inc."
1227.%T "Remote Procedure Call Programming Guide"
1228.Re
1229.Rs
1230.%A "Sun Microsystems, Inc."
1231.%T "rpcgen Programming Guide"
1232.Re
1233.Rs
1234.%A "Sun Microsystems, Inc."
1235.%T "RPC: Remote Procedure Call Protocol Specification"
1236.Re
1237.Rs
1238.%A "Sun Microsystems, Inc."
1239.%D "June 1988"
1240.%T "RFC 1057"
1241.Re
1242