Imported Upstream version 0.2.5
[platform/upstream/libtirpc.git] / src / xdr.c
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 #include <sys/cdefs.h>
30
31 /*
32  * xdr.c, Generic XDR routines implementation.
33  *
34  * Copyright (C) 1986, Sun Microsystems, Inc.
35  *
36  * These are the "generic" xdr routines used to serialize and de-serialize
37  * most common data items.  See xdr.h for more info on the interface to
38  * xdr.
39  */
40
41 #include <err.h>
42 #include <stdio.h>
43 #include <stdlib.h>
44 #include <string.h>
45
46 #include <rpc/types.h>
47 #include <rpc/xdr.h>
48
49 typedef quad_t          longlong_t;     /* ANSI long long type */
50 typedef u_quad_t        u_longlong_t;   /* ANSI unsigned long long type */
51
52 /*
53  * constants specific to the xdr "protocol"
54  */
55 #define XDR_FALSE       ((long) 0)
56 #define XDR_TRUE        ((long) 1)
57 #define LASTUNSIGNED    ((u_int) 0-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
634         /*
635          * first deal with the length since xdr bytes are counted
636          */
637         if (! xdr_u_int(xdrs, sizep)) {
638                 return (FALSE);
639         }
640         nodesize = *sizep;
641         if ((nodesize > maxsize) && (xdrs->x_op != XDR_FREE)) {
642                 return (FALSE);
643         }
644
645         /*
646          * now deal with the actual bytes
647          */
648         switch (xdrs->x_op) {
649
650         case XDR_DECODE:
651                 if (nodesize == 0) {
652                         return (TRUE);
653                 }
654                 if (sp == NULL) {
655                         *cpp = sp = mem_alloc(nodesize);
656                 }
657                 if (sp == NULL) {
658                         warnx("xdr_bytes: out of memory");
659                         return (FALSE);
660                 }
661                 /* FALLTHROUGH */
662
663         case XDR_ENCODE:
664                 return (xdr_opaque(xdrs, sp, nodesize));
665
666         case XDR_FREE:
667                 if (sp != NULL) {
668                         mem_free(sp, nodesize);
669                         *cpp = NULL;
670                 }
671                 return (TRUE);
672         }
673         /* NOTREACHED */
674         return (FALSE);
675 }
676
677 /*
678  * Implemented here due to commonality of the object.
679  */
680 bool_t
681 xdr_netobj(xdrs, np)
682         XDR *xdrs;
683         struct netobj *np;
684 {
685
686         return (xdr_bytes(xdrs, &np->n_bytes, &np->n_len, MAX_NETOBJ_SZ));
687 }
688
689 /*
690  * XDR a descriminated union
691  * Support routine for discriminated unions.
692  * You create an array of xdrdiscrim structures, terminated with
693  * an entry with a null procedure pointer.  The routine gets
694  * the discriminant value and then searches the array of xdrdiscrims
695  * looking for that value.  It calls the procedure given in the xdrdiscrim
696  * to handle the discriminant.  If there is no specific routine a default
697  * routine may be called.
698  * If there is no specific or default routine an error is returned.
699  */
700 bool_t
701 xdr_union(xdrs, dscmp, unp, choices, dfault)
702         XDR *xdrs;
703         enum_t *dscmp;          /* enum to decide which arm to work on */
704         char *unp;              /* the union itself */
705         const struct xdr_discrim *choices;      /* [value, xdr proc] for each arm */
706         xdrproc_t dfault;       /* default xdr routine */
707 {
708         enum_t dscm;
709
710         /*
711          * we deal with the discriminator;  it's an enum
712          */
713         if (! xdr_enum(xdrs, dscmp)) {
714                 return (FALSE);
715         }
716         dscm = *dscmp;
717
718         /*
719          * search choices for a value that matches the discriminator.
720          * if we find one, execute the xdr routine for that value.
721          */
722         for (; choices->proc != NULL_xdrproc_t; choices++) {
723                 if (choices->value == dscm)
724                         return ((*(choices->proc))(xdrs, unp));
725         }
726
727         /*
728          * no match - execute the default xdr routine if there is one
729          */
730         return ((dfault == NULL_xdrproc_t) ? FALSE :
731             (*dfault)(xdrs, unp));
732 }
733
734
735 /*
736  * Non-portable xdr primitives.
737  * Care should be taken when moving these routines to new architectures.
738  */
739
740
741 /*
742  * XDR null terminated ASCII strings
743  * xdr_string deals with "C strings" - arrays of bytes that are
744  * terminated by a NULL character.  The parameter cpp references a
745  * pointer to storage; If the pointer is null, then the necessary
746  * storage is allocated.  The last parameter is the max allowed length
747  * of the string as specified by a protocol.
748  */
749 bool_t
750 xdr_string(xdrs, cpp, maxsize)
751         XDR *xdrs;
752         char **cpp;
753         u_int maxsize;
754 {
755         char *sp = *cpp;  /* sp is the actual string pointer */
756         u_int size;
757         u_int nodesize;
758
759         /*
760          * first deal with the length since xdr strings are counted-strings
761          */
762         switch (xdrs->x_op) {
763         case XDR_FREE:
764                 if (sp == NULL) {
765                         return(TRUE);   /* already free */
766                 }
767                 /* FALLTHROUGH */
768         case XDR_ENCODE:
769                 if (sp == NULL)
770                         return FALSE;
771                 size = strlen(sp);
772                 break;
773         case XDR_DECODE:
774                 break;
775         }
776         if (! xdr_u_int(xdrs, &size)) {
777                 return (FALSE);
778         }
779         if (size > maxsize) {
780                 return (FALSE);
781         }
782         nodesize = size + 1;
783         if (nodesize == 0) {
784                 /* This means an overflow.  It a bug in the caller which
785                  * provided a too large maxsize but nevertheless catch it
786                  * here.
787                  */
788                 return FALSE;
789         }
790
791         /*
792          * now deal with the actual bytes
793          */
794         switch (xdrs->x_op) {
795
796         case XDR_DECODE:
797                 if (sp == NULL)
798                         *cpp = sp = mem_alloc(nodesize);
799                 if (sp == NULL) {
800                         warnx("xdr_string: out of memory");
801                         return (FALSE);
802                 }
803                 sp[size] = 0;
804                 /* FALLTHROUGH */
805
806         case XDR_ENCODE:
807                 return (xdr_opaque(xdrs, sp, size));
808
809         case XDR_FREE:
810                 mem_free(sp, nodesize);
811                 *cpp = NULL;
812                 return (TRUE);
813         }
814         /* NOTREACHED */
815         return (FALSE);
816 }
817
818 /* 
819  * Wrapper for xdr_string that can be called directly from 
820  * routines like clnt_call
821  */
822 bool_t
823 xdr_wrapstring(xdrs, cpp)
824         XDR *xdrs;
825         char **cpp;
826 {
827         return xdr_string(xdrs, cpp, LASTUNSIGNED);
828 }
829
830 /*
831  * NOTE: xdr_hyper(), xdr_u_hyper(), xdr_longlong_t(), and xdr_u_longlong_t()
832  * are in the "non-portable" section because they require that a `long long'
833  * be a 64-bit type.
834  *
835  *      --thorpej@netbsd.org, November 30, 1999
836  */
837
838 /*
839  * XDR 64-bit integers
840  */
841 bool_t
842 xdr_int64_t(xdrs, llp)
843         XDR *xdrs;
844         int64_t *llp;
845 {
846         u_long ul[2];
847
848         switch (xdrs->x_op) {
849         case XDR_ENCODE:
850                 ul[0] = (u_long)((u_int64_t)*llp >> 32) & 0xffffffff;
851                 ul[1] = (u_long)((u_int64_t)*llp) & 0xffffffff;
852                 if (XDR_PUTLONG(xdrs, (long *)&ul[0]) == FALSE)
853                         return (FALSE);
854                 return (XDR_PUTLONG(xdrs, (long *)&ul[1]));
855         case XDR_DECODE:
856                 if (XDR_GETLONG(xdrs, (long *)&ul[0]) == FALSE)
857                         return (FALSE);
858                 if (XDR_GETLONG(xdrs, (long *)&ul[1]) == FALSE)
859                         return (FALSE);
860                 *llp = (int64_t)
861                     (((u_int64_t)ul[0] << 32) | ((u_int64_t)ul[1]));
862                 return (TRUE);
863         case XDR_FREE:
864                 return (TRUE);
865         }
866         /* NOTREACHED */
867         return (FALSE);
868 }
869
870
871 /*
872  * XDR unsigned 64-bit integers
873  */
874 bool_t
875 xdr_u_int64_t(xdrs, ullp)
876         XDR *xdrs;
877         u_int64_t *ullp;
878 {
879         u_long ul[2];
880
881         switch (xdrs->x_op) {
882         case XDR_ENCODE:
883                 ul[0] = (u_long)(*ullp >> 32) & 0xffffffff;
884                 ul[1] = (u_long)(*ullp) & 0xffffffff;
885                 if (XDR_PUTLONG(xdrs, (long *)&ul[0]) == FALSE)
886                         return (FALSE);
887                 return (XDR_PUTLONG(xdrs, (long *)&ul[1]));
888         case XDR_DECODE:
889                 if (XDR_GETLONG(xdrs, (long *)&ul[0]) == FALSE)
890                         return (FALSE);
891                 if (XDR_GETLONG(xdrs, (long *)&ul[1]) == FALSE)
892                         return (FALSE);
893                 *ullp = (u_int64_t)
894                     (((u_int64_t)ul[0] << 32) | ((u_int64_t)ul[1]));
895                 return (TRUE);
896         case XDR_FREE:
897                 return (TRUE);
898         }
899         /* NOTREACHED */
900         return (FALSE);
901 }
902
903
904 /*
905  * XDR unsigned 64-bit integers
906  */
907 bool_t
908 xdr_uint64_t(xdrs, ullp)
909         XDR *xdrs;
910         uint64_t *ullp;
911 {
912         return (xdr_u_int64_t(xdrs, (u_int64_t *)ullp));
913 }
914
915
916 /*
917  * XDR hypers
918  */
919 bool_t
920 xdr_hyper(xdrs, llp)
921         XDR *xdrs;
922         longlong_t *llp;
923 {
924
925         /*
926          * Don't bother open-coding this; it's a fair amount of code.  Just
927          * call xdr_int64_t().
928          */
929         return (xdr_int64_t(xdrs, (int64_t *)llp));
930 }
931
932
933 /*
934  * XDR unsigned hypers
935  */
936 bool_t
937 xdr_u_hyper(xdrs, ullp)
938         XDR *xdrs;
939         u_longlong_t *ullp;
940 {
941
942         /*
943          * Don't bother open-coding this; it's a fair amount of code.  Just
944          * call xdr_u_int64_t().
945          */
946         return (xdr_u_int64_t(xdrs, (u_int64_t *)ullp));
947 }
948
949
950 /*
951  * XDR longlong_t's
952  */
953 bool_t
954 xdr_longlong_t(xdrs, llp)
955         XDR *xdrs;
956         longlong_t *llp;
957 {
958
959         /*
960          * Don't bother open-coding this; it's a fair amount of code.  Just
961          * call xdr_int64_t().
962          */
963         return (xdr_int64_t(xdrs, (int64_t *)llp));
964 }
965
966
967 /*
968  * XDR u_longlong_t's
969  */
970 bool_t
971 xdr_u_longlong_t(xdrs, ullp)
972         XDR *xdrs;
973         u_longlong_t *ullp;
974 {
975
976         /*
977          * Don't bother open-coding this; it's a fair amount of code.  Just
978          * call xdr_u_int64_t().
979          */
980         return (xdr_u_int64_t(xdrs, (u_int64_t *)ullp));
981 }
982
983 /*
984  * XDR quad_t
985  */
986 bool_t
987 xdr_quad_t(xdrs, llp)
988         XDR *xdrs;
989         int64_t *llp;
990 {
991         return (xdr_int64_t(xdrs, (int64_t *)llp));
992 }
993
994
995 /*
996  * XDR u_quad_t
997  */
998 bool_t
999 xdr_u_quad_t(xdrs, ullp)
1000         XDR *xdrs;
1001         u_int64_t *ullp;
1002 {
1003         return (xdr_u_int64_t(xdrs, (u_int64_t *)ullp));
1004 }