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