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