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