1 /*        $NetBSD: rpc_msg.h,v 1.15 2006/02/25 00:58:34 wiz Exp $     */
2 
3 /*
4  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
5  * unrestricted use provided that this legend is included on all tape
6  * media and as a part of the software program in whole or part.  Users
7  * may copy or modify Sun RPC without charge, but are not authorized
8  * to license or distribute it to anyone else except as part of a product or
9  * program developed by the user.
10  *
11  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
12  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
13  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
14  *
15  * Sun RPC is provided with no support and without any obligation on the
16  * part of Sun Microsystems, Inc. to assist in its use, correction,
17  * modification or enhancement.
18  *
19  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
20  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
21  * OR ANY PART THEREOF.
22  *
23  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
24  * or profits or other special, indirect and consequential damages, even if
25  * Sun has been advised of the possibility of such damages.
26  *
27  * Sun Microsystems, Inc.
28  * 2550 Garcia Avenue
29  * Mountain View, California  94043
30  *
31  *        from: @(#)rpc_msg.h 1.7 86/07/16 SMI
32  *        @(#)rpc_msg.h       2.1 88/07/29 4.0 RPCSRC
33  */
34 
35 /*
36  * rpc_msg.h
37  * rpc message definition
38  *
39  * Copyright (C) 1984, Sun Microsystems, Inc.
40  */
41 
42 #ifndef _RPC_RPC_MSG_H_
43 #define _RPC_RPC_MSG_H_
44 
45 #define RPC_MSG_VERSION                 ((uint32_t) 2)
46 #define RPC_SERVICE_PORT      ((u_short) 2048)
47 
48 /*
49  * Bottom up definition of an rpc message.
50  * NOTE: call and reply use the same overall struct but
51  * different parts of unions within it.
52  */
53 
54 enum msg_type {
55           CALL=0,
56           REPLY=1
57 };
58 
59 enum reply_stat {
60           MSG_ACCEPTED=0,
61           MSG_DENIED=1
62 };
63 
64 enum accept_stat {
65           SUCCESS=0,
66           PROG_UNAVAIL=1,
67           PROG_MISMATCH=2,
68           PROC_UNAVAIL=3,
69           GARBAGE_ARGS=4,
70           SYSTEM_ERR=5
71 };
72 
73 enum reject_stat {
74           RPC_MISMATCH=0,
75           AUTH_ERROR=1
76 };
77 
78 /*
79  * Reply part of an rpc exchange
80  */
81 
82 /*
83  * Reply to an rpc request that was accepted by the server.
84  * Note: there could be an error even though the request was
85  * accepted.
86  */
87 struct accepted_reply {
88           struct opaque_auth  ar_verf;
89           enum accept_stat    ar_stat;
90           union {
91                     struct {
92                               rpcvers_t low;
93                               rpcvers_t high;
94                     } AR_versions;
95                     struct {
96                               const char *where;
97                               xdrproc_t proc;
98                     } AR_results;
99                     /* and many other null cases */
100           } ru;
101 #define   ar_results          ru.AR_results
102 #define   ar_vers             ru.AR_versions
103 };
104 
105 /*
106  * Reply to an rpc request that was rejected by the server.
107  */
108 struct rejected_reply {
109           enum reject_stat rj_stat;
110           union {
111                     struct {
112                               rpcvers_t low;
113                               rpcvers_t high;
114                     } RJ_versions;
115                     enum auth_stat RJ_why;  /* why authentication did not work */
116           } ru;
117 #define   rj_vers   ru.RJ_versions
118 #define   rj_why    ru.RJ_why
119 };
120 
121 /*
122  * Body of a reply to an rpc request.
123  */
124 struct reply_body {
125           enum reply_stat rp_stat;
126           union {
127                     struct accepted_reply RP_ar;
128                     struct rejected_reply RP_dr;
129           } ru;
130 #define   rp_acpt   ru.RP_ar
131 #define   rp_rjct   ru.RP_dr
132 };
133 
134 /*
135  * Body of an rpc request call.
136  */
137 struct call_body {
138           rpcvers_t cb_rpcvers;         /* must be equal to two */
139           rpcprog_t cb_prog;
140           rpcvers_t cb_vers;
141           rpcproc_t cb_proc;
142           struct opaque_auth cb_cred;
143           struct opaque_auth cb_verf; /* protocol specific - provided by client */
144 };
145 
146 /*
147  * The rpc message
148  */
149 struct rpc_msg {
150           uint32_t            rm_xid;
151           enum msg_type                 rm_direction;
152           union {
153                     struct call_body RM_cmb;
154                     struct reply_body RM_rmb;
155           } ru;
156 #define   rm_call             ru.RM_cmb
157 #define   rm_reply  ru.RM_rmb
158 };
159 #define   acpted_rply         ru.RM_rmb.ru.RP_ar
160 #define   rjcted_rply         ru.RM_rmb.ru.RP_dr
161 
162 __BEGIN_DECLS
163 /*
164  * XDR routine to handle an rpc message.
165  * xdr_callmsg(xdrs, cmsg)
166  *        XDR *xdrs;
167  *        struct rpc_msg *cmsg;
168  */
169 extern bool_t       xdr_callmsg         (XDR *, struct rpc_msg *);
170 
171 /*
172  * XDR routine to pre-serialize the static part of an rpc message.
173  * xdr_callhdr(xdrs, cmsg)
174  *        XDR *xdrs;
175  *        struct rpc_msg *cmsg;
176  */
177 extern bool_t       xdr_callhdr         (XDR *, struct rpc_msg *);
178 
179 /*
180  * XDR routine to handle an rpc reply.
181  * xdr_replymsg(xdrs, rmsg)
182  *        XDR *xdrs;
183  *        struct rpc_msg *rmsg;
184  */
185 extern bool_t       xdr_replymsg        (XDR *, struct rpc_msg *);
186 
187 
188 /*
189  * XDR routine to handle a accepted rpc reply.
190  * xdr_accepted_reply(xdrs, rej)
191  *        XDR *xdrs;
192  *        struct accepted_reply *rej;
193  */
194 extern bool_t       xdr_accepted_reply  (XDR *, struct accepted_reply *);
195 
196 /*
197  * XDR routine to handle a rejected rpc reply.
198  * xdr_rejected_reply(xdrs, rej)
199  *        XDR *xdrs;
200  *        struct rejected_reply *rej;
201  */
202 extern bool_t       xdr_rejected_reply  (XDR *, struct rejected_reply *);
203 
204 /*
205  * Fills in the error part of a reply message.
206  * _seterr_reply(msg, error)
207  *        struct rpc_msg *msg;
208  *        struct rpc_err *error;
209  */
210 extern void         _seterr_reply       (struct rpc_msg *, struct rpc_err *);
211 __END_DECLS
212 
213 #endif /* !_RPC_RPC_MSG_H_ */
214