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