1.\" @(#)rpc_clnt_create.3n 1.36 93/08/31 SMI; from SVr4 2.\" Copyright 1989 AT&T 3.\" @(#)rpc_clnt_create 1.5 89/07/24 SMI; 4.\" Copyright (c) 1988 Sun Microsystems, Inc. - All Rights Reserved. 5.\" $NetBSD: rpc_clnt_create.3,v 1.2 2000/06/20 00:53:08 fvdl Exp $ 6.\" $FreeBSD$ 7.Dd May 7, 1993 8.Dt RPC_CLNT_CREATE 3 9.Os 10.Sh NAME 11.Nm rpc_clnt_create , 12.Nm clnt_control , 13.Nm clnt_create , 14.Nm clnt_create_timed , 15.Nm clnt_create_vers , 16.Nm clnt_create_vers_timed , 17.Nm clnt_destroy , 18.Nm clnt_dg_create , 19.Nm clnt_pcreateerror , 20.Nm clnt_raw_create , 21.Nm clnt_spcreateerror , 22.Nm clnt_tli_create , 23.Nm clnt_tp_create , 24.Nm clnt_tp_create_timed , 25.Nm clnt_vc_create , 26.Nm rpc_createerr 27.Nd "library routines for dealing with creation and manipulation of" 28.Vt CLIENT 29handles 30.Sh LIBRARY 31.Lb libc 32.Sh SYNOPSIS 33.In rpc/rpc.h 34.Ft bool_t 35.Fn clnt_control "CLIENT *clnt" "const u_int req" "char *info" 36.Ft "CLIENT *" 37.Fn clnt_create "const char * host" "const rpcprog_t prognum" "const rpcvers_t versnum" "const char *nettype" 38.Ft "CLIENT *" 39.Fn clnt_create_timed "const char * host" "const rpcprog_t prognum" "const rpcvers_t versnum" "const char *nettype" "const struct timeval *timeout" 40.Ft "CLIENT *" 41.Fn clnt_create_vers "const char * host" "const rpcprog_t prognum" "rpcvers_t *vers_outp" "const rpcvers_t vers_low" "const rpcvers_t vers_high" "const char *nettype" 42.Ft "CLIENT *" 43.Fn clnt_create_vers_timed "const char * host" "const rpcprog_t prognum" "rpcvers_t *vers_outp" "const rpcvers_t vers_low" "const rpcvers_t vers_high" "char *nettype" "const struct timeval *timeout" 44.Ft void 45.Fn clnt_destroy "CLIENT *clnt" 46.Ft "CLIENT *" 47.Fn clnt_dg_create "const int fildes" "const struct netbuf *svcaddr" "const rpcprog_t prognum" "const rpcvers_t versnum" "const u_int sendsz" "const u_int recvsz" 48.Ft void 49.Fn clnt_pcreateerror "const char *s" 50.Ft "char *" 51.Fn clnt_spcreateerror "const char *s" 52.Ft "CLIENT *" 53.Fn clnt_raw_create "const rpcprog_t prognum" "const rpcvers_t versnum" 54.Ft "CLIENT *" 55.Fn clnt_tli_create "const int fildes" "const struct netconfig *netconf" "const struct netbuf *svcaddr" "const rpcprog_t prognum" "const rpcvers_t versnum" "const u_int sendsz" "const u_int recvsz" 56.Ft "CLIENT *" 57.Fn clnt_tp_create "const char * host" "const rpcprog_t prognum" "const rpcvers_t versnum" "const struct netconfig *netconf" 58.Ft "CLIENT *" 59.Fn clnt_tp_create_timed "const char * host" "const rpcprog_t prognum" "const rpcvers_t versnum" "const struct netconfig *netconf" "const struct timeval *timeout" 60.Ft "CLIENT *" 61.Fn clnt_vc_create "const int fildes" "const struct netbuf *svcaddr" "const rpcprog_t prognum" "const rpcvers_t versnum" "u_int sendsz" "u_int recvsz" 62.Sh DESCRIPTION 63RPC library routines allow C language programs to make procedure 64calls on other machines across the network. 65First a 66.Vt CLIENT 67handle is created and then the client calls a procedure to send a 68request to the server. 69On receipt of the request, the server calls a dispatch routine 70to perform the requested service, and then sends a reply. 71.Sh Routines 72.Bl -tag -width YYYYYYY 73.It Fn clnt_control 74A function macro to change or retrieve various information 75about a client object. 76.Fa req 77indicates the type of operation, and 78.Fa info 79is a pointer to the information. 80For both connectionless and connection-oriented transports, 81the supported values of 82.Fa req 83and their argument types and what they do are: 84.Bl -column "CLSET_FD_NCLOSE" "struct timeval *" "set total timeout" 85.It Dv CLSET_TIMEOUT Ta "struct timeval *" Ta "set total timeout" 86.It Dv CLGET_TIMEOUT Ta "struct timeval *" Ta "get total timeout" 87.El 88.Pp 89Note: 90if you set the timeout using 91.Fn clnt_control , 92the timeout argument passed by 93.Fn clnt_call 94is ignored in all subsequent calls. 95.Pp 96Note: 97If you set the timeout value to 0, 98.Fn clnt_control 99immediately returns an error 100.Pq Dv RPC_TIMEDOUT . 101Set the timeout parameter to 0 for batching calls. 102.Bl -column CLSET_FD_NCLOSE "struct timeval *" "do not close fd on destroy" 103.It Dv CLGET_SVC_ADDR Ta "struct netbuf *" Ta "get servers address" 104.It Dv CLGET_FD Ta "int *" Ta "get fd from handle" 105.It Dv CLSET_FD_CLOSE Ta "void" Ta "close fd on destroy" 106.It Dv CLSET_FD_NCLOSE Ta void Ta "don't close fd on destroy" 107.It Dv CLGET_VERS Ta "unsigned long *" Ta "get RPC program version" 108.It Dv CLSET_VERS Ta "unsigned long *" Ta "set RPC program version" 109.It Dv CLGET_XID Ta "unsigned long *" Ta "get XID of previous call" 110.It Dv CLSET_XID Ta "unsigned long *" Ta "set XID of next call" 111.El 112.Pp 113The following operations are valid for connectionless transports only: 114.Bl -column CLSET_RETRY_TIMEOUT "struct timeval *" "set total timeout" 115.It Dv CLSET_RETRY_TIMEOUT Ta "struct timeval *" Ta "set the retry timeout" 116.It Dv CLGET_RETRY_TIMEOUT Ta "struct timeval *" Ta "get the retry timeout" 117.It Dv CLSET_CONNECT Ta Vt "int *" Ta use Xr connect 2 118.El 119.Pp 120The retry timeout is the time that RPC 121waits for the server to reply before retransmitting the request. 122.Fn clnt_control 123returns 124.Dv TRUE 125on success and 126.Dv FALSE 127on failure. 128.It Fn clnt_create 129Generic client creation routine for program 130.Fa prognum 131and version 132.Fa versnum . 133.Fa host 134identifies the name of the remote host where the server 135is located. 136.Fa nettype 137indicates the class of transport protocol to use. 138The transports are tried in left to right order in 139.Ev NETPATH 140environment variable or in top to bottom order in 141the netconfig database. 142.Fn clnt_create 143tries all the transports of the 144.Fa nettype 145class available from the 146.Ev NETPATH 147environment variable and the netconfig database, 148and chooses the first successful one. 149A default timeout is set and can be modified using 150.Fn clnt_control . 151This routine returns 152.Dv NULL 153if it fails. 154The 155.Fn clnt_pcreateerror 156routine can be used to print the reason for failure. 157.Pp 158Note: 159.Fn clnt_create 160returns a valid client handle even 161if the particular version number supplied to 162.Fn clnt_create 163is not registered with the 164.Xr rpcbind 8 165service. 166This mismatch will be discovered by a 167.Fn clnt_call 168later (see 169.Xr rpc_clnt_calls 3 ) . 170.It Fn clnt_create_timed 171Generic client creation routine which is similar to 172.Fn clnt_create 173but which also has the additional parameter 174.Fa timeout 175that specifies the maximum amount of time allowed for 176each transport class tried. 177In all other respects, the 178.Fn clnt_create_timed 179call behaves exactly like the 180.Fn clnt_create 181call. 182.It Fn clnt_create_vers 183Generic client creation routine which is similar to 184.Fn clnt_create 185but which also checks for the 186version availability. 187.Fa host 188identifies the name of the remote host where the server 189is located. 190.Fa nettype 191indicates the class transport protocols to be used. 192If the routine is successful it returns a client handle created for 193the highest version between 194.Fa vers_low 195and 196.Fa vers_high 197that is supported by the server. 198.Fa vers_outp 199is set to this value. 200That is, after a successful return 201.Fa vers_low 202<= 203.Fa *vers_outp 204<= 205.Fa vers_high . 206If no version between 207.Fa vers_low 208and 209.Fa vers_high 210is supported by the server then the routine fails and returns 211.Dv NULL . 212A default timeout is set and can be modified using 213.Fn clnt_control . 214This routine returns 215.Dv NULL 216if it fails. 217The 218.Fn clnt_pcreateerror 219routine can be used to print the reason for failure. 220Note: 221.Fn clnt_create 222returns a valid client handle even 223if the particular version number supplied to 224.Fn clnt_create 225is not registered with the 226.Xr rpcbind 8 227service. 228This mismatch will be discovered by a 229.Fn clnt_call 230later (see 231.Xr rpc_clnt_calls 3 ) . 232However, 233.Fn clnt_create_vers 234does this for you and returns a valid handle 235only if a version within 236the range supplied is supported by the server. 237.It Fn clnt_create_vers_timed 238Generic client creation routine which is similar to 239.Fn clnt_create_vers 240but which also has the additional parameter 241.Fa timeout 242that specifies the maximum amount of time allowed for 243each transport class tried. 244In all other respects, the 245.Fn clnt_create_vers_timed 246call behaves exactly like the 247.Fn clnt_create_vers 248call. 249.It Fn clnt_destroy 250A function macro that destroys the client's RPC handle. 251Destruction usually involves deallocation 252of private data structures, including 253.Fa clnt 254itself. 255Use of 256.Fa clnt 257is undefined after calling 258.Fn clnt_destroy . 259If the RPC library opened the associated file descriptor, or 260.Dv CLSET_FD_CLOSE 261was set using 262.Fn clnt_control , 263the file descriptor will be closed. 264The caller should call 265.Fn auth_destroy "clnt->cl_auth" 266(before calling 267.Fn clnt_destroy ) 268to destroy the associated 269.Vt AUTH 270structure (see 271.Xr rpc_clnt_auth 3 ) . 272.It Fn clnt_dg_create 273This routine creates an RPC client for the remote program 274.Fa prognum 275and version 276.Fa versnum ; 277the client uses a connectionless transport. 278The remote program is located at address 279.Fa svcaddr . 280The parameter 281.Fa fildes 282is an open and bound file descriptor. 283This routine will resend the call message in intervals of 28415 seconds until a response is received or until the 285call times out. 286The total time for the call to time out is specified by 287.Fn clnt_call 288(see 289.Fn clnt_call 290in 291.Xr rpc_clnt_calls 3 ) . 292The retry time out and the total time out periods can 293be changed using 294.Fn clnt_control . 295The user may set the size of the send and receive 296buffers with the parameters 297.Fa sendsz 298and 299.Fa recvsz ; 300values of 0 choose suitable defaults. 301This routine returns 302.Dv NULL 303if it fails. 304.It Fn clnt_pcreateerror 305Print a message to standard error indicating 306why a client RPC handle could not be created. 307The message is prepended with the string 308.Fa s 309and a colon, and appended with a newline. 310.It Fn clnt_spcreateerror 311Like 312.Fn clnt_pcreateerror , 313except that it returns a string 314instead of printing to the standard error. 315A newline is not appended to the message in this case. 316Warning: 317returns a pointer to a buffer that is overwritten 318on each call. 319.It Fn clnt_raw_create 320This routine creates an RPC 321client handle for the remote program 322.Fa prognum 323and version 324.Fa versnum . 325The transport used to pass messages to the service is 326a buffer within the process's address space, 327so the corresponding RPC 328server should live in the same address space; 329(see 330.Fn svc_raw_create 331in 332.Xr rpc_svc_create 3 ) . 333This allows simulation of RPC and measurement of 334RPC overheads, such as round trip times, 335without any kernel or networking interference. 336This routine returns 337.Dv NULL 338if it fails. 339.Fn clnt_raw_create 340should be called after 341.Fn svc_raw_create . 342.It Fn clnt_tli_create 343This routine creates an RPC 344client handle for the remote program 345.Fa prognum 346and version 347.Fa versnum . 348The remote program is located at address 349.Fa svcaddr . 350If 351.Fa svcaddr 352is 353.Dv NULL 354and it is connection-oriented, it is assumed that the file descriptor 355is connected. 356For connectionless transports, if 357.Fa svcaddr 358is 359.Dv NULL , 360.Dv RPC_UNKNOWNADDR 361error is set. 362.Fa fildes 363is a file descriptor which may be open, bound and connected. 364If it is 365.Dv RPC_ANYFD , 366it opens a file descriptor on the transport specified by 367.Fa netconf . 368If 369.Fa fildes 370is 371.Dv RPC_ANYFD 372and 373.Fa netconf 374is 375.Dv NULL , 376a 377.Dv RPC_UNKNOWNPROTO 378error is set. 379If 380.Fa fildes 381is unbound, then it will attempt to bind the descriptor. 382The user may specify the size of the buffers with the parameters 383.Fa sendsz 384and 385.Fa recvsz ; 386values of 0 choose suitable defaults. 387Depending upon the type of the transport (connection-oriented 388or connectionless), 389.Fn clnt_tli_create 390calls appropriate client creation routines. 391This routine returns 392.Dv NULL 393if it fails. 394The 395.Fn clnt_pcreateerror 396routine can be used to print the reason for failure. 397The remote rpcbind 398service (see 399.Xr rpcbind 8 ) 400is not consulted for the address of the remote 401service. 402.It Fn clnt_tp_create 403Like 404.Fn clnt_create 405except 406.Fn clnt_tp_create 407tries only one transport specified through 408.Fa netconf . 409.Fn clnt_tp_create 410creates a client handle for the program 411.Fa prognum , 412the version 413.Fa versnum , 414and for the transport specified by 415.Fa netconf . 416Default options are set, 417which can be changed using 418.Fn clnt_control 419calls. 420The remote rpcbind service on the host 421.Fa host 422is consulted for the address of the remote service. 423This routine returns 424.Dv NULL 425if it fails. 426The 427.Fn clnt_pcreateerror 428routine can be used to print the reason for failure. 429.It Fn clnt_tp_create_timed 430Like 431.Fn clnt_tp_create 432except 433.Fn clnt_tp_create_timed 434has the extra parameter 435.Fa timeout 436which specifies the maximum time allowed for 437for the creation attempt to succeed. 438In all other respects, the 439.Fn clnt_tp_create_timed 440call behaves exactly like the 441.Fn clnt_tp_create 442call. 443.It Fn clnt_vc_create 444This routine creates an RPC 445client for the remote program 446.Fa prognum 447and version 448.Fa versnum ; 449the client uses a connection-oriented transport. 450The remote program is located at address 451.Fa svcaddr . 452The parameter 453.Fa fildes 454is an open and bound file descriptor. 455The user may specify the size of the send and receive buffers 456with the parameters 457.Fa sendsz 458and 459.Fa recvsz ; 460values of 0 choose suitable defaults. 461This routine returns 462.Dv NULL 463if it fails. 464The address 465.Fa svcaddr 466should not be 467.Dv NULL 468and should point to the actual address of the remote program. 469.Fn clnt_vc_create 470does not consult the remote rpcbind service for this information. 471.It Xo 472.Vt "struct rpc_createerr" Va rpc_createerr ; 473.Xc 474A global variable whose value is set by any RPC 475client handle creation routine 476that fails. 477It is used by the routine 478.Fn clnt_pcreateerror 479to print the reason for the failure. 480.El 481.Sh SEE ALSO 482.Xr rpc 3 , 483.Xr rpc_clnt_auth 3 , 484.Xr rpc_clnt_calls 3 , 485.Xr rpcbind 8 486