source: rtems-libbsd/freebsd/lib/libc/xdr/xdr.c

6-freebsd-12
Last change on this file was bb80d9d, checked in by Sebastian Huber <sebastian.huber@…>, on 08/09/18 at 12:02:09

Update to FreeBSD head 2017-12-01

Git mirror commit e724f51f811a4b2bd29447f8b85ab5c2f9b88266.

Update #3472.

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