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_create
  • clnt_control
  • clnt_create
  • clnt_create_timed
  • clnt_create_vers
  • clnt_create_vers_timed
  • clnt_destroy
  • clnt_dg_create
  • clnt_pcreateerror
  • clnt_raw_create
  • clnt_spcreateerror
  • clnt_tli_create
  • clnt_tp_create
  • clnt_tp_create_timed
  • clnt_vc_create
  • rpc_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 timeout
  • CLGET_TIMEOUT β€” struct timeval * β€” get total timeout
Note: if you set the timeout using clnt_control(), the timeout argument passed by clnt_call() is ignored in all subsequent calls.
Note: If you set the timeout value to 0, clnt_control() immediately returns an error (RPC_TIMEDOUT). Set the timeout argument to 0 for batching calls.
  • CLGET_SVC_ADDR β€” struct netbuf * β€” get servers address
  • CLGET_FD β€” int * β€” get fd from handle
  • CLSET_FD_CLOSE β€” void β€” close fd on destroy
  • CLSET_FD_NCLOSE β€” void β€” don't close fd on destroy
  • CLGET_VERS β€” u_int32_t * β€” get RPC program version
  • CLSET_VERS β€” u_int32_t * β€” set RPC program version
  • CLGET_XID β€” u_int32_t * β€” get XID of previous call
  • CLSET_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 timeout
  • CLGET_RETRY_TIMEOUT β€” struct timeval * β€” get the retry timeout
  • CLSET_CONNECT β€” int * β€” use connect(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 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)).

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 svcaddr is NULL and it's connection-oriented, it's assumed that the file descriptor is already connected.
  • For connectionless transports, if svcaddr is NULL, the RPC_UNKNOWNADDR error is set. πŸ™ˆ
  • The fildes argument 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 by netconf.
  • If fildes is RPC_ANYFD and netconf is NULL, the RPC_UNKNOWNPROTO error gets set. 😭
  • If fildes is unbound, then it will attempt to bind the descriptor.
  • You can specify the size of the buffers with the sendsz and recvsz arguments, and values of 0 choose 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 remote rpcbind service (see rpcbind(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 address svcaddr should not be NULL and should point to the actual address of the remote program. And clnt_vc_create() does not consult the remote rpcbind service 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