Debian Codegraph @

extra/tirpc/libtirpc-1.3.5/src/xdr.c

raw symbols SCIP
1 /*
2 * Copyright (c) 2009, Sun Microsystems, Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * - Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
9 * - Redistributions in binary form must reproduce the above copyright notice,
10 * this list of conditions and the following disclaimer in the documentation
11 * and/or other materials provided with the distribution.
12 * - Neither the name of Sun Microsystems, Inc. nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
28
29
30 /*
31 * xdr.c, Generic XDR routines implementation.
32 *
33 * Copyright (C) 1986, Sun Microsystems, Inc.
34 *
35 * These are the "generic" xdr routines used to serialize and de-serialize
36 * most common data items. See xdr.h for more info on the interface to
37 * xdr.
38 */
39
40 #include <err.h>
41 #include <stdio.h>
42 #include <stdlib.h>
43 #include <string.h>
44
45 #include <rpc/rpc.h>
46 #include <rpc/types.h>
47 #include <rpc/xdr.h>
48 #include <rpc/rpc_com.h>
49
50 typedef quad_t longlong_t; /* ANSI long long type */
51 typedef u_quad_t u_longlong_t; /* ANSI unsigned long long type */
52
53 /*
54 * constants specific to the xdr "protocol"
55 */
56 #define XDR_FALSE ((long) 0)
57 #define XDR_TRUE ((long) 1)
58
59 /*
60 * for unit alignment
61 */
62 static const char xdr_zero[BYTES_PER_XDR_UNIT] = { 0, 0, 0, 0 };
63
64 /*
65 * Free a data structure using XDR
66 * Not a filter, but a convenient utility nonetheless
67 */
68 void
69 xdr_free(proc, objp)
70 xdrproc_t proc;
71 void *objp;
72 {
73 XDR x;
74
75 x.x_op = XDR_FREE;
76 (*proc)(&x, objp);
77 }
78
79 /*
80 * XDR nothing
81 */
82 bool_t
83 xdr_void(void)
84 {
85
86 return (TRUE);
87 }
88
89
90 /*
91 * XDR integers
92 */
93 bool_t
94 xdr_int(xdrs, ip)
95 XDR *xdrs;
96 int *ip;
97 {
98 long l;
99
100 switch (xdrs->x_op) {
101
102 case XDR_ENCODE:
103 l = (long) *ip;
104 return (XDR_PUTLONG(xdrs, &l));
105
106 case XDR_DECODE:
107 if (!XDR_GETLONG(xdrs, &l)) {
108 return (FALSE);
109 }
110 *ip = (int) l;
111 return (TRUE);
112
113 case XDR_FREE:
114 return (TRUE);
115 }
116 /* NOTREACHED */
117 return (FALSE);
118 }
119
120 /*
121 * XDR unsigned integers
122 */
123 bool_t
124 xdr_u_int(xdrs, up)
125 XDR *xdrs;
126 u_int *up;
127 {
128 u_long l;
129
130 switch (xdrs->x_op) {
131
132 case XDR_ENCODE:
133 l = (u_long) *up;
134 return (XDR_PUTLONG(xdrs, (long *)&l));
135
136 case XDR_DECODE:
137 if (!XDR_GETLONG(xdrs, (long *)&l)) {
138 return (FALSE);
139 }
140 *up = (u_int) l;
141 return (TRUE);
142
143 case XDR_FREE:
144 return (TRUE);
145 }
146 /* NOTREACHED */
147 return (FALSE);
148 }
149
150
151 /*
152 * XDR long integers
153 * same as xdr_u_long - open coded to save a proc call!
154 */
155 bool_t
156 xdr_long(xdrs, lp)
157 XDR *xdrs;
158 long *lp;
159 {
160 switch (xdrs->x_op) {
161 case XDR_ENCODE:
162 return (XDR_PUTLONG(xdrs, lp));
163 case XDR_DECODE:
164 return (XDR_GETLONG(xdrs, lp));
165 case XDR_FREE:
166 return (TRUE);
167 }
168 /* NOTREACHED */
169 return (FALSE);
170 }
171
172 /*
173 * XDR unsigned long integers
174 * same as xdr_long - open coded to save a proc call!
175 */
176 bool_t
177 xdr_u_long(xdrs, ulp)
178 XDR *xdrs;
179 u_long *ulp;
180 {
181 switch (xdrs->x_op) {
182 case XDR_ENCODE:
183 return (XDR_PUTLONG(xdrs, (long *)ulp));
184 case XDR_DECODE:
185 return (XDR_GETLONG(xdrs, (long *)ulp));
186 case XDR_FREE:
187 return (TRUE);
188 }
189 /* NOTREACHED */
190 return (FALSE);
191 }
192
193
194 /*
195 * XDR 32-bit integers
196 * same as xdr_u_int32_t - open coded to save a proc call!
197 */
198 bool_t
199 xdr_int32_t(xdrs, int32_p)
200 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 /* NOTREACHED */
222 return (FALSE);
223 }
224
225 /*
226 * XDR unsigned 32-bit integers
227 * same as xdr_int32_t - open coded to save a proc call!
228 */
229 bool_t
230 xdr_u_int32_t(xdrs, u_int32_p)
231 XDR *xdrs;
232 u_int32_t *u_int32_p;
233 {
234 u_long l;
235
236 switch (xdrs->x_op) {
237
238 case XDR_ENCODE:
239 l = (u_long) *u_int32_p;
240 return (XDR_PUTLONG(xdrs, (long *)&l));
241
242 case XDR_DECODE:
243 if (!XDR_GETLONG(xdrs, (long *)&l)) {
244 return (FALSE);
245 }
246 *u_int32_p = (u_int32_t) l;
247 return (TRUE);
248
249 case XDR_FREE:
250 return (TRUE);
251 }
252 /* NOTREACHED */
253 return (FALSE);
254 }
255
256
257 /*
258 * XDR unsigned 32-bit integers
259 */
260 bool_t
261 xdr_uint32_t(xdrs, uint32_p)
262 XDR *xdrs;
263 uint32_t *uint32_p;
264 {
265 return (xdr_u_int32_t(xdrs, (u_int32_t *)uint32_p));
266 }
267
268
269 /*
270 * XDR short integers
271 */
272 bool_t
273 xdr_short(xdrs, sp)
274 XDR *xdrs;
275 short *sp;
276 {
277 long l;
278
279 switch (xdrs->x_op) {
280
281 case XDR_ENCODE:
282 l = (long) *sp;
283 return (XDR_PUTLONG(xdrs, &l));
284
285 case XDR_DECODE:
286 if (!XDR_GETLONG(xdrs, &l)) {
287 return (FALSE);
288 }
289 *sp = (short) l;
290 return (TRUE);
291
292 case XDR_FREE:
293 return (TRUE);
294 }
295 /* NOTREACHED */
296 return (FALSE);
297 }
298
299 /*
300 * XDR unsigned short integers
301 */
302 bool_t
303 xdr_u_short(xdrs, usp)
304 XDR *xdrs;
305 u_short *usp;
306 {
307 u_long l;
308
309 switch (xdrs->x_op) {
310
311 case XDR_ENCODE:
312 l = (u_long) *usp;
313 return (XDR_PUTLONG(xdrs, (long *)&l));
314
315 case XDR_DECODE:
316 if (!XDR_GETLONG(xdrs, (long *)&l)) {
317 return (FALSE);
318 }
319 *usp = (u_short) l;
320 return (TRUE);
321
322 case XDR_FREE:
323 return (TRUE);
324 }
325 /* NOTREACHED */
326 return (FALSE);
327 }
328
329
330 /*
331 * XDR 16-bit integers
332 */
333 bool_t
334 xdr_int16_t(xdrs, int16_p)
335 XDR *xdrs;
336 int16_t *int16_p;
337 {
338 long l;
339
340 switch (xdrs->x_op) {
341
342 case XDR_ENCODE:
343 l = (long) *int16_p;
344 return (XDR_PUTLONG(xdrs, &l));
345
346 case XDR_DECODE:
347 if (!XDR_GETLONG(xdrs, &l)) {
348 return (FALSE);
349 }
350 *int16_p = (int16_t) l;
351 return (TRUE);
352
353 case XDR_FREE:
354 return (TRUE);
355 }
356 /* NOTREACHED */
357 return (FALSE);
358 }
359
360 /*
361 * XDR unsigned 16-bit integers
362 */
363 bool_t
364 xdr_u_int16_t(xdrs, u_int16_p)
365 XDR *xdrs;
366 u_int16_t *u_int16_p;
367 {
368 u_long l;
369
370 switch (xdrs->x_op) {
371
372 case XDR_ENCODE:
373 l = (u_long) *u_int16_p;
374 return (XDR_PUTLONG(xdrs, (long *)&l));
375
376 case XDR_DECODE:
377 if (!XDR_GETLONG(xdrs, (long *)&l)) {
378 return (FALSE);
379 }
380 *u_int16_p = (u_int16_t) l;
381 return (TRUE);
382
383 case XDR_FREE:
384 return (TRUE);
385 }
386 /* NOTREACHED */
387 return (FALSE);
388 }
389
390
391 /*
392 * XDR unsigned 16-bit integers
393 */
394 bool_t
395 xdr_uint16_t(xdrs, uint16_p)
396 XDR *xdrs;
397 uint16_t *uint16_p;
398 {
399 return (xdr_u_int16_t(xdrs, (u_int16_t *)uint16_p));
400 }
401
402
403 /*
404 * XDR 8-bit integers
405 */
406 bool_t
407 xdr_int8_t(xdrs, int8_p)
408 XDR *xdrs;
409 int8_t *int8_p;
410 {
411 long l;
412
413 switch (xdrs->x_op) {
414
415 case XDR_ENCODE:
416 l = (long) *int8_p;
417 return (XDR_PUTLONG(xdrs, &l));
418
419 case XDR_DECODE:
420 if (!XDR_GETLONG(xdrs, &l)) {
421 return (FALSE);
422 }
423 *int8_p = (int8_t) l;
424 return (TRUE);
425
426 case XDR_FREE:
427 return (TRUE);
428 }
429 /* NOTREACHED */
430 return (FALSE);
431 }
432
433
434 /*
435 * XDR unsigned 8-bit integers
436 */
437 bool_t
438 xdr_u_int8_t(xdrs, uint8_p)
439 XDR *xdrs;
440 uint8_t *uint8_p;
441 {
442 u_long l;
443
444 switch (xdrs->x_op) {
445
446 case XDR_ENCODE:
447 l = (u_long) *uint8_p;
448 return (XDR_PUTLONG(xdrs, (long *)&l));
449
450 case XDR_DECODE:
451 if (!XDR_GETLONG(xdrs, (long *)&l)) {
452 return (FALSE);
453 }
454 *uint8_p = (uint8_t) l;
455 return (TRUE);
456
457 case XDR_FREE:
458 return (TRUE);
459 }
460 /* NOTREACHED */
461 return (FALSE);
462 }
463
464
465 /*
466 * XDR unsigned 8-bit integers
467 */
468 bool_t
469 xdr_uint8_t(xdrs, uint8_p)
470 XDR *xdrs;
471 uint8_t *uint8_p;
472 {
473 return (xdr_u_int8_t(xdrs, (uint8_t *)uint8_p));
474 }
475
476
477 /*
478 * XDR a char
479 */
480 bool_t
481 xdr_char(xdrs, cp)
482 XDR *xdrs;
483 char *cp;
484 {
485 int i;
486
487 i = (*cp);
488 if (!xdr_int(xdrs, &i)) {
489 return (FALSE);
490 }
491 *cp = i;
492 return (TRUE);
493 }
494
495 /*
496 * XDR an unsigned char
497 */
498 bool_t
499 xdr_u_char(xdrs, cp)
500 XDR *xdrs;
501 u_char *cp;
502 {
503 u_int u;
504
505 u = (*cp);
506 if (!xdr_u_int(xdrs, &u)) {
507 return (FALSE);
508 }
509 *cp = u;
510 return (TRUE);
511 }
512
513 /*
514 * XDR booleans
515 */
516 bool_t
517 xdr_bool(xdrs, bp)
518 XDR *xdrs;
519 bool_t *bp;
520 {
521 long lb;
522
523 switch (xdrs->x_op) {
524
525 case XDR_ENCODE:
526 lb = *bp ? XDR_TRUE : XDR_FALSE;
527 return (XDR_PUTLONG(xdrs, &lb));
528
529 case XDR_DECODE:
530 if (!XDR_GETLONG(xdrs, &lb)) {
531 return (FALSE);
532 }
533 *bp = (lb == XDR_FALSE) ? FALSE : TRUE;
534 return (TRUE);
535
536 case XDR_FREE:
537 return (TRUE);
538 }
539 /* NOTREACHED */
540 return (FALSE);
541 }
542
543 /*
544 * XDR enumerations
545 */
546 bool_t
547 xdr_enum(xdrs, ep)
548 XDR *xdrs;
549 enum_t *ep;
550 {
551 enum sizecheck { SIZEVAL }; /* used to find the size of an enum */
552
553 /*
554 * enums are treated as ints
555 */
556 /* LINTED */ if (sizeof (enum sizecheck) == sizeof (long)) {
557 return (xdr_long(xdrs, (long *)(void *)ep));
558 } else /* LINTED */ if (sizeof (enum sizecheck) == sizeof (int)) {
559 return (xdr_int(xdrs, (int *)(void *)ep));
560 } else /* LINTED */ if (sizeof (enum sizecheck) == sizeof (short)) {
561 return (xdr_short(xdrs, (short *)(void *)ep));
562 } else {
563 return (FALSE);
564 }
565 }
566
567 /*
568 * XDR opaque data
569 * Allows the specification of a fixed size sequence of opaque bytes.
570 * cp points to the opaque object and cnt gives the byte length.
571 */
572 bool_t
573 xdr_opaque(xdrs, cp, cnt)
574 XDR *xdrs;
575 caddr_t cp;
576 u_int cnt;
577 {
578 u_int rndup;
579 static int crud[BYTES_PER_XDR_UNIT];
580
581 /*
582 * if no data we are done
583 */
584 if (cnt == 0)
585 return (TRUE);
586
587 /*
588 * round byte count to full xdr units
589 */
590 rndup = cnt % BYTES_PER_XDR_UNIT;
591 if (rndup > 0)
592 rndup = BYTES_PER_XDR_UNIT - rndup;
593
594 if (xdrs->x_op == XDR_DECODE) {
595 if (!XDR_GETBYTES(xdrs, cp, cnt)) {
596 return (FALSE);
597 }
598 if (rndup == 0)
599 return (TRUE);
600 return (XDR_GETBYTES(xdrs, (caddr_t)(void *)crud, rndup));
601 }
602
603 if (xdrs->x_op == XDR_ENCODE) {
604 if (!XDR_PUTBYTES(xdrs, cp, cnt)) {
605 return (FALSE);
606 }
607 if (rndup == 0)
608 return (TRUE);
609 return (XDR_PUTBYTES(xdrs, xdr_zero, rndup));
610 }
611
612 if (xdrs->x_op == XDR_FREE) {
613 return (TRUE);
614 }
615
616 return (FALSE);
617 }
618
619 /*
620 * XDR counted bytes
621 * *cpp is a pointer to the bytes, *sizep is the count.
622 * If *cpp is NULL maxsize bytes are allocated
623 */
624 bool_t
625 xdr_bytes(xdrs, cpp, sizep, maxsize)
626 XDR *xdrs;
627 char **cpp;
628 u_int *sizep;
629 u_int maxsize;
630 {
631 char *sp = *cpp; /* sp is the actual string pointer */
632 u_int nodesize;
633 bool_t ret, allocated = FALSE;
634
635 /*
636 * first deal with the length since xdr bytes are counted
637 */
638 if (! xdr_u_int(xdrs, sizep)) {
639 return (FALSE);
640 }
641 nodesize = *sizep;
642 if ((nodesize > maxsize) && (xdrs->x_op != XDR_FREE)) {
643 return (FALSE);
644 }
645
646 /*
647 * now deal with the actual bytes
648 */
649 switch (xdrs->x_op) {
650
651 case XDR_DECODE:
652 if (nodesize == 0) {
653 return (TRUE);
654 }
655 if (sp == NULL) {
656 *cpp = sp = mem_alloc(nodesize);
657 allocated = TRUE;
658 }
659 if (sp == NULL) {
660 warnx("xdr_bytes: out of memory");
661 return (FALSE);
662 }
663 /* FALLTHROUGH */
664
665 case XDR_ENCODE:
666 ret = xdr_opaque(xdrs, sp, nodesize);
667 if ((xdrs->x_op == XDR_DECODE) && (ret == FALSE)) {
668 if (allocated == TRUE) {
669 free(sp);
670 *cpp = NULL;
671 }
672 }
673 return (ret);
674
675 case XDR_FREE:
676 if (sp != NULL) {
677 mem_free(sp, nodesize);
678 *cpp = NULL;
679 }
680 return (TRUE);
681 }
682 /* NOTREACHED */
683 return (FALSE);
684 }
685
686 /*
687 * Implemented here due to commonality of the object.
688 */
689 bool_t
690 xdr_netobj(xdrs, np)
691 XDR *xdrs;
692 struct netobj *np;
693 {
694
695 return (xdr_bytes(xdrs, &np->n_bytes, &np->n_len, MAX_NETOBJ_SZ));
696 }
697
698 /*
699 * XDR a descriminated union
700 * Support routine for discriminated unions.
701 * You create an array of xdrdiscrim structures, terminated with
702 * an entry with a null procedure pointer. The routine gets
703 * the discriminant value and then searches the array of xdrdiscrims
704 * looking for that value. It calls the procedure given in the xdrdiscrim
705 * to handle the discriminant. If there is no specific routine a default
706 * routine may be called.
707 * If there is no specific or default routine an error is returned.
708 */
709 bool_t
710 xdr_union(xdrs, dscmp, unp, choices, dfault)
711 XDR *xdrs;
712 enum_t *dscmp; /* enum to decide which arm to work on */
713 char *unp; /* the union itself */
714 const struct xdr_discrim *choices; /* [value, xdr proc] for each arm */
715 xdrproc_t dfault; /* default xdr routine */
716 {
717 enum_t dscm;
718
719 /*
720 * we deal with the discriminator; it's an enum
721 */
722 if (! xdr_enum(xdrs, dscmp)) {
723 return (FALSE);
724 }
725 dscm = *dscmp;
726
727 /*
728 * search choices for a value that matches the discriminator.
729 * if we find one, execute the xdr routine for that value.
730 */
731 for (; choices->proc != NULL_xdrproc_t; choices++) {
732 if (choices->value == dscm)
733 return ((*(choices->proc))(xdrs, unp));
734 }
735
736 /*
737 * no match - execute the default xdr routine if there is one
738 */
739 return ((dfault == NULL_xdrproc_t) ? FALSE :
740 (*dfault)(xdrs, unp));
741 }
742
743
744 /*
745 * Non-portable xdr primitives.
746 * Care should be taken when moving these routines to new architectures.
747 */
748
749
750 /*
751 * XDR null terminated ASCII strings
752 * xdr_string deals with "C strings" - arrays of bytes that are
753 * terminated by a NULL character. The parameter cpp references a
754 * pointer to storage; If the pointer is null, then the necessary
755 * storage is allocated. The last parameter is the max allowed length
756 * of the string as specified by a protocol.
757 */
758 bool_t
759 xdr_string(xdrs, cpp, maxsize)
760 XDR *xdrs;
761 char **cpp;
762 u_int maxsize;
763 {
764 char *sp = *cpp; /* sp is the actual string pointer */
765 u_int size;
766 u_int nodesize;
767 bool_t ret, allocated = FALSE;
768
769 /*
770 * first deal with the length since xdr strings are counted-strings
771 */
772 switch (xdrs->x_op) {
773 case XDR_FREE:
774 if (sp == NULL) {
775 return(TRUE); /* already free */
776 }
777 /* FALLTHROUGH */
778 case XDR_ENCODE:
779 if (sp == NULL)
780 return FALSE;
781 size = strlen(sp);
782 break;
783 case XDR_DECODE:
784 break;
785 }
786 if (! xdr_u_int(xdrs, &size)) {
787 return (FALSE);
788 }
789 if (size > maxsize) {
790 return (FALSE);
791 }
792 nodesize = size + 1;
793 if (nodesize == 0) {
794 /* This means an overflow. It a bug in the caller which
795 * provided a too large maxsize but nevertheless catch it
796 * here.
797 */
798 return FALSE;
799 }
800
801 /*
802 * now deal with the actual bytes
803 */
804 switch (xdrs->x_op) {
805
806 case XDR_DECODE:
807 if (sp == NULL) {
808 *cpp = sp = mem_alloc(nodesize);
809 allocated = TRUE;
810 }
811 if (sp == NULL) {
812 warnx("xdr_string: out of memory");
813 return (FALSE);
814 }
815 sp[size] = 0;
816 /* FALLTHROUGH */
817
818 case XDR_ENCODE:
819 ret = xdr_opaque(xdrs, sp, size);
820 if ((xdrs->x_op == XDR_DECODE) && (ret == FALSE)) {
821 if (allocated == TRUE) {
822 free(sp);
823 *cpp = NULL;
824 }
825 }
826 return (ret);
827
828 case XDR_FREE:
829 mem_free(sp, nodesize);
830 *cpp = NULL;
831 return (TRUE);
832 }
833 /* NOTREACHED */
834 return (FALSE);
835 }
836
837 /*
838 * Wrapper for xdr_string that can be called directly from
839 * routines like clnt_call
840 */
841 bool_t
842 xdr_wrapstring(xdrs, cpp)
843 XDR *xdrs;
844 char **cpp;
845 {
846 return xdr_string(xdrs, cpp, RPC_MAXDATASIZE);
847 }
848
849 /*
850 * NOTE: xdr_hyper(), xdr_u_hyper(), xdr_longlong_t(), and xdr_u_longlong_t()
851 * are in the "non-portable" section because they require that a `long long'
852 * be a 64-bit type.
853 *
854 * [email protected], November 30, 1999
855 */
856
857 /*
858 * XDR 64-bit integers
859 */
860 bool_t
861 xdr_int64_t(xdrs, llp)
862 XDR *xdrs;
863 int64_t *llp;
864 {
865 u_long ul[2];
866
867 switch (xdrs->x_op) {
868 case XDR_ENCODE:
869 ul[0] = (u_long)((u_int64_t)*llp >> 32) & 0xffffffff;
870 ul[1] = (u_long)((u_int64_t)*llp) & 0xffffffff;
871 if (XDR_PUTLONG(xdrs, (long *)&ul[0]) == FALSE)
872 return (FALSE);
873 return (XDR_PUTLONG(xdrs, (long *)&ul[1]));
874 case XDR_DECODE:
875 if (XDR_GETLONG(xdrs, (long *)&ul[0]) == FALSE)
876 return (FALSE);
877 if (XDR_GETLONG(xdrs, (long *)&ul[1]) == FALSE)
878 return (FALSE);
879 *llp = (int64_t)
880 (((u_int64_t)ul[0] << 32) |
881 ((u_int64_t)(ul[1]) & 0xffffffff));
882 return (TRUE);
883 case XDR_FREE:
884 return (TRUE);
885 }
886 /* NOTREACHED */
887 return (FALSE);
888 }
889
890
891 /*
892 * XDR unsigned 64-bit integers
893 */
894 bool_t
895 xdr_u_int64_t(xdrs, ullp)
896 XDR *xdrs;
897 u_int64_t *ullp;
898 {
899 u_long ul[2];
900
901 switch (xdrs->x_op) {
902 case XDR_ENCODE:
903 ul[0] = (u_long)(*ullp >> 32) & 0xffffffff;
904 ul[1] = (u_long)(*ullp) & 0xffffffff;
905 if (XDR_PUTLONG(xdrs, (long *)&ul[0]) == FALSE)
906 return (FALSE);
907 return (XDR_PUTLONG(xdrs, (long *)&ul[1]));
908 case XDR_DECODE:
909 if (XDR_GETLONG(xdrs, (long *)&ul[0]) == FALSE)
910 return (FALSE);
911 if (XDR_GETLONG(xdrs, (long *)&ul[1]) == FALSE)
912 return (FALSE);
913 *ullp = (u_int64_t)
914 (((u_int64_t)ul[0] << 32) |
915 ((u_int64_t)(ul[1]) & 0xffffffff));
916 return (TRUE);
917 case XDR_FREE:
918 return (TRUE);
919 }
920 /* NOTREACHED */
921 return (FALSE);
922 }
923
924
925 /*
926 * XDR unsigned 64-bit integers
927 */
928 bool_t
929 xdr_uint64_t(xdrs, ullp)
930 XDR *xdrs;
931 uint64_t *ullp;
932 {
933 return (xdr_u_int64_t(xdrs, (u_int64_t *)ullp));
934 }
935
936
937 /*
938 * XDR hypers
939 */
940 bool_t
941 xdr_hyper(xdrs, llp)
942 XDR *xdrs;
943 longlong_t *llp;
944 {
945
946 /*
947 * Don't bother open-coding this; it's a fair amount of code. Just
948 * call xdr_int64_t().
949 */
950 return (xdr_int64_t(xdrs, (int64_t *)llp));
951 }
952
953
954 /*
955 * XDR unsigned hypers
956 */
957 bool_t
958 xdr_u_hyper(xdrs, ullp)
959 XDR *xdrs;
960 u_longlong_t *ullp;
961 {
962
963 /*
964 * Don't bother open-coding this; it's a fair amount of code. Just
965 * call xdr_u_int64_t().
966 */
967 return (xdr_u_int64_t(xdrs, (u_int64_t *)ullp));
968 }
969
970
971 /*
972 * XDR longlong_t's
973 */
974 bool_t
975 xdr_longlong_t(xdrs, llp)
976 XDR *xdrs;
977 longlong_t *llp;
978 {
979
980 /*
981 * Don't bother open-coding this; it's a fair amount of code. Just
982 * call xdr_int64_t().
983 */
984 return (xdr_int64_t(xdrs, (int64_t *)llp));
985 }
986
987
988 /*
989 * XDR u_longlong_t's
990 */
991 bool_t
992 xdr_u_longlong_t(xdrs, ullp)
993 XDR *xdrs;
994 u_longlong_t *ullp;
995 {
996
997 /*
998 * Don't bother open-coding this; it's a fair amount of code. Just
999 * call xdr_u_int64_t().
1000 */
1001 return (xdr_u_int64_t(xdrs, (u_int64_t *)ullp));
1002 }
1003
1004 /*
1005 * XDR quad_t
1006 */
1007 bool_t
1008 xdr_quad_t(xdrs, llp)
1009 XDR *xdrs;
1010 int64_t *llp;
1011 {
1012 return (xdr_int64_t(xdrs, (int64_t *)llp));
1013 }
1014
1015
1016 /*
1017 * XDR u_quad_t
1018 */
1019 bool_t
1020 xdr_u_quad_t(xdrs, ullp)
1021 XDR *xdrs;
1022 u_int64_t *ullp;
1023 {
1024 return (xdr_u_int64_t(xdrs, (u_int64_t *)ullp));
1025 }