2 .\" Copyright 2014 Nexenta Systems, Inc. All Rights Reserved.
3 .\" Copyright (c) 2000, Sun Microsystems, Inc. All Rights Reserved
4 .\" Copyright 1989 AT&T
5 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
6 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
7 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
8 .TH RPC 3NSL "Nov 24, 2014"
10 rpc \- library routines for remote procedure calls
14 \fBcc\fR [ \fIflag\fR ... ] \fIfile\fR ... \fB-lnsl\fR [ \fIlibrary\fR ... ]
16 #include <netconfig.h>
21 These routines allow C language programs to make procedure calls on other
22 machines across a network. First, the client sends a request to the server. On
23 receipt of the request, the server calls a dispatch routine to perform the
24 requested service, and then sends back a reply.
27 All \fBRPC\fR routines require the header \fB<rpc/rpc.h>\fR\&. Routines that
28 take a \fBnetconfig\fR structure also require that \fB<netconfig.h>\fR be
29 included. Applications using \fBRPC\fR and \fBXDR\fR routines should be
30 linked with the \fBlibnsl\fR library.
31 .SS "Multithread Considerations"
33 In the case of multithreaded applications, the \fB-mt\fR option must be
34 specified on the command line at compilation time to enable a thread-specific
35 version of \fBrpc_createerr()\fR. See \fBrpc_clnt_create\fR(3NSL) and
39 When used in multithreaded applications, client-side routines are MT-Safe.
40 \fBCLIENT\fR handles can be shared between threads; however, in this
41 implementation, requests by different threads are serialized (that is, the
42 first request will receive its results before the second request is sent). See
43 \fBrpc_clnt_create\fR(3NSL).
46 When used in multithreaded applications, server-side routines are usually
47 Unsafe. In this implementation the service transport handle, \fBSVCXPRT\fR
48 contains a single data area for decoding arguments and encoding results. See
49 \fBrpc_svc_create\fR(3NSL). Therefore, this structure cannot be freely shared
50 between threads that call functions that do this. Routines that are affected
51 by this restriction are marked as unsafe for MT applications. See
52 \fBrpc_svc_calls\fR(3NSL).
55 Some of the high-level \fBRPC\fR interface routines take a \fInettype\fR string
56 as one of the parameters (for example, \fBclnt_create()\fR, \fBsvc_create()\fR,
57 \fBrpc_reg()\fR, \fBrpc_call()\fR). This string defines a class of transports
58 which can be used for a particular application.
61 \fInettype\fR can be one of the following:
68 Choose from the transports which have been indicated by their token names in
69 the \fBNETPATH\fR environment variable. If \fBNETPATH\fR is unset or
70 \fINULL\fR, it defaults to \fBvisible\fR. \fBnetpath\fR is the default
80 Choose the transports which have the visible flag (\fBv\fR) set in the
81 \fB/etc/netconfig\fR file.
90 This is same as \fBvisible\fR except that it chooses only the connection
91 oriented transports (semantics \fBtpi_cots\fR or \fBtpi_cots_ord\fR) from the
92 entries in the \fB/etc/netconfig\fR file.
98 \fB\fBdatagram_v\fR\fR
101 This is same as \fBvisible\fR except that it chooses only the connectionless
102 datagram transports (semantics \fBtpi_clts\fR) from the entries in the
103 \fB/etc/netconfig\fR file.
109 \fB\fBcircuit_n\fR\fR
112 This is same as \fBnetpath\fR except that it chooses only the connection
113 oriented datagram transports (semantics \fBtpi_cots\fR or \fBtpi_cots_ord\fR).
119 \fB\fBdatagram_n\fR\fR
122 This is same as \fBnetpath\fR except that it chooses only the connectionless
123 datagram transports (semantics \fBtpi_clts\fR).
132 This refers to Internet \fBUDP.\fR
141 This refers to Internet \fBTCP.\fR
146 If \fInettype\fR is \fINULL\fR, it defaults to \fBnetpath\fR. The transports
147 are tried in left to right order in the \fBNETPATH\fR variable or in top to
148 down order in the \fB/etc/netconfig\fR file.
151 In a 64-bit environment, the derived types are defined as follows:
158 \fBtypedef\fR \fBuint32_t\fR \fBrpcprog_t;\fR
159 \fBtypedef\fR \fBuint32_t\fR \fBrpcvers_t;\fR
160 \fBtypedef\fR \fBuint32_t\fR \fBrpcproc_t;\fR
161 \fBtypedef\fR \fBuint32_t\fR \fBrpcprot_t;\fR
162 \fBtypedef\fR \fBuint32_t\fR \fBrpcport_t;\fR
163 \fBtypedef\fR \fBint32_t\fR \fBrpc_inline_t;\fR
168 In a 32-bit environment, the derived types are defined as follows:
175 \fBtypedef\fR \fBunsigned long\fR \fBrpcprog_t;\fR
176 \fBtypedef\fR \fBunsigned long\fR \fBrpcvers_t;\fR
177 \fBtypedef\fR \fBunsigned long\fR \fBrpcproc_t;\fR
178 \fBtypedef\fR \fBunsigned long\fR \fBrpcprot_t;\fR
179 \fBtypedef\fR \fBunsigned long\fR \fBrpcport_t;\fR
180 \fBtypedef\fR \fBlong\fR \fBrpc_inline_t;\fR
183 .SS "Data Structures"
185 Some of the data structures used by the \fBRPC\fR package are shown below.
186 .SS "The \fBAUTH\fR Structure"
196 typedef union des_block des_block;
197 extern bool_t xdr_des_block(\|);
199 * Authentication info. Opaque to client.
202 enum_t oa_flavor; /* flavor of auth */
203 caddr_t oa_base; /* address of more auth stuff */
204 uint_t oa_length; /* not to exceed MAX_AUTH_BYTES */
207 * Auth handle, interface to client side authenticators.
210 struct opaque_auth ah_cred;
211 struct opaque_auth ah_verf;
212 union des_block ah_key;
214 void(*ah_nextverf)(\|);
215 int(*ah_marshal)(\|); /* nextverf & serialize */
216 int(*ah_validate)(\|); /* validate verifier */
217 int(*ah_refresh)(\|); /* refresh credentials */
218 void(*ah_destroy)(\|); /* destroy this structure */
225 .SS "The \fBCLIENT\fR Structure"
230 * Created by individual implementations.
231 * Client is responsible for initializing auth.
234 AUTH *cl_auth; /* authenticator */
236 enum clnt_stat (*cl_call)(\|); /* call remote procedure */
237 void (*cl_abort)(\|); /* abort a call */
238 void (*cl_geterr)(\|); /* get specific error code */
239 bool_t (*cl_freeres)(\|); /* frees results */
240 void (*cl_destroy)(\|); /* destroy this structure */
241 bool_t (*cl_control)(\|); /* the ioctl(\|) of rpc */
242 int (*cl_settimers)(\|); /* set rpc level timers */
244 caddr_t cl_private; /* private stuff */
245 char *cl_netid; /* network identifier */
246 char *cl_tp; /* device name */
251 .SS "The \fBSVCXPRT\fR Structure"
260 * Server side transport handle
263 int xp_fd; /* file descriptor for the
264 ushort_t xp_port; /* obsolete */
266 bool_t (*xp_recv)(\|); /* receive incoming requests */
267 enum xprt_stat (*xp_stat)(\|); /* get transport status */
268 bool_t (*xp_getargs)(\|); /* get arguments */
269 bool_t (*xp_reply)(\|); /* send reply */
270 bool_t (*xp_freeargs)(\|); /* free mem allocated
272 void (*xp_destroy)(\|); /* destroy this struct */
274 int xp_addrlen; /* length of remote addr.
276 char *xp_tp; /* transport provider device
278 char *xp_netid; /* network identifier */
279 struct netbuf xp_ltaddr; /* local transport address */
280 struct netbuf xp_rtaddr; /* remote transport address */
281 char xp_raddr[16]; /* remote address. Obsolete */
282 struct opaque_auth xp_verf; /* raw response verifier */
283 caddr_t xp_p1; /* private: for use
285 caddr_t xp_p2; /* private: for use
287 caddr_t xp_p3; /* private: for use
289 int xp_type /* transport type */
294 .SS "The \fBsvc_reg\fR Structure"
298 rpcprog_t rq_prog; /* service program number */
299 rpcvers_t rq_vers; /* service protocol version */
300 rpcproc_t rq_proc; /* the desired procedure */
301 struct opaque_auth rq_cred; /* raw creds from the wire */
302 caddr_t rq_clntcred; /* read only cooked cred */
303 SVCXPRT *rq_xprt; /* associated transport */
309 .SS "The \fBXDR\fR Structure"
314 * XDR_ENCODE causes the type to be encoded into the stream.
315 * XDR_DECODE causes the type to be extracted from the stream.
316 * XDR_FREE can be used to release the space allocated by an XDR_DECODE
325 * This is the number of bytes per unit of external data.
327 #define BYTES_PER_XDR_UNIT (4)
328 #define RNDUP(x) ((((x) + BYTES_PER_XDR_UNIT - 1) /
329 BYTES_PER_XDR_UNIT) \e * BYTES_PER_XDR_UNIT)
331 * A xdrproc_t exists for each data type which is to be encoded or
332 * decoded. The second argument to the xdrproc_t is a pointer to
333 * an opaque pointer. The opaque pointer generally points to a
334 * structure of the data type to be decoded. If this points to 0,
335 * then the type routines should allocate dynamic storage of the
336 * appropriate size and return it.
337 * bool_t (*xdrproc_t)(XDR *, caddr_t *);
339 typedef bool_t (*xdrproc_t)(\|);
342 * Contains operation which is being applied to the stream,
343 * an operations vector for the particular implementation
347 enum xdr_op x_op; /* operation; fast additional param */
350 bool_t (*x_getlong)(\|); /* get long from underlying stream */
351 bool_t (*x_putlong)(\|); /* put long to underlying stream */
352 bool_t (*x_getbytes)(\|); /* get bytes from underlying stream */
353 bool_t (*x_putbytes)(\|); /* put bytes to underlying stream */
354 uint_t (*x_getpostn)(\|); /* returns bytes off from beginning */
355 bool_t (*x_setpostn)(\|); /* reposition the stream */
356 rpc_inline_t *(*x_inline)(\|); /* buf quick ptr to buffered data */
357 void (*x_destroy)(\|); /* free privates of this xdr_stream */
358 bool_t (*x_control)(\|); /* changed/retrieve client object info*/
359 bool_t (*x_getint32)(\|); /* get int from underlying stream */
360 bool_t (*x_putint32)(\|); /* put int to underlying stream */
364 caddr_t x_public; /* users' data */
365 caddr_t x_priv /* pointer to private data */
366 caddr_t x_base; /* private used for position info */
367 int x_handy; /* extra private word */
372 .SS "Index to Routines"
374 The following table lists \fBRPC\fR routines and the manual reference pages on
375 which they are described:
379 \fB\fBRPC Routine\fR\fR
382 \fBManual Reference Page\fR
388 \fB\fBauth_destroy\fR\fR
391 \fBrpc_clnt_auth\fR(3NSL)
397 \fB\fBauthdes_create\fR\fR
406 \fB\fBauthdes_getucred\fR\fR
409 \fBsecure_rpc\fR(3NSL)
415 \fB\fBauthdes_seccreate\fR\fR
418 \fBsecure_rpc\fR(3NSL)
424 \fB\fBauthnone_create\fR\fR
427 \fBrpc_clnt_auth\fR(3NSL)
433 \fB\fBauthsys_create\fR\fR
436 \fBrpc_clnt_auth\fR(3NSL)
442 \fB\fBauthsys_create_default\fR\fR
445 \fBrpc_clnt_auth\fR(3NSL)
451 \fB\fBauthunix_create\fR\fR
460 \fB\fBauthunix_create_default\fR\fR
478 \fB\fBclnt_broadcast\fR\fR
487 \fB\fBclnt_call\fR\fR
490 \fBrpc_clnt_calls\fR(3NSL)
496 \fB\fBclnt_control\fR\fR
499 \fBrpc_clnt_create\fR(3NSL)
505 \fB\fBclnt_create\fR\fR
508 \fBrpc_clnt_create\fR(3NSL)
514 \fB\fBclnt_destroy\fR\fR
517 \fBrpc_clnt_create\fR(3NSL)
523 \fB\fBclnt_dg_create\fR\fR
526 \fBrpc_clnt_create\fR(3NSL)
532 \fB\fBclnt_freeres\fR\fR
535 \fBrpc_clnt_calls\fR(3NSL)
541 \fB\fBclnt_geterr\fR\fR
544 \fBrpc_clnt_calls\fR(3NSL)
550 \fB\fBclnt_pcreateerror\fR\fR
553 \fBrpc_clnt_create\fR(3NSL)
559 \fB\fBclnt_perrno\fR\fR
562 \fBrpc_clnt_calls\fR(3NSL)
568 \fB\fBclnt_perror\fR\fR
571 \fBrpc_clnt_calls\fR(3NSL)
577 \fB\fBclnt_raw_create\fR\fR
580 \fBrpc_clnt_create\fR(3NSL)
586 \fB\fBclnt_spcreateerror\fR\fR
589 \fBrpc_clnt_create\fR(3NSL)
595 \fB\fBclnt_sperrno\fR\fR
598 \fBrpc_clnt_calls\fR(3NSL)
604 \fB\fBclnt_sperror\fR\fR
607 \fBrpc_clnt_calls\fR(3NSL)
613 \fB\fBclnt_tli_create\fR\fR
616 \fBrpc_clnt_create\fR(3NSL)
622 \fB\fBclnt_tp_create\fR\fR
625 \fBrpc_clnt_create\fR(3NSL)
631 \fB\fBclnt_vc_create\fR\fR
634 \fBrpc_clnt_create\fR(3NSL)
640 \fB\fBclntraw_create\fR\fR
649 \fB\fBclnttcp_create\fR\fR
658 \fB\fBclntudp_bufcreate\fR\fR
667 \fB\fBclntudp_create\fR\fR
676 \fB\fBget_myaddress\fR\fR
685 \fB\fBgetnetname\fR\fR
688 \fBsecure_rpc\fR(3NSL)
694 \fB\fBhost2netname\fR\fR
697 \fBsecure_rpc\fR(3NSL)
703 \fB\fBkey_decryptsession\fR\fR
706 \fBsecure_rpc\fR(3NSL)
712 \fB\fBkey_encryptsession\fR\fR
715 \fBsecure_rpc\fR(3NSL)
721 \fB\fBkey_gendes\fR\fR
724 \fBsecure_rpc\fR(3NSL)
730 \fB\fBkey_setsecret\fR\fR
733 \fBsecure_rpc\fR(3NSL)
739 \fB\fBnetname2host\fR\fR
742 \fBsecure_rpc\fR(3NSL)
748 \fB\fBnetname2user\fR\fR
751 \fBsecure_rpc\fR(3NSL)
757 \fB\fBpmap_getmaps\fR\fR
766 \fB\fBpmap_getport\fR\fR
775 \fB\fBpmap_rmtcall\fR\fR
793 \fB\fBpmap_unset\fR\fR
802 \fB\fBregisterrpc\fR\fR
811 \fB\fBrpc_broadcast\fR\fR
814 \fBrpc_clnt_calls\fR(3NSL)
820 \fB\fBrpc_broadcast_exp\fR\fR
823 \fBrpc_clnt_calls\fR(3NSL)
832 \fBrpc_clnt_calls\fR(3NSL)
841 \fBrpc_svc_reg\fR(3NSL)
847 \fB\fBsvc_create\fR\fR
850 \fBrpc_svc_create\fR(3NSL)
856 \fB\fBsvc_destroy\fR\fR
859 \fBrpc_svc_create\fR(3NSL)
865 \fB\fBsvc_dg_create\fR\fR
868 \fBrpc_svc_create\fR(3NSL)
874 \fB\fBsvc_dg_enablecache\fR\fR
877 \fBrpc_svc_calls\fR(3NSL)
883 \fB\fBsvc_fd_create\fR\fR
886 \fBrpc_svc_create\fR(3NSL)
901 \fB\fBsvc_freeargs\fR\fR
904 \fBrpc_svc_calls\fR(3NSL)
910 \fB\fBsvc_getargs\fR\fR
913 \fBrpc_svc_calls\fR(3NSL)
919 \fB\fBsvc_getcaller\fR\fR
928 \fB\fBsvc_getreq\fR\fR
937 \fB\fBsvc_getreqset\fR\fR
940 \fBrpc_svc_calls\fR(3NSL)
946 \fB\fBsvc_getrpccaller\fR\fR
949 \fBrpc_svc_calls\fR(3NSL)
955 \fB\fBsvc_raw_create\fR\fR
958 \fBrpc_svc_create\fR(3NSL)
967 \fBrpc_svc_reg\fR(3NSL)
973 \fB\fBsvc_register\fR\fR
985 \fBrpc_svc_calls\fR(3NSL)
991 \fB\fBsvc_sendreply\fR\fR
994 \fBrpc_svc_calls\fR(3NSL)
1000 \fB\fBsvc_tli_create\fR\fR
1003 \fBrpc_svc_create\fR(3NSL)
1009 \fB\fBsvc_tp_create\fR\fR
1012 \fBrpc_svc_create\fR(3NSL)
1018 \fB\fBsvc_unreg\fR\fR
1021 \fBrpc_svc_reg\fR(3NSL)
1027 \fB\fBsvc_unregister\fR\fR
1036 \fB\fBsvc_vc_create\fR\fR
1039 \fBrpc_svc_create\fR(3NSL)
1045 \fB\fBsvcerr_auth\fR\fR
1048 \fBrpc_svc_err\fR(3NSL)
1054 \fB\fBsvcerr_decode\fR\fR
1057 \fBrpc_svc_err\fR(3NSL)
1063 \fB\fBsvcerr_noproc\fR\fR
1066 \fBrpc_svc_err\fR(3NSL)
1072 \fB\fBsvcerr_noprog\fR\fR
1075 \fBrpc_svc_err\fR(3NSL)
1081 \fB\fBsvcerr_progvers\fR\fR
1084 \fBrpc_svc_err\fR(3NSL)
1090 \fB\fBsvcerr_systemerr\fR\fR
1093 \fBrpc_svc_err\fR(3NSL)
1099 \fB\fBsvcerr_weakauth\fR\fR
1102 \fBrpc_svc_err\fR(3NSL)
1108 \fB\fBsvcfd_create\fR\fR
1117 \fB\fBsvcraw_create\fR\fR
1126 \fB\fBsvctcp_create\fR\fR
1135 \fB\fBsvcudp_bufcreate\fR\fR
1144 \fB\fBsvcudp_create\fR\fR
1153 \fB\fBuser2netname\fR\fR
1156 \fBsecure_rpc\fR(3NSL)
1162 \fB\fBxdr_accepted_reply\fR\fR
1171 \fB\fBxdr_authsys_parms\fR\fR
1180 \fB\fBxdr_authunix_parms\fR\fR
1189 \fB\fBxdr_callhdr\fR\fR
1198 \fB\fBxdr_callmsg\fR\fR
1207 \fB\fBxdr_opaque_auth\fR\fR
1216 \fB\fBxdr_rejected_reply\fR\fR
1225 \fB\fBxdr_replymsg\fR\fR
1234 \fB\fBxprt_register\fR\fR
1237 \fBrpc_svc_reg\fR(3NSL)
1243 \fB\fBxprt_unregister\fR\fR
1246 \fBrpc_svc_reg\fR(3NSL)
1251 \fB/etc/netconfig\fR
1254 See \fBattributes\fR(5) for descriptions of the following attributes:
1262 ATTRIBUTE TYPE ATTRIBUTE VALUE
1264 MT-Level MT-Safe with exceptions
1269 \fBgetnetconfig\fR(3NSL), \fBgetnetpath\fR(3NSL), \fBrpc_clnt_auth\fR(3NSL),
1270 \fBrpc_clnt_calls\fR(3NSL), \fBrpc_clnt_create\fR(3NSL),
1271 \fBrpc_svc_calls\fR(3NSL), \fBrpc_svc_create\fR(3NSL), \fBrpc_svc_err\fR(3NSL),
1272 \fBrpc_svc_reg\fR(3NSL), \fBrpc_xdr\fR(3NSL), \fBrpcbind\fR(3NSL),
1273 \fBsecure_rpc\fR(3NSL), \fBthreads\fR(5), \fBxdr\fR(3NSL), \fBnetconfig\fR(4),
1274 \fBrpc\fR(4), \fBattributes\fR(5), \fBenviron\fR(5)