Libinfo-517.200.9.tar.gz
[apple/libinfo.git] / rpc.subproj / xdr.c
1 /*
2 * Copyright (c) 1999-2018 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.1 (the "License"). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
12 * this file.
13 *
14 * The Original Code and all software distributed under the License are
15 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
20 * under the License.
21 *
22 * @APPLE_LICENSE_HEADER_END@
23 */
24
25 /* $NetBSD: xdr.c,v 1.22 2000/07/06 03:10:35 christos Exp $ */
26
27 /*
28 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
29 * unrestricted use provided that this legend is included on all tape
30 * media and as a part of the software program in whole or part. Users
31 * may copy or modify Sun RPC without charge, but are not authorized
32 * to license or distribute it to anyone else except as part of a product or
33 * program developed by the user.
34 *
35 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
36 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
37 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
38 *
39 * Sun RPC is provided with no support and without any obligation on the
40 * part of Sun Microsystems, Inc. to assist in its use, correction,
41 * modification or enhancement.
42 *
43 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
44 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
45 * OR ANY PART THEREOF.
46 *
47 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
48 * or profits or other special, indirect and consequential damages, even if
49 * Sun has been advised of the possibility of such damages.
50 *
51 * Sun Microsystems, Inc.
52 * 2550 Garcia Avenue
53 * Mountain View, California 94043
54 */
55
56 #if defined(LIBC_SCCS) && !defined(lint)
57 static char *sccsid = "@(#)xdr.c 1.35 87/08/12";
58 static char *sccsid = "@(#)xdr.c 2.1 88/07/29 4.0 RPCSRC";
59 #endif
60 #include <sys/cdefs.h>
61
62 /*
63 * xdr.c, Generic XDR routines implementation.
64 *
65 * Copyright (C) 1986, Sun Microsystems, Inc.
66 *
67 * These are the "generic" xdr routines used to serialize and de-serialize
68 * most common data items. See xdr.h for more info on the interface to
69 * xdr.
70 */
71
72 #include "libinfo_common.h"
73
74 #include <err.h>
75 #include <stdio.h>
76 #include <stdlib.h>
77 #include <string.h>
78
79 #include <rpc/types.h>
80 #include <rpc/xdr.h>
81
82 #ifdef __LP64__
83 #define xdrlong_t int
84 #else
85 #define xdrlong_t long
86 #endif
87
88 typedef quad_t longlong_t; /* ANSI long long type */
89 typedef u_quad_t u_longlong_t; /* ANSI unsigned long long type */
90
91 /*
92 * constants specific to the xdr "protocol"
93 */
94 #ifdef __LP64__
95 #define XDR_FALSE ((int) 0)
96 #define XDR_TRUE ((int) 1)
97 #else
98 #define XDR_FALSE ((long) 0)
99 #define XDR_TRUE ((long) 1)
100 #endif
101 #define LASTUNSIGNED ((u_int) 0-1)
102
103 /*
104 * for unit alignment
105 */
106 static const char xdr_zero[BYTES_PER_XDR_UNIT] = { 0, 0, 0, 0 };
107
108 /*
109 * Free a data structure using XDR
110 * Not a filter, but a convenient utility nonetheless
111 */
112 LIBINFO_EXPORT
113 void
114 xdr_free(proc, objp)
115 xdrproc_t proc;
116 void *objp;
117 {
118 XDR x;
119
120 x.x_op = XDR_FREE;
121 (*proc)(&x, objp, 0);
122 }
123
124 /*
125 * XDR nothing
126 */
127 LIBINFO_EXPORT
128 bool_t
129 xdr_void(void)
130 {
131
132 return (TRUE);
133 }
134
135
136 /*
137 * XDR integers
138 */
139 bool_t
140 LIBINFO_EXPORT
141 xdr_int(xdrs, ip)
142 XDR *xdrs;
143 int *ip;
144 {
145 xdrlong_t l;
146
147 switch (xdrs->x_op) {
148
149 case XDR_ENCODE:
150 l = *ip;
151 return (XDR_PUTLONG(xdrs, (const xdrlong_t *)&l));
152
153 case XDR_DECODE:
154 if (!XDR_GETLONG(xdrs, &l)) {
155 return (FALSE);
156 }
157 *ip = l;
158 return (TRUE);
159
160 case XDR_FREE:
161 return (TRUE);
162 }
163 /* NOTREACHED */
164 return (FALSE);
165 }
166
167 /*
168 * XDR unsigned integers
169 */
170 LIBINFO_EXPORT
171 bool_t
172 xdr_u_int(xdrs, up)
173 XDR *xdrs;
174 u_int *up;
175 {
176 xdrlong_t l;
177
178 switch (xdrs->x_op) {
179
180 case XDR_ENCODE:
181 l = *up;
182 return (XDR_PUTLONG(xdrs, (const xdrlong_t *)&l));
183
184 case XDR_DECODE:
185 if (!XDR_GETLONG(xdrs, &l)) {
186 return (FALSE);
187 }
188 *up = l;
189 return (TRUE);
190
191 case XDR_FREE:
192 return (TRUE);
193 }
194 /* NOTREACHED */
195 return (FALSE);
196 }
197
198
199 /*
200 * XDR long integers
201 * same as xdr_u_long - open coded to save a proc call!
202 */
203 LIBINFO_EXPORT
204 bool_t
205 xdr_long(xdrs, lp)
206 XDR *xdrs;
207 #ifdef __LP64__
208 int *lp;
209 #else
210 long *lp;
211 #endif
212 {
213 switch (xdrs->x_op) {
214 case XDR_ENCODE:
215 return (XDR_PUTLONG(xdrs, lp));
216 case XDR_DECODE:
217 return (XDR_GETLONG(xdrs, lp));
218 case XDR_FREE:
219 return (TRUE);
220 }
221 /* NOTREACHED */
222 return (FALSE);
223 }
224
225 /*
226 * XDR unsigned long integers
227 * same as xdr_long - open coded to save a proc call!
228 */
229 LIBINFO_EXPORT
230 bool_t
231 xdr_u_long(xdrs, ulp)
232 XDR *xdrs;
233 #ifdef __LP64__
234 unsigned int *ulp;
235 #else
236 u_long *ulp;
237 #endif
238 {
239 switch (xdrs->x_op) {
240 case XDR_ENCODE:
241 return (XDR_PUTLONG(xdrs, (const xdrlong_t *)ulp));
242 case XDR_DECODE:
243 return (XDR_GETLONG(xdrs, (xdrlong_t *)ulp));
244 case XDR_FREE:
245 return (TRUE);
246 }
247 /* NOTREACHED */
248 return (FALSE);
249 }
250
251
252 /*
253 * XDR 32-bit integers
254 * same as xdr_u_int32_t - open coded to save a proc call!
255 */
256 LIBINFO_EXPORT
257 bool_t
258 xdr_int32_t(xdrs, int32_p)
259 XDR *xdrs;
260 int32_t *int32_p;
261 {
262 xdrlong_t l;
263
264 switch (xdrs->x_op) {
265
266 case XDR_ENCODE:
267 l = *int32_p;
268 return (XDR_PUTLONG(xdrs, (const xdrlong_t *)&l));
269
270 case XDR_DECODE:
271 if (!XDR_GETLONG(xdrs, &l)) {
272 return (FALSE);
273 }
274 *int32_p = l;
275 return (TRUE);
276
277 case XDR_FREE:
278 return (TRUE);
279 }
280 /* NOTREACHED */
281 return (FALSE);
282 }
283
284 /*
285 * XDR unsigned 32-bit integers
286 * same as xdr_int32_t - open coded to save a proc call!
287 */
288 LIBINFO_EXPORT
289 bool_t
290 xdr_u_int32_t(xdrs, u_int32_p)
291 XDR *xdrs;
292 u_int32_t *u_int32_p;
293 {
294 u_int32_t l;
295
296 switch (xdrs->x_op) {
297
298 case XDR_ENCODE:
299 l = *u_int32_p;
300 return (XDR_PUTLONG(xdrs, (xdrlong_t *)&l));
301
302 case XDR_DECODE:
303 if (!XDR_GETLONG(xdrs, (xdrlong_t *)&l)) return (FALSE);
304 *u_int32_p = l;
305 return (TRUE);
306
307 case XDR_FREE:
308 return (TRUE);
309 }
310 /* NOTREACHED */
311 return (FALSE);
312 }
313
314
315 /*
316 * XDR short integers
317 */
318 LIBINFO_EXPORT
319 bool_t
320 xdr_short(xdrs, sp)
321 XDR *xdrs;
322 short *sp;
323 {
324 xdrlong_t l;
325
326 switch (xdrs->x_op) {
327
328 case XDR_ENCODE:
329 l = *sp;
330 return (XDR_PUTLONG(xdrs, (const xdrlong_t *)&l));
331
332 case XDR_DECODE:
333 if (!XDR_GETLONG(xdrs, &l)) {
334 return (FALSE);
335 }
336 *sp = l;
337 return (TRUE);
338
339 case XDR_FREE:
340 return (TRUE);
341 }
342 /* NOTREACHED */
343 return (FALSE);
344 }
345
346 /*
347 * XDR unsigned short integers
348 */
349 LIBINFO_EXPORT
350 bool_t
351 xdr_u_short(xdrs, usp)
352 XDR *xdrs;
353 u_short *usp;
354 {
355 xdrlong_t l;
356
357 switch (xdrs->x_op) {
358
359 case XDR_ENCODE:
360 l = *usp;
361 return (XDR_PUTLONG(xdrs, (const xdrlong_t *)&l));
362
363 case XDR_DECODE:
364 if (!XDR_GETLONG(xdrs, &l)) {
365 return (FALSE);
366 }
367 *usp = l;
368 return (TRUE);
369
370 case XDR_FREE:
371 return (TRUE);
372 }
373 /* NOTREACHED */
374 return (FALSE);
375 }
376
377
378 /*
379 * XDR 16-bit integers
380 */
381 LIBINFO_EXPORT
382 bool_t
383 xdr_int16_t(xdrs, int16_p)
384 XDR *xdrs;
385 int16_t *int16_p;
386 {
387 xdrlong_t l;
388
389 switch (xdrs->x_op) {
390
391 case XDR_ENCODE:
392 l = *int16_p;
393 return (XDR_PUTLONG(xdrs, (const xdrlong_t *)&l));
394
395 case XDR_DECODE:
396 if (!XDR_GETLONG(xdrs, &l)) {
397 return (FALSE);
398 }
399 *int16_p = l;
400 return (TRUE);
401
402 case XDR_FREE:
403 return (TRUE);
404 }
405 /* NOTREACHED */
406 return (FALSE);
407 }
408
409 /*
410 * XDR unsigned 16-bit integers
411 */
412 LIBINFO_EXPORT
413 bool_t
414 xdr_u_int16_t(xdrs, u_int16_p)
415 XDR *xdrs;
416 u_int16_t *u_int16_p;
417 {
418 xdrlong_t l;
419
420 switch (xdrs->x_op) {
421
422 case XDR_ENCODE:
423 l = *u_int16_p;
424 return (XDR_PUTLONG(xdrs, (const xdrlong_t *)&l));
425
426 case XDR_DECODE:
427 if (!XDR_GETLONG(xdrs, &l)) {
428 return (FALSE);
429 }
430 *u_int16_p = l;
431 return (TRUE);
432
433 case XDR_FREE:
434 return (TRUE);
435 }
436 /* NOTREACHED */
437 return (FALSE);
438 }
439
440
441 /*
442 * XDR a char
443 */
444 LIBINFO_EXPORT
445 bool_t
446 xdr_char(xdrs, cp)
447 XDR *xdrs;
448 char *cp;
449 {
450 int i;
451
452 i = (*cp);
453 if (!xdr_int(xdrs, &i)) {
454 return (FALSE);
455 }
456 *cp = i;
457 return (TRUE);
458 }
459
460 /*
461 * XDR an unsigned char
462 */
463 LIBINFO_EXPORT
464 bool_t
465 xdr_u_char(xdrs, cp)
466 XDR *xdrs;
467 u_char *cp;
468 {
469 u_int32_t u;
470
471 u = (*cp);
472 if (!xdr_u_int(xdrs, &u)) {
473 return (FALSE);
474 }
475 *cp = u;
476 return (TRUE);
477 }
478
479 /*
480 * XDR booleans
481 */
482 LIBINFO_EXPORT
483 bool_t
484 xdr_bool(xdrs, bp)
485 XDR *xdrs;
486 bool_t *bp;
487 {
488 xdrlong_t lb;
489
490 switch (xdrs->x_op) {
491
492 case XDR_ENCODE:
493 lb = *bp ? XDR_TRUE : XDR_FALSE;
494 return (XDR_PUTLONG(xdrs, (const xdrlong_t *)&lb));
495
496 case XDR_DECODE:
497 if (!XDR_GETLONG(xdrs, &lb)) {
498 return (FALSE);
499 }
500 *bp = (lb == XDR_FALSE) ? FALSE : TRUE;
501 return (TRUE);
502
503 case XDR_FREE:
504 return (TRUE);
505 }
506 /* NOTREACHED */
507 return (FALSE);
508 }
509
510 /*
511 * XDR enumerations
512 */
513 LIBINFO_EXPORT
514 bool_t
515 xdr_enum(xdrs, ep)
516 XDR *xdrs;
517 enum_t *ep;
518 {
519 enum sizecheck { SIZEVAL }; /* used to find the size of an enum */
520
521 /*
522 * enums are treated as ints
523 */
524 /* LINTED */ if (sizeof (enum sizecheck) == sizeof (int)) {
525 return (xdr_long(xdrs, (xdrlong_t *)(void *)ep));
526 } else /* LINTED */ if (sizeof (enum sizecheck) == sizeof (int)) {
527 return (xdr_int(xdrs, (int *)(void *)ep));
528 } else /* LINTED */ if (sizeof (enum sizecheck) == sizeof (short)) {
529 return (xdr_short(xdrs, (short *)(void *)ep));
530 } else {
531 return (FALSE);
532 }
533 }
534
535 /*
536 * XDR opaque data
537 * Allows the specification of a fixed size sequence of opaque bytes.
538 * cp points to the opaque object and cnt gives the byte length.
539 */
540 LIBINFO_EXPORT
541 bool_t
542 xdr_opaque(xdrs, cp, cnt)
543 XDR *xdrs;
544 caddr_t cp;
545 u_int cnt;
546 {
547 u_int32_t rndup;
548 u_int8_t crud[BYTES_PER_XDR_UNIT];
549
550 /*
551 * if no data we are done
552 */
553 if (cnt == 0)
554 return (TRUE);
555
556 /*
557 * round byte count to full xdr units
558 */
559 rndup = cnt % BYTES_PER_XDR_UNIT;
560 if (rndup > 0)
561 rndup = BYTES_PER_XDR_UNIT - rndup;
562
563 if (xdrs->x_op == XDR_DECODE) {
564 if (!XDR_GETBYTES(xdrs, cp, cnt)) {
565 return (FALSE);
566 }
567 if (rndup == 0)
568 return (TRUE);
569 return (XDR_GETBYTES(xdrs, (caddr_t)(void *)crud, rndup));
570 }
571
572 if (xdrs->x_op == XDR_ENCODE) {
573 if (!XDR_PUTBYTES(xdrs, cp, cnt)) {
574 return (FALSE);
575 }
576 if (rndup == 0)
577 return (TRUE);
578 return (XDR_PUTBYTES(xdrs, xdr_zero, rndup));
579 }
580
581 if (xdrs->x_op == XDR_FREE) {
582 return (TRUE);
583 }
584
585 return (FALSE);
586 }
587
588 /*
589 * XDR counted bytes
590 * *cpp is a pointer to the bytes, *sizep is the count.
591 * If *cpp is NULL maxsize bytes are allocated
592 */
593 LIBINFO_EXPORT
594 bool_t
595 xdr_bytes(xdrs, cpp, sizep, maxsize)
596 XDR *xdrs;
597 char **cpp;
598 u_int *sizep;
599 u_int maxsize;
600 {
601 char *sp = *cpp; /* sp is the actual string pointer */
602 u_int32_t nodesize;
603
604 /*
605 * first deal with the length since xdr bytes are counted
606 */
607 if (! xdr_u_int(xdrs, sizep)) {
608 return (FALSE);
609 }
610 nodesize = *sizep;
611 if ((nodesize > maxsize) && (xdrs->x_op != XDR_FREE)) {
612 return (FALSE);
613 }
614
615 /*
616 * now deal with the actual bytes
617 */
618 switch (xdrs->x_op) {
619
620 case XDR_DECODE:
621 if (nodesize == 0) {
622 return (TRUE);
623 }
624 if (sp == NULL) {
625 *cpp = sp = mem_alloc(nodesize);
626 }
627 if (sp == NULL) {
628 warnx("xdr_bytes: out of memory");
629 return (FALSE);
630 }
631 /* FALLTHROUGH */
632
633 case XDR_ENCODE:
634 return (xdr_opaque(xdrs, sp, nodesize));
635
636 case XDR_FREE:
637 if (sp != NULL) {
638 mem_free(sp, nodesize);
639 *cpp = NULL;
640 }
641 return (TRUE);
642 }
643 /* NOTREACHED */
644 return (FALSE);
645 }
646
647 /*
648 * Implemented here due to commonality of the object.
649 */
650 LIBINFO_EXPORT
651 bool_t
652 xdr_netobj(xdrs, np)
653 XDR *xdrs;
654 struct netobj *np;
655 {
656
657 return (xdr_bytes(xdrs, &np->n_bytes, &np->n_len, MAX_NETOBJ_SZ));
658 }
659
660 /*
661 * XDR a descriminated union
662 * Support routine for discriminated unions.
663 * You create an array of xdrdiscrim structures, terminated with
664 * an entry with a null procedure pointer. The routine gets
665 * the discriminant value and then searches the array of xdrdiscrims
666 * looking for that value. It calls the procedure given in the xdrdiscrim
667 * to handle the discriminant. If there is no specific routine a default
668 * routine may be called.
669 * If there is no specific or default routine an error is returned.
670 */
671 LIBINFO_EXPORT
672 bool_t
673 xdr_union(xdrs, dscmp, unp, choices, dfault)
674 XDR *xdrs;
675 enum_t *dscmp; /* enum to decide which arm to work on */
676 char *unp; /* the union itself */
677 const struct xdr_discrim *choices; /* [value, xdr proc] for each arm */
678 xdrproc_t dfault; /* default xdr routine */
679 {
680 enum_t dscm;
681
682 /*
683 * we deal with the discriminator; it's an enum
684 */
685 if (! xdr_enum(xdrs, dscmp)) {
686 return (FALSE);
687 }
688 dscm = *dscmp;
689
690 /*
691 * search choices for a value that matches the discriminator.
692 * if we find one, execute the xdr routine for that value.
693 */
694 for (; choices->proc != NULL_xdrproc_t; choices++) {
695 if (choices->value == dscm)
696 return ((*(choices->proc))(xdrs, unp, 0));
697 }
698
699 /*
700 * no match - execute the default xdr routine if there is one
701 */
702 return ((dfault == NULL_xdrproc_t) ? FALSE :
703 (*dfault)(xdrs, unp, 0));
704 }
705
706
707 /*
708 * Non-portable xdr primitives.
709 * Care should be taken when moving these routines to new architectures.
710 */
711
712
713 /*
714 * XDR null terminated ASCII strings
715 * xdr_string deals with "C strings" - arrays of bytes that are
716 * terminated by a NULL character. The parameter cpp references a
717 * pointer to storage; If the pointer is null, then the necessary
718 * storage is allocated. The last parameter is the max allowed length
719 * of the string as specified by a protocol.
720 */
721 LIBINFO_EXPORT
722 bool_t
723 xdr_string(xdrs, cpp, maxsize)
724 XDR *xdrs;
725 char **cpp;
726 u_int maxsize;
727 {
728 char *sp = *cpp; /* sp is the actual string pointer */
729 u_int32_t size;
730 u_int32_t nodesize;
731
732 /*
733 * first deal with the length since xdr strings are counted-strings
734 */
735 switch (xdrs->x_op) {
736 case XDR_FREE:
737 if (sp == NULL) {
738 return(TRUE); /* already free */
739 }
740 /* FALLTHROUGH */
741 case XDR_ENCODE:
742 size = strlen(sp);
743 break;
744 case XDR_DECODE:
745 break;
746 }
747 if (! xdr_u_int(xdrs, &size)) {
748 return (FALSE);
749 }
750 if (size > maxsize) {
751 return (FALSE);
752 }
753 nodesize = size + 1;
754
755 /*
756 * now deal with the actual bytes
757 */
758 switch (xdrs->x_op) {
759
760 case XDR_DECODE:
761 if (nodesize == 0) {
762 return (TRUE);
763 }
764 if (sp == NULL)
765 *cpp = sp = mem_alloc(nodesize);
766 if (sp == NULL) {
767 warnx("xdr_string: out of memory");
768 return (FALSE);
769 }
770 sp[size] = 0;
771 /* FALLTHROUGH */
772
773 case XDR_ENCODE:
774 return (xdr_opaque(xdrs, sp, size));
775
776 case XDR_FREE:
777 mem_free(sp, nodesize);
778 *cpp = NULL;
779 return (TRUE);
780 }
781 /* NOTREACHED */
782 return (FALSE);
783 }
784
785 /*
786 * Wrapper for xdr_string that can be called directly from
787 * routines like clnt_call
788 */
789 LIBINFO_EXPORT
790 bool_t
791 xdr_wrapstring(xdrs, cpp)
792 XDR *xdrs;
793 char **cpp;
794 {
795 return xdr_string(xdrs, cpp, LASTUNSIGNED);
796 }
797
798 /*
799 * NOTE: xdr_hyper(), xdr_u_hyper(), xdr_longlong_t(), and xdr_u_longlong_t()
800 * are in the "non-portable" section because they require that a `long long'
801 * be a 64-bit type.
802 *
803 * --thorpej@netbsd.org, November 30, 1999
804 */
805
806 /*
807 * XDR 64-bit integers
808 */
809 LIBINFO_EXPORT
810 bool_t
811 xdr_int64_t(xdrs, llp)
812 XDR *xdrs;
813 int64_t *llp;
814 {
815 u_int32_t ul[2];
816
817 switch (xdrs->x_op) {
818 case XDR_ENCODE:
819 ul[0] = (u_int32_t)((u_int64_t)*llp >> 32) & 0xffffffff;
820 ul[1] = (u_int32_t)((u_int64_t)*llp) & 0xffffffff;
821 if (XDR_PUTLONG(xdrs, (xdrlong_t *)&ul[0]) == FALSE)
822 return (FALSE);
823 return (XDR_PUTLONG(xdrs, (xdrlong_t *)&ul[1]));
824 case XDR_DECODE:
825 if (XDR_GETLONG(xdrs, (xdrlong_t *)&ul[0]) == FALSE)
826 return (FALSE);
827 if (XDR_GETLONG(xdrs, (xdrlong_t *)&ul[1]) == FALSE)
828 return (FALSE);
829 *llp = (int64_t)
830 (((u_int64_t)ul[0] << 32) | ((u_int64_t)ul[1]));
831 return (TRUE);
832 case XDR_FREE:
833 return (TRUE);
834 }
835 /* NOTREACHED */
836 return (FALSE);
837 }
838
839
840 /*
841 * XDR unsigned 64-bit integers
842 */
843 LIBINFO_EXPORT
844 bool_t
845 xdr_u_int64_t(xdrs, ullp)
846 XDR *xdrs;
847 u_int64_t *ullp;
848 {
849 u_int32_t ul[2];
850
851 switch (xdrs->x_op) {
852 case XDR_ENCODE:
853 ul[0] = (u_int32_t)(*ullp >> 32) & 0xffffffff;
854 ul[1] = (u_int32_t)(*ullp) & 0xffffffff;
855 if (XDR_PUTLONG(xdrs, (xdrlong_t *)&ul[0]) == FALSE)
856 return (FALSE);
857 return (XDR_PUTLONG(xdrs, (xdrlong_t *)&ul[1]));
858 case XDR_DECODE:
859 if (XDR_GETLONG(xdrs, (xdrlong_t *)&ul[0]) == FALSE)
860 return (FALSE);
861 if (XDR_GETLONG(xdrs, (xdrlong_t *)&ul[1]) == FALSE)
862 return (FALSE);
863 *ullp = (u_int64_t)
864 (((u_int64_t)ul[0] << 32) | ((u_int64_t)ul[1]));
865 return (TRUE);
866 case XDR_FREE:
867 return (TRUE);
868 }
869 /* NOTREACHED */
870 return (FALSE);
871 }
872
873
874 /*
875 * XDR hypers
876 */
877 LIBINFO_EXPORT
878 bool_t
879 xdr_hyper(xdrs, llp)
880 XDR *xdrs;
881 longlong_t *llp;
882 {
883 /*
884 * Don't bother open-coding this; it's a fair amount of code. Just
885 * call xdr_int64_t().
886 */
887 return (xdr_int64_t(xdrs, (int64_t *)llp));
888 }
889
890
891 /*
892 * XDR unsigned hypers
893 */
894 LIBINFO_EXPORT
895 bool_t
896 xdr_u_hyper(xdrs, ullp)
897 XDR *xdrs;
898 u_longlong_t *ullp;
899 {
900 /*
901 * Don't bother open-coding this; it's a fair amount of code. Just
902 * call xdr_u_int64_t().
903 */
904 return (xdr_u_int64_t(xdrs, (u_int64_t *)ullp));
905 }
906
907
908 /*
909 * XDR longlong_t's
910 */
911 LIBINFO_EXPORT
912 bool_t
913 xdr_longlong_t(xdrs, llp)
914 XDR *xdrs;
915 longlong_t *llp;
916 {
917 /*
918 * Don't bother open-coding this; it's a fair amount of code. Just
919 * call xdr_int64_t().
920 */
921 return (xdr_int64_t(xdrs, (int64_t *)llp));
922 }
923
924
925 /*
926 * XDR u_longlong_t's
927 */
928 LIBINFO_EXPORT
929 bool_t
930 xdr_u_longlong_t(xdrs, ullp)
931 XDR *xdrs;
932 u_longlong_t *ullp;
933 {
934
935 /*
936 * Don't bother open-coding this; it's a fair amount of code. Just
937 * call xdr_u_int64_t().
938 */
939 return (xdr_u_int64_t(xdrs, (u_int64_t *)ullp));
940 }