xdr.c (0cc39166733d7a7eee94bd8aa573237a90d9838e) xdr.c (1ad08a09e9732e9e6e44f069c55f4abe27ed392a)
1/*
2 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
3 * unrestricted use provided that this legend is included on all tape
4 * media and as a part of the software program in whole or part. Users
5 * may copy or modify Sun RPC without charge, but are not authorized
6 * to license or distribute it to anyone else except as part of a product or
7 * program developed by the user.
1/*
2 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
3 * unrestricted use provided that this legend is included on all tape
4 * media and as a part of the software program in whole or part. Users
5 * may copy or modify Sun RPC without charge, but are not authorized
6 * to license or distribute it to anyone else except as part of a product or
7 * program developed by the user.
8 *
8 *
9 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
10 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
11 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
9 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
10 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
11 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
12 *
12 *
13 * Sun RPC is provided with no support and without any obligation on the
14 * part of Sun Microsystems, Inc. to assist in its use, correction,
15 * modification or enhancement.
13 * Sun RPC is provided with no support and without any obligation on the
14 * part of Sun Microsystems, Inc. to assist in its use, correction,
15 * modification or enhancement.
16 *
16 *
17 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
18 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
19 * OR ANY PART THEREOF.
17 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
18 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
19 * OR ANY PART THEREOF.
20 *
20 *
21 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
22 * or profits or other special, indirect and consequential damages, even if
23 * Sun has been advised of the possibility of such damages.
21 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
22 * or profits or other special, indirect and consequential damages, even if
23 * Sun has been advised of the possibility of such damages.
24 *
24 *
25 * Sun Microsystems, Inc.
26 * 2550 Garcia Avenue
27 * Mountain View, California 94043
28 */
29
30#if defined(LIBC_SCCS) && !defined(lint)
31/*static char *sccsid = "from: @(#)xdr.c 1.35 87/08/12";*/
32/*static char *sccsid = "from: @(#)xdr.c 2.1 88/07/29 4.0 RPCSRC";*/
25 * Sun Microsystems, Inc.
26 * 2550 Garcia Avenue
27 * Mountain View, California 94043
28 */
29
30#if defined(LIBC_SCCS) && !defined(lint)
31/*static char *sccsid = "from: @(#)xdr.c 1.35 87/08/12";*/
32/*static char *sccsid = "from: @(#)xdr.c 2.1 88/07/29 4.0 RPCSRC";*/
33static char *rcsid = "$Id: xdr.c,v 1.1 1993/10/27 05:41:06 paul Exp $";
33static char *rcsid = "$Id: xdr.c,v 1.3 1995/10/22 14:53:51 phk Exp $";
34#endif
35
36/*
37 * xdr.c, Generic XDR routines implementation.
38 *
39 * Copyright (C) 1986, Sun Microsystems, Inc.
40 *
41 * These are the "generic" xdr routines used to serialize and de-serialize
42 * most common data items. See xdr.h for more info on the interface to
43 * xdr.
44 */
45
46#include <stdio.h>
34#endif
35
36/*
37 * xdr.c, Generic XDR routines implementation.
38 *
39 * Copyright (C) 1986, Sun Microsystems, Inc.
40 *
41 * These are the "generic" xdr routines used to serialize and de-serialize
42 * most common data items. See xdr.h for more info on the interface to
43 * xdr.
44 */
45
46#include <stdio.h>
47#include <stdlib.h>
48#include <string.h>
47
48#include <rpc/types.h>
49#include <rpc/xdr.h>
50
51/*
52 * constants specific to the xdr "protocol"
53 */
54#define XDR_FALSE ((long) 0)

--- 10 unchanged lines hidden (view full) ---

65 * Not a filter, but a convenient utility nonetheless
66 */
67void
68xdr_free(proc, objp)
69 xdrproc_t proc;
70 char *objp;
71{
72 XDR x;
49
50#include <rpc/types.h>
51#include <rpc/xdr.h>
52
53/*
54 * constants specific to the xdr "protocol"
55 */
56#define XDR_FALSE ((long) 0)

--- 10 unchanged lines hidden (view full) ---

67 * Not a filter, but a convenient utility nonetheless
68 */
69void
70xdr_free(proc, objp)
71 xdrproc_t proc;
72 char *objp;
73{
74 XDR x;
73
75
74 x.x_op = XDR_FREE;
75 (*proc)(&x, objp);
76}
77
78/*
79 * XDR nothing
80 */
81bool_t
82xdr_void(/* xdrs, addr */)
83 /* XDR *xdrs; */
84 /* caddr_t addr; */
85{
86
87 return (TRUE);
88}
89
76 x.x_op = XDR_FREE;
77 (*proc)(&x, objp);
78}
79
80/*
81 * XDR nothing
82 */
83bool_t
84xdr_void(/* xdrs, addr */)
85 /* XDR *xdrs; */
86 /* caddr_t addr; */
87{
88
89 return (TRUE);
90}
91
92
90/*
91 * XDR integers
92 */
93bool_t
94xdr_int(xdrs, ip)
95 XDR *xdrs;
96 int *ip;
97{
93/*
94 * XDR integers
95 */
96bool_t
97xdr_int(xdrs, ip)
98 XDR *xdrs;
99 int *ip;
100{
101 long l;
98
102
99#ifdef lint
100 (void) (xdr_short(xdrs, (short *)ip));
101 return (xdr_long(xdrs, (long *)ip));
102#else
103 if (sizeof (int) == sizeof (long)) {
104 return (xdr_long(xdrs, (long *)ip));
105 } else {
106 return (xdr_short(xdrs, (short *)ip));
103 switch (xdrs->x_op) {
104
105 case XDR_ENCODE:
106 l = (long) *ip;
107 return (XDR_PUTLONG(xdrs, &l));
108
109 case XDR_DECODE:
110 if (!XDR_GETLONG(xdrs, &l)) {
111 return (FALSE);
112 }
113 *ip = (int) l;
114 return (TRUE);
115
116 case XDR_FREE:
117 return (TRUE);
107 }
118 }
108#endif
119 return (FALSE);
109}
110
111/*
112 * XDR unsigned integers
113 */
114bool_t
115xdr_u_int(xdrs, up)
116 XDR *xdrs;
117 u_int *up;
118{
120}
121
122/*
123 * XDR unsigned integers
124 */
125bool_t
126xdr_u_int(xdrs, up)
127 XDR *xdrs;
128 u_int *up;
129{
130 u_long l;
119
131
120#ifdef lint
121 (void) (xdr_short(xdrs, (short *)up));
122 return (xdr_u_long(xdrs, (u_long *)up));
123#else
124 if (sizeof (u_int) == sizeof (u_long)) {
125 return (xdr_u_long(xdrs, (u_long *)up));
126 } else {
127 return (xdr_short(xdrs, (short *)up));
132 switch (xdrs->x_op) {
133
134 case XDR_ENCODE:
135 l = (u_long) *up;
136 return (XDR_PUTLONG(xdrs, (long *)&l));
137
138 case XDR_DECODE:
139 if (!XDR_GETLONG(xdrs, (long *)&l)) {
140 return (FALSE);
141 }
142 *up = (u_int) l;
143 return (TRUE);
144
145 case XDR_FREE:
146 return (TRUE);
128 }
147 }
129#endif
148 return (FALSE);
130}
131
149}
150
151
132/*
133 * XDR long integers
134 * same as xdr_u_long - open coded to save a proc call!
135 */
136bool_t
137xdr_long(xdrs, lp)
138 register XDR *xdrs;
139 long *lp;
140{
152/*
153 * XDR long integers
154 * same as xdr_u_long - open coded to save a proc call!
155 */
156bool_t
157xdr_long(xdrs, lp)
158 register XDR *xdrs;
159 long *lp;
160{
141
142 if (xdrs->x_op == XDR_ENCODE)
161 switch (xdrs->x_op) {
162 case XDR_ENCODE:
143 return (XDR_PUTLONG(xdrs, lp));
163 return (XDR_PUTLONG(xdrs, lp));
144
145 if (xdrs->x_op == XDR_DECODE)
164 case XDR_DECODE:
146 return (XDR_GETLONG(xdrs, lp));
165 return (XDR_GETLONG(xdrs, lp));
147
148 if (xdrs->x_op == XDR_FREE)
166 case XDR_FREE:
149 return (TRUE);
167 return (TRUE);
168 }
150
151 return (FALSE);
152}
153
154/*
155 * XDR unsigned long integers
156 * same as xdr_long - open coded to save a proc call!
157 */
158bool_t
159xdr_u_long(xdrs, ulp)
160 register XDR *xdrs;
161 u_long *ulp;
162{
169
170 return (FALSE);
171}
172
173/*
174 * XDR unsigned long integers
175 * same as xdr_long - open coded to save a proc call!
176 */
177bool_t
178xdr_u_long(xdrs, ulp)
179 register XDR *xdrs;
180 u_long *ulp;
181{
163
164 if (xdrs->x_op == XDR_DECODE)
165 return (XDR_GETLONG(xdrs, (long *)ulp));
166 if (xdrs->x_op == XDR_ENCODE)
182 switch (xdrs->x_op) {
183 case XDR_ENCODE:
167 return (XDR_PUTLONG(xdrs, (long *)ulp));
184 return (XDR_PUTLONG(xdrs, (long *)ulp));
168 if (xdrs->x_op == XDR_FREE)
185 case XDR_DECODE:
186 return (XDR_GETLONG(xdrs, (long *)ulp));
187 case XDR_FREE:
169 return (TRUE);
188 return (TRUE);
189 }
170 return (FALSE);
171}
172
190 return (FALSE);
191}
192
193
173/*
194/*
195 * XDR 32-bit integers
196 * same as xdr_u_int32_t - open coded to save a proc call!
197 */
198bool_t
199xdr_int32_t(xdrs, int32_p)
200 register XDR *xdrs;
201 int32_t *int32_p;
202{
203 long l;
204
205 switch (xdrs->x_op) {
206
207 case XDR_ENCODE:
208 l = (long) *int32_p;
209 return (XDR_PUTLONG(xdrs, &l));
210
211 case XDR_DECODE:
212 if (!XDR_GETLONG(xdrs, &l)) {
213 return (FALSE);
214 }
215 *int32_p = (int32_t) l;
216 return (TRUE);
217
218 case XDR_FREE:
219 return (TRUE);
220 }
221 return (FALSE);
222}
223
224/*
225 * XDR unsigned 32-bit integers
226 * same as xdr_int32_t - open coded to save a proc call!
227 */
228bool_t
229xdr_u_int32_t(xdrs, u_int32_p)
230 register XDR *xdrs;
231 u_int32_t *u_int32_p;
232{
233 u_long l;
234
235 switch (xdrs->x_op) {
236
237 case XDR_ENCODE:
238 l = (u_long) *u_int32_p;
239 return (XDR_PUTLONG(xdrs, (long *)&l));
240
241 case XDR_DECODE:
242 if (!XDR_GETLONG(xdrs, (long *)&l)) {
243 return (FALSE);
244 }
245 *u_int32_p = (u_int32_t) l;
246 return (TRUE);
247
248 case XDR_FREE:
249 return (TRUE);
250 }
251 return (FALSE);
252}
253
254
255/*
174 * XDR short integers
175 */
176bool_t
177xdr_short(xdrs, sp)
178 register XDR *xdrs;
179 short *sp;
180{
181 long l;

--- 26 unchanged lines hidden (view full) ---

208 u_short *usp;
209{
210 u_long l;
211
212 switch (xdrs->x_op) {
213
214 case XDR_ENCODE:
215 l = (u_long) *usp;
256 * XDR short integers
257 */
258bool_t
259xdr_short(xdrs, sp)
260 register XDR *xdrs;
261 short *sp;
262{
263 long l;

--- 26 unchanged lines hidden (view full) ---

290 u_short *usp;
291{
292 u_long l;
293
294 switch (xdrs->x_op) {
295
296 case XDR_ENCODE:
297 l = (u_long) *usp;
298 return (XDR_PUTLONG(xdrs, (long *)&l));
299
300 case XDR_DECODE:
301 if (!XDR_GETLONG(xdrs, (long *)&l)) {
302 return (FALSE);
303 }
304 *usp = (u_short) l;
305 return (TRUE);
306
307 case XDR_FREE:
308 return (TRUE);
309 }
310 return (FALSE);
311}
312
313
314/*
315 * XDR 16-bit integers
316 */
317bool_t
318xdr_int16_t(xdrs, int16_p)
319 register XDR *xdrs;
320 int16_t *int16_p;
321{
322 long l;
323
324 switch (xdrs->x_op) {
325
326 case XDR_ENCODE:
327 l = (long) *int16_p;
216 return (XDR_PUTLONG(xdrs, &l));
217
218 case XDR_DECODE:
219 if (!XDR_GETLONG(xdrs, &l)) {
220 return (FALSE);
221 }
328 return (XDR_PUTLONG(xdrs, &l));
329
330 case XDR_DECODE:
331 if (!XDR_GETLONG(xdrs, &l)) {
332 return (FALSE);
333 }
222 *usp = (u_short) l;
334 *int16_p = (int16_t) l;
223 return (TRUE);
224
225 case XDR_FREE:
226 return (TRUE);
227 }
228 return (FALSE);
229}
230
335 return (TRUE);
336
337 case XDR_FREE:
338 return (TRUE);
339 }
340 return (FALSE);
341}
342
343/*
344 * XDR unsigned 16-bit integers
345 */
346bool_t
347xdr_u_int16_t(xdrs, u_int16_p)
348 register XDR *xdrs;
349 u_int16_t *u_int16_p;
350{
351 u_long l;
231
352
353 switch (xdrs->x_op) {
354
355 case XDR_ENCODE:
356 l = (u_long) *u_int16_p;
357 return (XDR_PUTLONG(xdrs, (long *)&l));
358
359 case XDR_DECODE:
360 if (!XDR_GETLONG(xdrs, (long *)&l)) {
361 return (FALSE);
362 }
363 *u_int16_p = (u_int16_t) l;
364 return (TRUE);
365
366 case XDR_FREE:
367 return (TRUE);
368 }
369 return (FALSE);
370}
371
372
232/*
233 * XDR a char
234 */
235bool_t
236xdr_char(xdrs, cp)
237 XDR *xdrs;
238 char *cp;
239{

--- 8 unchanged lines hidden (view full) ---

248}
249
250/*
251 * XDR an unsigned char
252 */
253bool_t
254xdr_u_char(xdrs, cp)
255 XDR *xdrs;
373/*
374 * XDR a char
375 */
376bool_t
377xdr_char(xdrs, cp)
378 XDR *xdrs;
379 char *cp;
380{

--- 8 unchanged lines hidden (view full) ---

389}
390
391/*
392 * XDR an unsigned char
393 */
394bool_t
395xdr_u_char(xdrs, cp)
396 XDR *xdrs;
256 char *cp;
397 u_char *cp;
257{
258 u_int u;
259
260 u = (*cp);
261 if (!xdr_u_int(xdrs, &u)) {
262 return (FALSE);
263 }
264 *cp = u;

--- 40 unchanged lines hidden (view full) ---

305#ifndef lint
306 enum sizecheck { SIZEVAL }; /* used to find the size of an enum */
307
308 /*
309 * enums are treated as ints
310 */
311 if (sizeof (enum sizecheck) == sizeof (long)) {
312 return (xdr_long(xdrs, (long *)ep));
398{
399 u_int u;
400
401 u = (*cp);
402 if (!xdr_u_int(xdrs, &u)) {
403 return (FALSE);
404 }
405 *cp = u;

--- 40 unchanged lines hidden (view full) ---

446#ifndef lint
447 enum sizecheck { SIZEVAL }; /* used to find the size of an enum */
448
449 /*
450 * enums are treated as ints
451 */
452 if (sizeof (enum sizecheck) == sizeof (long)) {
453 return (xdr_long(xdrs, (long *)ep));
454 } else if (sizeof (enum sizecheck) == sizeof (int)) {
455 return (xdr_int(xdrs, (int *)ep));
313 } else if (sizeof (enum sizecheck) == sizeof (short)) {
314 return (xdr_short(xdrs, (short *)ep));
315 } else {
316 return (FALSE);
317 }
318#else
319 (void) (xdr_short(xdrs, (short *)ep));
456 } else if (sizeof (enum sizecheck) == sizeof (short)) {
457 return (xdr_short(xdrs, (short *)ep));
458 } else {
459 return (FALSE);
460 }
461#else
462 (void) (xdr_short(xdrs, (short *)ep));
463 (void) (xdr_int(xdrs, (int *)ep));
320 return (xdr_long(xdrs, (long *)ep));
321#endif
322}
323
324/*
325 * XDR opaque data
326 * Allows the specification of a fixed size sequence of opaque bytes.
327 * cp points to the opaque object and cnt gives the byte length.

--- 21 unchanged lines hidden (view full) ---

349 rndup = BYTES_PER_XDR_UNIT - rndup;
350
351 if (xdrs->x_op == XDR_DECODE) {
352 if (!XDR_GETBYTES(xdrs, cp, cnt)) {
353 return (FALSE);
354 }
355 if (rndup == 0)
356 return (TRUE);
464 return (xdr_long(xdrs, (long *)ep));
465#endif
466}
467
468/*
469 * XDR opaque data
470 * Allows the specification of a fixed size sequence of opaque bytes.
471 * cp points to the opaque object and cnt gives the byte length.

--- 21 unchanged lines hidden (view full) ---

493 rndup = BYTES_PER_XDR_UNIT - rndup;
494
495 if (xdrs->x_op == XDR_DECODE) {
496 if (!XDR_GETBYTES(xdrs, cp, cnt)) {
497 return (FALSE);
498 }
499 if (rndup == 0)
500 return (TRUE);
357 return (XDR_GETBYTES(xdrs, crud, rndup));
501 return (XDR_GETBYTES(xdrs, (caddr_t)crud, rndup));
358 }
359
360 if (xdrs->x_op == XDR_ENCODE) {
361 if (!XDR_PUTBYTES(xdrs, cp, cnt)) {
362 return (FALSE);
363 }
364 if (rndup == 0)
365 return (TRUE);

--- 191 unchanged lines hidden (view full) ---

557 case XDR_FREE:
558 mem_free(sp, nodesize);
559 *cpp = NULL;
560 return (TRUE);
561 }
562 return (FALSE);
563}
564
502 }
503
504 if (xdrs->x_op == XDR_ENCODE) {
505 if (!XDR_PUTBYTES(xdrs, cp, cnt)) {
506 return (FALSE);
507 }
508 if (rndup == 0)
509 return (TRUE);

--- 191 unchanged lines hidden (view full) ---

701 case XDR_FREE:
702 mem_free(sp, nodesize);
703 *cpp = NULL;
704 return (TRUE);
705 }
706 return (FALSE);
707}
708
565/*
566 * Wrapper for xdr_string that can be called directly from
709/*
710 * Wrapper for xdr_string that can be called directly from
567 * routines like clnt_call
568 */
569bool_t
570xdr_wrapstring(xdrs, cpp)
571 XDR *xdrs;
572 char **cpp;
573{
711 * routines like clnt_call
712 */
713bool_t
714xdr_wrapstring(xdrs, cpp)
715 XDR *xdrs;
716 char **cpp;
717{
574 if (xdr_string(xdrs, cpp, LASTUNSIGNED)) {
575 return (TRUE);
576 }
577 return (FALSE);
718 return xdr_string(xdrs, cpp, LASTUNSIGNED);
578}
719}