RPC_CLNT_CREATE(3)
β¨ RPC_CLNT_CREATE(3) β¨
okay bestie, gather round π«Ά this is the manual page for rpc_clnt_create, clnt_control, clnt_create, and basically the whole squad of functions that handle creating and manipulating CLIENT handles. it's giving "networking but make it cute" π
and it's long, so this is part 1 of 2. more coming, don't go anywhere.
πΈ NAME πΈ
rpc_clnt_createclnt_controlclnt_createclnt_create_timedclnt_create_versclnt_create_vers_timedclnt_destroyclnt_dg_createclnt_pcreateerrorclnt_raw_createclnt_spcreateerrorclnt_tli_createclnt_tp_createclnt_tp_create_timedclnt_vc_createrpc_createerr
β library routines for dealing with creation and manipulation of CLIENT handles. periodt. π
π¦ SYNOPSIS π¦
#include <rpc/rpc.h>
bool_t
clnt_control(CLIENT *clnt, const u_int req, char *info);
CLIENT *
clnt_create(const char * host, const rpcprog_t prognum,
const rpcvers_t versnum, const char *nettype);
CLIENT *
clnt_create_timed(const char * host, const rpcprog_t prognum,
const rpcvers_t versnum, const char *nettype,
const struct timeval *timeout);
CLIENT *
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);
CLIENT *
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);
void
clnt_destroy(CLIENT *clnt);
CLIENT *
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);
void
clnt_pcreateerror(const char *s);
char *
clnt_spcreateerror(const char *s);
CLIENT *
clnt_raw_create(const rpcprog_t prognum, const rpcvers_t versnum);
CLIENT *
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);
CLIENT *
clnt_tp_create(const char * host, const rpcprog_t prognum,
const rpcvers_t versnum, const struct netconfig *netconf);
CLIENT *
clnt_tp_create_timed(const char * host, const rpcprog_t prognum,
const rpcvers_t versnum, const struct netconfig *netconf,
const struct timeval *timeout);
CLIENT *
clnt_vc_create(const int fildes, const struct netbuf *svcaddr,
const rpcprog_t prognum, const rpcvers_t versnum, u_int sendsz,
u_int recvsz);
π DESCRIPTION π
RPC library routines let your C programs make procedure calls on other machines across the network. the whole vibe is: first you create a CLIENT handle, then your client calls a procedure to send a request to the server. when the server gets that request, it calls a dispatch routine to do the requested service, and then sends a reply back. it's a whole conversation, fr fr. π
π§ Routines π§
clnt_control()
a function macro that changes or retrieves various info about a client object. the req argument says what type of operation you want, and info is a pointer to the information. for both connectionless and connection-oriented transports, the supported values of req, their argument types, and what they do are:
CLSET_TIMEOUTβstruct timeval *β set total timeoutCLGET_TIMEOUTβstruct timeval *β get total timeout
Note: if you set the timeout usingclnt_control(), the timeout argument passed byclnt_call()is ignored in all subsequent calls.
Note: If you set the timeout value to0,clnt_control()immediately returns an error (RPC_TIMEDOUT). Set the timeout argument to0for batching calls.
CLGET_SVC_ADDRβstruct netbuf *β get servers addressCLGET_FDβint *β get fd from handleCLSET_FD_CLOSEβvoidβ close fd on destroyCLSET_FD_NCLOSEβvoidβ don't close fd on destroyCLGET_VERSβu_int32_t *β get RPC program versionCLSET_VERSβu_int32_t *β set RPC program versionCLGET_XIDβu_int32_t *β get XID of previous callCLSET_XIDβu_int32_t *β set XID of next call
the following operations are valid for connectionless transports only:
CLSET_RETRY_TIMEOUTβstruct timeval *β set the retry timeoutCLGET_RETRY_TIMEOUTβstruct timeval *β get the retry timeoutCLSET_CONNECTβint *β useconnect(2)
the retry timeout is the time that RPC waits for the server to reply before retransmitting the request. the clnt_control() function returns TRUE on success and FALSE on failure. π
clnt_create()
generic client creation routine for program prognum and version versnum. the host argument identifies the name of the remote host where the server is located. the nettype argument indicates the class of transport protocol to use. the transports are tried in left to right order in the NETPATH environment variable or in top to bottom order in the netconfig database. the clnt_create() function tries all the transports of the nettype class available from the NETPATH environment variable and the netconfig database, and chooses the first successful one. a default timeout is set and can be modified using clnt_control(). this routine returns NULL if it fails. the clnt_pcreateerror() routine can be used to print the reason for failure. π
Note:clnt_create()returns a valid client handle even if the particular version number supplied toclnt_create()is not registered with therpcbind(8)service. This mismatch will be discovered by aclnt_call()later (seerpc_clnt_calls(3)).
clnt_create_timed()
generic client creation routine which is similar to clnt_create() but which also has the additional argument timeout that specifies the maximum amount of time allowed for each transport class tried. in all other respects, the clnt_create_timed() call behaves exactly like the clnt_create() call. β°
clnt_create_vers()
generic client creation routine which is similar to clnt_create() but which also checks for the version availability. the host argument identifies the name of the remote host where the server is located. the nettype argument indicates the class transport protocols to be used. if the routine is successful it returns a client handle created for the highest version between vers_low and vers_high that is supported by the server. the vers_outp argument is set to this value. that is, after a successful return vers_low <= *vers_outp <= vers_high. if no version between vers_low and vers_high is supported by the server then the routine fails and returns NULL. a default timeout is set and can be modified using clnt_control(). this routine returns NULL if it fails. the clnt_pcreateerror() routine can be used to print the reason for failure. Note: clnt_create() returns a valid client handle even if the particular version number supplied to clnt_create() is not registered with the rpcbind(8) service. This mismatch will be discovered by a clnt_call() later (see rpc_clnt_calls(3)). However, clnt_create_vers() does this for you and returns a valid handle only if a version within the range supplied is supported by the server. π
clnt_create_vers_timed()
generic client creation routine which is similar to clnt_create_vers() but which also has the additional argument timeout that specifies the maximum amount of time allowed for each transport class tried. in all other respects, the clnt_create_vers_timed() call behaves exactly like the clnt_create_vers() call. π
clnt_destroy()
a function macro that destroys the client's RPC handle. destruction usually involves deallocation of private data structures, including clnt itself. use of clnt is undefined after calling clnt_destroy(). if the RPC library opened the associated file descriptor, or CLSET_FD_CLOSE was set using clnt_control(), the file descriptor will be closed. the caller should call auth_destroy(clnt->cl_auth) (before calling clnt_destroy()) to destroy the associated AUTH structure (see rpc_clnt_auth(3)). π«Ά
clnt_dg_create()
this routine creates an RPC client for the remote program prognum and version versnum; the client uses a connectionless transport. the remote program is located at address svcaddr. the fildes argument is an open and bound file descriptor. this routine will resend the call message in intervals of 15 seconds until a response is received or until the call times out. the total time for the call to time out is specified by clnt_call() (see clnt_call() in rpc_clnt_calls(3)). the retry time out and the total time out periods can be changed using clnt_control(). the user may set the size of the send and receive buffers with the sendsz and recvsz arguments; values of 0 choose suitable defaults. this routine returns NULL if it fails. π
clnt_pcreateerror()
print a message to standard error indicating why a client RPC handle could not be created. the message is prepended with the string s and a colon, and appended with a newline. π
clnt_spcreateerror()
like clnt_pcreateerror(), except that it returns a string instead of printing to the standard error. a newline is not appended to the message in this case. Warning: returns a pointer to a buffer that is overwritten on each call. β οΈ
β¨ clnt_raw_create() β¨
Okay so this one is so cute, it makes an RPC client handle for the remote program prognum and version versnum β but the transport it uses to pass messages to the service is literally a buffer inside your own process's address space π«§ which means the matching RPC server has to live in the same address space, no exceptions. (peep svc_raw_create() over in rpc_svc_create(3) π
)
Why would you want that? Because it lets you simulate RPC and measure RPC overheads β round trip times and everything β with zero kernel or networking interference. Pure vibes. Immaculate testing conditions. π§ͺβ¨
It returns NULL if it fails. And bestie, listen: clnt_raw_create() should be called after svc_raw_create(). Order matters, don't skip it. π
πΈ clnt_tli_create() πΈ
This routine creates an RPC client handle for the remote program prognum and version versnum, and the remote program is located at address svcaddr. Let's break it down because there are a lot of little rules here:
- If
svcaddrisNULLand it's connection-oriented, it's assumed that the file descriptor is already connected. - For connectionless transports, if
svcaddrisNULL, theRPC_UNKNOWNADDRerror is set. π - The
fildesargument is a file descriptor which may be open, bound and connected. - If it's
RPC_ANYFD, it opens a file descriptor on the transport specified bynetconf. - If
fildesisRPC_ANYFDandnetconfisNULL, theRPC_UNKNOWNPROTOerror gets set. π - If
fildesis unbound, then it will attempt to bind the descriptor. - You can specify the size of the buffers with the
sendszandrecvszarguments, and values of0choose suitable defaults. (defaults ate, fr fr π )
Depending on the type of the transport (connection-oriented or connectionless), clnt_tli_create() calls the appropriate client creation routines. It returns NULL if it fails, and the clnt_pcreateerror() routine can be used to print the reason for failure β highly recommend, otherwise you're just staring at NULL like ποΈπποΈ
Heads up: the remoterpcbindservice (seerpcbind(8)) is not consulted for the address of the remote service. You're on your own for that address, bestie.
π clnt_tp_create() π
Like clnt_create() except clnt_tp_create() tries only one transport, specified through netconf. One transport. Monogamy. π
The clnt_tp_create() function creates a client handle for the program prognum, the version versnum, and for the transport specified by netconf. Default options are set, which can be changed using clnt_control() calls.
Unlike the previous one, the remote rpcbind service on the host host is consulted for the address of the remote service. π
This routine returns NULL if it fails, and the clnt_pcreateerror() routine can be used to print the reason for failure.
β clnt_tp_create_timed() β
Like clnt_tp_create() except clnt_tp_create_timed() has the extra argument timeout, which specifies the maximum time allowed for the creation attempt to succeed. Clock's ticking, bestie β°
In all other respects, the clnt_tp_create_timed() call behaves exactly like the clnt_tp_create() call. No cap.
π¦ clnt_vc_create() π¦
This routine creates an RPC client for the remote program prognum and version versnum, and the client uses a connection-oriented transport. π
The remote program is located at address svcaddr. The fildes argument is an open and bound file descriptor. You may specify the size of the send and receive buffers with the sendsz and recvsz arguments, and values of 0 choose suitable defaults.
This routine returns NULL if it fails.
Real talk: the addresssvcaddrshould not beNULLand should point to the actual address of the remote program. Andclnt_vc_create()does not consult the remoterpcbindservice for this information. You brought the address, you own the address. π«Ά
π struct rpc_createerr rpc_createerr; π
A global variable whose value is set by any RPC client handle creation routine that fails. π
It is used by the routine clnt_pcreateerror() to print the reason for the failure. So when everything's going wrong and you're like "why π", this is the little guy holding the receipts.
β¨ AVAILABILITY β¨
These functions are part of libtirpc. π
πΈ SEE ALSO πΈ
And that's the whole page, bestie!! π This one came from the Debian crew, dated May 7, 1993 (yes, 1993, our vintage icon π), filed under RPC_CLNT_CREATE(3). Go make some client handles, you've got this. πβ¨
π¦ where this page comes from
- alpine 3.22: libtirpc-doc 1.3.5-r0 Β· BSD-3-Clause
- alpine 3.23: libtirpc-doc 1.3.5-r1 Β· BSD-3-Clause
- alpine 3.24: libtirpc-doc 1.3.5-r1 Β· BSD-3-Clause
- arch rolling: libtirpc 1.3.8-1 Β· SISSL AND BSD-3-Clause
- centos-stream 10: libtirpc-devel 1.3.5-1.el10 Β· SISSL AND BSD-3-Clause
- centos-stream 9: libtirpc-devel 1.3.3-9.el9 Β· SISSL and BSD
- centos-stream 9: libtirpc-devel 1.3.3-9.el9 Β· SISSL and BSD
- debian bookworm: libtirpc-dev 1.3.3+ds-1 Β· BSD-3-Clause
- debian trixie: libtirpc-dev 1.3.6+ds-1 Β· BSD-3-Clause
- fedora 43: libtirpc-devel 1.3.7-0.fc43 Β· SISSL AND BSD-3-Clause
- fedora 43: libtirpc-devel 1.3.7-0.fc43 Β· SISSL AND BSD-3-Clause
- fedora 43: libtirpc-devel 1.3.7-1.rc1.fc43 Β· SISSL AND BSD-3-Clause
- fedora 43: libtirpc-devel 1.3.7-1.rc1.fc43 Β· SISSL AND BSD-3-Clause
- fedora 44: libtirpc-devel 1.3.7-2.fc44 Β· SISSL AND BSD-3-Clause
- fedora 44: libtirpc-devel 1.3.7-2.fc44 Β· SISSL AND BSD-3-Clause
- fedora 44: libtirpc-devel 1.3.8-0.fc44 Β· SISSL AND BSD-3-Clause
- fedora 44: libtirpc-devel 1.3.8-0.fc44 Β· SISSL AND BSD-3-Clause
- nixos 26.05: libtirpc 1.3.7
- nixpkgs unstable: libtirpc 1.3.7
- opensuse-leap 16.0: libtirpc-devel 1.3.6-160000.2.2 Β· BSD-3-Clause
- opensuse-leap 16.0: libtirpc-devel 1.3.6-160000.2.2 Β· BSD-3-Clause
- opensuse-leap 16.0: libtirpc-devel 1.3.6-160000.2.2 Β· BSD-3-Clause
- opensuse-leap 16.0: libtirpc-devel 1.3.6-160000.2.2 Β· BSD-3-Clause
- ubuntu jammy: libtirpc-dev 1.3.2-2build1 Β· BSD-3-Clause
- ubuntu jammy: libtirpc-dev 1.3.2-2ubuntu0.1 Β· BSD-3-Clause
- ubuntu noble: libtirpc-dev 1.3.4+ds-1.1build1 Β· BSD-3-Clause
- ubuntu questing: libtirpc-dev 1.3.6+ds-1
- ubuntu resolute: libtirpc-dev 1.3.7-0.1 Β· BSD-3-Clause
- ubuntu stonking: libtirpc-dev 1.3.7+ds-1 Β· BSD-3-Clause
- Copyright 1989 AT&T
- Copyright (c) 1988 Sun Microsystems, Inc. - All Rights Reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms