xref: /titanic_50/usr/src/uts/common/rpc/xdr.c (revision 1fcced4c370617db71610fecffd5451a5894ca5e)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
50a701b1eSRobert Gordon  * Common Development and Distribution License (the "License").
60a701b1eSRobert Gordon  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*1fcced4cSJordan Brown  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate /*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
277c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate /*
307c478bd9Sstevel@tonic-gate  * Portions of this source code were derived from Berkeley 4.3 BSD
317c478bd9Sstevel@tonic-gate  * under license from the Regents of the University of California.
327c478bd9Sstevel@tonic-gate  */
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate /*
357c478bd9Sstevel@tonic-gate  * xdr.c, generic XDR routines implementation.
367c478bd9Sstevel@tonic-gate  * These are the "generic" xdr routines used to serialize and de-serialize
377c478bd9Sstevel@tonic-gate  * most common data items.  See xdr.h for more info on the interface to
387c478bd9Sstevel@tonic-gate  * xdr.
397c478bd9Sstevel@tonic-gate  */
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate #include <sys/param.h>
427c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
437c478bd9Sstevel@tonic-gate #include <sys/types.h>
447c478bd9Sstevel@tonic-gate #include <sys/systm.h>
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate #include <rpc/types.h>
477c478bd9Sstevel@tonic-gate #include <rpc/xdr.h>
487c478bd9Sstevel@tonic-gate #include <sys/isa_defs.h>
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate #pragma weak xdr_int32_t = xdr_int
517c478bd9Sstevel@tonic-gate #pragma weak xdr_uint32_t = xdr_u_int
527c478bd9Sstevel@tonic-gate #pragma weak xdr_int64_t = xdr_longlong_t
537c478bd9Sstevel@tonic-gate #pragma weak xdr_uint64_t = xdr_u_longlong_t
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate #if !defined(_BIG_ENDIAN) && !defined(_LITTLE_ENDIAN)
567c478bd9Sstevel@tonic-gate #error "Exactly one of _BIG_ENDIAN or _LITTLE_ENDIAN must be defined"
577c478bd9Sstevel@tonic-gate #elif defined(_BIG_ENDIAN) && defined(_LITTLE_ENDIAN)
587c478bd9Sstevel@tonic-gate #error "Only one of _BIG_ENDIAN or _LITTLE_ENDIAN may be defined"
597c478bd9Sstevel@tonic-gate #endif
607c478bd9Sstevel@tonic-gate 
617c478bd9Sstevel@tonic-gate /*
627c478bd9Sstevel@tonic-gate  * constants specific to the xdr "protocol"
637c478bd9Sstevel@tonic-gate  */
647c478bd9Sstevel@tonic-gate #define	XDR_FALSE	((int32_t)0)
657c478bd9Sstevel@tonic-gate #define	XDR_TRUE	((int32_t)1)
667c478bd9Sstevel@tonic-gate #define	LASTUNSIGNED	((uint_t)0-1)
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate /*
697c478bd9Sstevel@tonic-gate  * for unit alignment
707c478bd9Sstevel@tonic-gate  */
717c478bd9Sstevel@tonic-gate static char xdr_zero[BYTES_PER_XDR_UNIT] = { 0, 0, 0, 0 };
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate /*
747c478bd9Sstevel@tonic-gate  * Free a data structure using XDR
757c478bd9Sstevel@tonic-gate  * Not a filter, but a convenient utility nonetheless
767c478bd9Sstevel@tonic-gate  */
777c478bd9Sstevel@tonic-gate void
xdr_free(xdrproc_t proc,char * objp)787c478bd9Sstevel@tonic-gate xdr_free(xdrproc_t proc, char *objp)
797c478bd9Sstevel@tonic-gate {
807c478bd9Sstevel@tonic-gate 	XDR x;
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate 	x.x_op = XDR_FREE;
837c478bd9Sstevel@tonic-gate 	(*proc)(&x, objp);
847c478bd9Sstevel@tonic-gate }
857c478bd9Sstevel@tonic-gate 
867c478bd9Sstevel@tonic-gate /*
877c478bd9Sstevel@tonic-gate  * XDR nothing
887c478bd9Sstevel@tonic-gate  */
897c478bd9Sstevel@tonic-gate bool_t
xdr_void(void)907c478bd9Sstevel@tonic-gate xdr_void(void)
917c478bd9Sstevel@tonic-gate {
927c478bd9Sstevel@tonic-gate 	return (TRUE);
937c478bd9Sstevel@tonic-gate }
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate /*
967c478bd9Sstevel@tonic-gate  * XDR integers
977c478bd9Sstevel@tonic-gate  *
987c478bd9Sstevel@tonic-gate  * PSARC 2003/523 Contract Private Interface
997c478bd9Sstevel@tonic-gate  * xdr_int
1007c478bd9Sstevel@tonic-gate  * Changes must be reviewed by Solaris File Sharing
1017c478bd9Sstevel@tonic-gate  * Changes must be communicated to contract-2003-523@sun.com
1027c478bd9Sstevel@tonic-gate  */
1037c478bd9Sstevel@tonic-gate bool_t
xdr_int(XDR * xdrs,int * ip)1047c478bd9Sstevel@tonic-gate xdr_int(XDR *xdrs, int *ip)
1057c478bd9Sstevel@tonic-gate {
1067c478bd9Sstevel@tonic-gate 	if (xdrs->x_op == XDR_ENCODE)
1077c478bd9Sstevel@tonic-gate 		return (XDR_PUTINT32(xdrs, ip));
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate 	if (xdrs->x_op == XDR_DECODE)
1107c478bd9Sstevel@tonic-gate 		return (XDR_GETINT32(xdrs, ip));
1117c478bd9Sstevel@tonic-gate 
1127c478bd9Sstevel@tonic-gate 	if (xdrs->x_op == XDR_FREE)
1137c478bd9Sstevel@tonic-gate 		return (TRUE);
1147c478bd9Sstevel@tonic-gate 
1157c478bd9Sstevel@tonic-gate 	return (FALSE);
1167c478bd9Sstevel@tonic-gate }
1177c478bd9Sstevel@tonic-gate 
1187c478bd9Sstevel@tonic-gate /*
1197c478bd9Sstevel@tonic-gate  * XDR unsigned integers
1207c478bd9Sstevel@tonic-gate  *
1217c478bd9Sstevel@tonic-gate  * PSARC 2003/523 Contract Private Interface
1227c478bd9Sstevel@tonic-gate  * xdr_u_int
1237c478bd9Sstevel@tonic-gate  * Changes must be reviewed by Solaris File Sharing
1247c478bd9Sstevel@tonic-gate  * Changes must be communicated to contract-2003-523@sun.com
1257c478bd9Sstevel@tonic-gate  */
1267c478bd9Sstevel@tonic-gate bool_t
xdr_u_int(XDR * xdrs,uint_t * up)1277c478bd9Sstevel@tonic-gate xdr_u_int(XDR *xdrs, uint_t *up)
1287c478bd9Sstevel@tonic-gate {
1297c478bd9Sstevel@tonic-gate 	if (xdrs->x_op == XDR_ENCODE)
1307c478bd9Sstevel@tonic-gate 		return (XDR_PUTINT32(xdrs, (int32_t *)up));
1317c478bd9Sstevel@tonic-gate 
1327c478bd9Sstevel@tonic-gate 	if (xdrs->x_op == XDR_DECODE)
1337c478bd9Sstevel@tonic-gate 		return (XDR_GETINT32(xdrs, (int32_t *)up));
1347c478bd9Sstevel@tonic-gate 
1357c478bd9Sstevel@tonic-gate 	if (xdrs->x_op == XDR_FREE)
1367c478bd9Sstevel@tonic-gate 		return (TRUE);
1377c478bd9Sstevel@tonic-gate 
1387c478bd9Sstevel@tonic-gate 	return (FALSE);
1397c478bd9Sstevel@tonic-gate }
1407c478bd9Sstevel@tonic-gate 
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate #if defined(_ILP32)
1437c478bd9Sstevel@tonic-gate /*
1447c478bd9Sstevel@tonic-gate  * xdr_long and xdr_u_long for binary compatability on ILP32 kernels.
1457c478bd9Sstevel@tonic-gate  *
1467c478bd9Sstevel@tonic-gate  * No prototypes since new code should not be using these interfaces.
1477c478bd9Sstevel@tonic-gate  */
1487c478bd9Sstevel@tonic-gate bool_t
xdr_long(XDR * xdrs,long * ip)1497c478bd9Sstevel@tonic-gate xdr_long(XDR *xdrs, long *ip)
1507c478bd9Sstevel@tonic-gate {
1517c478bd9Sstevel@tonic-gate 	return (xdr_int(xdrs, (int *)ip));
1527c478bd9Sstevel@tonic-gate }
1537c478bd9Sstevel@tonic-gate 
1547c478bd9Sstevel@tonic-gate bool_t
xdr_u_long(XDR * xdrs,unsigned long * up)1557c478bd9Sstevel@tonic-gate xdr_u_long(XDR *xdrs, unsigned long *up)
1567c478bd9Sstevel@tonic-gate {
1577c478bd9Sstevel@tonic-gate 	return (xdr_u_int(xdrs, (uint_t *)up));
1587c478bd9Sstevel@tonic-gate }
1597c478bd9Sstevel@tonic-gate #endif /* _ILP32 */
1607c478bd9Sstevel@tonic-gate 
1617c478bd9Sstevel@tonic-gate 
1627c478bd9Sstevel@tonic-gate /*
1637c478bd9Sstevel@tonic-gate  * XDR long long integers
1647c478bd9Sstevel@tonic-gate  */
1657c478bd9Sstevel@tonic-gate bool_t
xdr_longlong_t(XDR * xdrs,longlong_t * hp)1667c478bd9Sstevel@tonic-gate xdr_longlong_t(XDR *xdrs, longlong_t *hp)
1677c478bd9Sstevel@tonic-gate {
1687c478bd9Sstevel@tonic-gate 	if (xdrs->x_op == XDR_ENCODE) {
1697c478bd9Sstevel@tonic-gate #if defined(_LITTLE_ENDIAN)
1707c478bd9Sstevel@tonic-gate 		if (XDR_PUTINT32(xdrs, (int32_t *)((char *)hp +
1717c478bd9Sstevel@tonic-gate 		    BYTES_PER_XDR_UNIT)) == TRUE) {
1727c478bd9Sstevel@tonic-gate 			return (XDR_PUTINT32(xdrs, (int32_t *)hp));
1737c478bd9Sstevel@tonic-gate 		}
1747c478bd9Sstevel@tonic-gate #elif defined(_BIG_ENDIAN)
1757c478bd9Sstevel@tonic-gate 		if (XDR_PUTINT32(xdrs, (int32_t *)hp) == TRUE) {
1767c478bd9Sstevel@tonic-gate 			return (XDR_PUTINT32(xdrs, (int32_t *)((char *)hp +
1777c478bd9Sstevel@tonic-gate 			    BYTES_PER_XDR_UNIT)));
1787c478bd9Sstevel@tonic-gate 		}
1797c478bd9Sstevel@tonic-gate #endif
1807c478bd9Sstevel@tonic-gate 		return (FALSE);
1817c478bd9Sstevel@tonic-gate 
1827c478bd9Sstevel@tonic-gate 	}
1837c478bd9Sstevel@tonic-gate 	if (xdrs->x_op == XDR_DECODE) {
1847c478bd9Sstevel@tonic-gate #if defined(_LITTLE_ENDIAN)
1857c478bd9Sstevel@tonic-gate 		if (XDR_GETINT32(xdrs, (int32_t *)((char *)hp +
1867c478bd9Sstevel@tonic-gate 		    BYTES_PER_XDR_UNIT)) == TRUE) {
1877c478bd9Sstevel@tonic-gate 			return (XDR_GETINT32(xdrs, (int32_t *)hp));
1887c478bd9Sstevel@tonic-gate 		}
1897c478bd9Sstevel@tonic-gate #elif defined(_BIG_ENDIAN)
1907c478bd9Sstevel@tonic-gate 		if (XDR_GETINT32(xdrs, (int32_t *)hp) == TRUE) {
1917c478bd9Sstevel@tonic-gate 			return (XDR_GETINT32(xdrs, (int32_t *)((char *)hp +
1927c478bd9Sstevel@tonic-gate 			    BYTES_PER_XDR_UNIT)));
1937c478bd9Sstevel@tonic-gate 		}
1947c478bd9Sstevel@tonic-gate #endif
1957c478bd9Sstevel@tonic-gate 		return (FALSE);
1967c478bd9Sstevel@tonic-gate 	}
1977c478bd9Sstevel@tonic-gate 	return (TRUE);
1987c478bd9Sstevel@tonic-gate }
1997c478bd9Sstevel@tonic-gate 
2007c478bd9Sstevel@tonic-gate /*
2017c478bd9Sstevel@tonic-gate  * XDR unsigned long long integers
2027c478bd9Sstevel@tonic-gate  */
2037c478bd9Sstevel@tonic-gate bool_t
xdr_u_longlong_t(XDR * xdrs,u_longlong_t * hp)2047c478bd9Sstevel@tonic-gate xdr_u_longlong_t(XDR *xdrs, u_longlong_t *hp)
2057c478bd9Sstevel@tonic-gate {
2067c478bd9Sstevel@tonic-gate 
2077c478bd9Sstevel@tonic-gate 	if (xdrs->x_op == XDR_ENCODE) {
2087c478bd9Sstevel@tonic-gate #if defined(_LITTLE_ENDIAN)
2097c478bd9Sstevel@tonic-gate 		if (XDR_PUTINT32(xdrs, (int32_t *)((char *)hp +
2107c478bd9Sstevel@tonic-gate 		    BYTES_PER_XDR_UNIT)) == TRUE) {
2117c478bd9Sstevel@tonic-gate 			return (XDR_PUTINT32(xdrs, (int32_t *)hp));
2127c478bd9Sstevel@tonic-gate 		}
2137c478bd9Sstevel@tonic-gate #elif defined(_BIG_ENDIAN)
2147c478bd9Sstevel@tonic-gate 		if (XDR_PUTINT32(xdrs, (int32_t *)hp) == TRUE) {
2157c478bd9Sstevel@tonic-gate 			return (XDR_PUTINT32(xdrs, (int32_t *)((char *)hp +
2167c478bd9Sstevel@tonic-gate 			    BYTES_PER_XDR_UNIT)));
2177c478bd9Sstevel@tonic-gate 		}
2187c478bd9Sstevel@tonic-gate #endif
2197c478bd9Sstevel@tonic-gate 		return (FALSE);
2207c478bd9Sstevel@tonic-gate 
2217c478bd9Sstevel@tonic-gate 	}
2227c478bd9Sstevel@tonic-gate 	if (xdrs->x_op == XDR_DECODE) {
2237c478bd9Sstevel@tonic-gate #if defined(_LITTLE_ENDIAN)
2247c478bd9Sstevel@tonic-gate 		if (XDR_GETINT32(xdrs, (int32_t *)((char *)hp +
2257c478bd9Sstevel@tonic-gate 		    BYTES_PER_XDR_UNIT)) == TRUE) {
2267c478bd9Sstevel@tonic-gate 			return (XDR_GETINT32(xdrs, (int32_t *)hp));
2277c478bd9Sstevel@tonic-gate 		}
2287c478bd9Sstevel@tonic-gate #elif defined(_BIG_ENDIAN)
2297c478bd9Sstevel@tonic-gate 		if (XDR_GETINT32(xdrs, (int32_t *)hp) == TRUE) {
2307c478bd9Sstevel@tonic-gate 			return (XDR_GETINT32(xdrs, (int32_t *)((char *)hp +
2317c478bd9Sstevel@tonic-gate 			    BYTES_PER_XDR_UNIT)));
2327c478bd9Sstevel@tonic-gate 		}
2337c478bd9Sstevel@tonic-gate #endif
2347c478bd9Sstevel@tonic-gate 		return (FALSE);
2357c478bd9Sstevel@tonic-gate 	}
2367c478bd9Sstevel@tonic-gate 	return (TRUE);
2377c478bd9Sstevel@tonic-gate }
2387c478bd9Sstevel@tonic-gate 
2397c478bd9Sstevel@tonic-gate /*
2407c478bd9Sstevel@tonic-gate  * XDR short integers
2417c478bd9Sstevel@tonic-gate  */
2427c478bd9Sstevel@tonic-gate bool_t
xdr_short(XDR * xdrs,short * sp)2437c478bd9Sstevel@tonic-gate xdr_short(XDR *xdrs, short *sp)
2447c478bd9Sstevel@tonic-gate {
2457c478bd9Sstevel@tonic-gate 	int32_t l;
2467c478bd9Sstevel@tonic-gate 
2477c478bd9Sstevel@tonic-gate 	switch (xdrs->x_op) {
2487c478bd9Sstevel@tonic-gate 
2497c478bd9Sstevel@tonic-gate 	case XDR_ENCODE:
2507c478bd9Sstevel@tonic-gate 		l = (int32_t)*sp;
2517c478bd9Sstevel@tonic-gate 		return (XDR_PUTINT32(xdrs, &l));
2527c478bd9Sstevel@tonic-gate 
2537c478bd9Sstevel@tonic-gate 	case XDR_DECODE:
2547c478bd9Sstevel@tonic-gate 		if (!XDR_GETINT32(xdrs, &l))
2557c478bd9Sstevel@tonic-gate 			return (FALSE);
2567c478bd9Sstevel@tonic-gate 		*sp = (short)l;
2577c478bd9Sstevel@tonic-gate 		return (TRUE);
2587c478bd9Sstevel@tonic-gate 
2597c478bd9Sstevel@tonic-gate 	case XDR_FREE:
2607c478bd9Sstevel@tonic-gate 		return (TRUE);
2617c478bd9Sstevel@tonic-gate 	}
2627c478bd9Sstevel@tonic-gate 	return (FALSE);
2637c478bd9Sstevel@tonic-gate }
2647c478bd9Sstevel@tonic-gate 
2657c478bd9Sstevel@tonic-gate /*
2667c478bd9Sstevel@tonic-gate  * XDR unsigned short integers
2677c478bd9Sstevel@tonic-gate  */
2687c478bd9Sstevel@tonic-gate bool_t
xdr_u_short(XDR * xdrs,ushort_t * usp)2697c478bd9Sstevel@tonic-gate xdr_u_short(XDR *xdrs, ushort_t *usp)
2707c478bd9Sstevel@tonic-gate {
2717c478bd9Sstevel@tonic-gate 	uint32_t l;
2727c478bd9Sstevel@tonic-gate 
2737c478bd9Sstevel@tonic-gate 	switch (xdrs->x_op) {
2747c478bd9Sstevel@tonic-gate 
2757c478bd9Sstevel@tonic-gate 	case XDR_ENCODE:
2767c478bd9Sstevel@tonic-gate 		l = (uint32_t)*usp;
2777c478bd9Sstevel@tonic-gate 		return (XDR_PUTINT32(xdrs, (int32_t *)&l));
2787c478bd9Sstevel@tonic-gate 
2797c478bd9Sstevel@tonic-gate 	case XDR_DECODE:
2807c478bd9Sstevel@tonic-gate 		if (!XDR_GETINT32(xdrs, (int32_t *)&l)) {
2817c478bd9Sstevel@tonic-gate 			return (FALSE);
2827c478bd9Sstevel@tonic-gate 		}
2837c478bd9Sstevel@tonic-gate 		*usp = (ushort_t)l;
2847c478bd9Sstevel@tonic-gate 		return (TRUE);
2857c478bd9Sstevel@tonic-gate 
2867c478bd9Sstevel@tonic-gate 	case XDR_FREE:
2877c478bd9Sstevel@tonic-gate 		return (TRUE);
2887c478bd9Sstevel@tonic-gate 	}
2897c478bd9Sstevel@tonic-gate 	return (FALSE);
2907c478bd9Sstevel@tonic-gate }
2917c478bd9Sstevel@tonic-gate 
2927c478bd9Sstevel@tonic-gate 
2937c478bd9Sstevel@tonic-gate /*
2947c478bd9Sstevel@tonic-gate  * XDR a char
2957c478bd9Sstevel@tonic-gate  */
2967c478bd9Sstevel@tonic-gate bool_t
xdr_char(XDR * xdrs,char * cp)2977c478bd9Sstevel@tonic-gate xdr_char(XDR *xdrs, char *cp)
2987c478bd9Sstevel@tonic-gate {
2997c478bd9Sstevel@tonic-gate 	int i;
3007c478bd9Sstevel@tonic-gate 
3017c478bd9Sstevel@tonic-gate 	i = (*cp);
3027c478bd9Sstevel@tonic-gate 	if (!xdr_int(xdrs, &i)) {
3037c478bd9Sstevel@tonic-gate 		return (FALSE);
3047c478bd9Sstevel@tonic-gate 	}
3057c478bd9Sstevel@tonic-gate 	*cp = (char)i;
3067c478bd9Sstevel@tonic-gate 	return (TRUE);
3077c478bd9Sstevel@tonic-gate }
3087c478bd9Sstevel@tonic-gate 
3097c478bd9Sstevel@tonic-gate /*
310*1fcced4cSJordan Brown  * XDR an unsigned char
311*1fcced4cSJordan Brown  */
312*1fcced4cSJordan Brown bool_t
xdr_u_char(XDR * xdrs,uchar_t * cp)313*1fcced4cSJordan Brown xdr_u_char(XDR *xdrs, uchar_t *cp)
314*1fcced4cSJordan Brown {
315*1fcced4cSJordan Brown 	int i;
316*1fcced4cSJordan Brown 
317*1fcced4cSJordan Brown 	switch (xdrs->x_op) {
318*1fcced4cSJordan Brown 	case XDR_ENCODE:
319*1fcced4cSJordan Brown 		i = (*cp);
320*1fcced4cSJordan Brown 		return (XDR_PUTINT32(xdrs, &i));
321*1fcced4cSJordan Brown 	case XDR_DECODE:
322*1fcced4cSJordan Brown 		if (!XDR_GETINT32(xdrs, &i))
323*1fcced4cSJordan Brown 			return (FALSE);
324*1fcced4cSJordan Brown 		*cp = (uchar_t)i;
325*1fcced4cSJordan Brown 		return (TRUE);
326*1fcced4cSJordan Brown 	case XDR_FREE:
327*1fcced4cSJordan Brown 		return (TRUE);
328*1fcced4cSJordan Brown 	}
329*1fcced4cSJordan Brown 	return (FALSE);
330*1fcced4cSJordan Brown }
331*1fcced4cSJordan Brown 
332*1fcced4cSJordan Brown /*
3337c478bd9Sstevel@tonic-gate  * XDR booleans
3347c478bd9Sstevel@tonic-gate  *
3357c478bd9Sstevel@tonic-gate  * PSARC 2003/523 Contract Private Interface
3367c478bd9Sstevel@tonic-gate  * xdr_bool
3377c478bd9Sstevel@tonic-gate  * Changes must be reviewed by Solaris File Sharing
3387c478bd9Sstevel@tonic-gate  * Changes must be communicated to contract-2003-523@sun.com
3397c478bd9Sstevel@tonic-gate  */
3407c478bd9Sstevel@tonic-gate bool_t
xdr_bool(XDR * xdrs,bool_t * bp)3417c478bd9Sstevel@tonic-gate xdr_bool(XDR *xdrs, bool_t *bp)
3427c478bd9Sstevel@tonic-gate {
3437c478bd9Sstevel@tonic-gate 	int32_t i32b;
3447c478bd9Sstevel@tonic-gate 
3457c478bd9Sstevel@tonic-gate 	switch (xdrs->x_op) {
3467c478bd9Sstevel@tonic-gate 
3477c478bd9Sstevel@tonic-gate 	case XDR_ENCODE:
3487c478bd9Sstevel@tonic-gate 		i32b = *bp ? XDR_TRUE : XDR_FALSE;
3497c478bd9Sstevel@tonic-gate 		return (XDR_PUTINT32(xdrs, &i32b));
3507c478bd9Sstevel@tonic-gate 
3517c478bd9Sstevel@tonic-gate 	case XDR_DECODE:
3527c478bd9Sstevel@tonic-gate 		if (!XDR_GETINT32(xdrs, &i32b)) {
3537c478bd9Sstevel@tonic-gate 			return (FALSE);
3547c478bd9Sstevel@tonic-gate 		}
3557c478bd9Sstevel@tonic-gate 		*bp = (i32b == XDR_FALSE) ? FALSE : TRUE;
3567c478bd9Sstevel@tonic-gate 		return (TRUE);
3577c478bd9Sstevel@tonic-gate 
3587c478bd9Sstevel@tonic-gate 	case XDR_FREE:
3597c478bd9Sstevel@tonic-gate 		return (TRUE);
3607c478bd9Sstevel@tonic-gate 	}
3617c478bd9Sstevel@tonic-gate 	return (FALSE);
3627c478bd9Sstevel@tonic-gate }
3637c478bd9Sstevel@tonic-gate 
3647c478bd9Sstevel@tonic-gate /*
3657c478bd9Sstevel@tonic-gate  * XDR enumerations
3667c478bd9Sstevel@tonic-gate  *
3677c478bd9Sstevel@tonic-gate  * PSARC 2003/523 Contract Private Interface
3687c478bd9Sstevel@tonic-gate  * xdr_enum
3697c478bd9Sstevel@tonic-gate  * Changes must be reviewed by Solaris File Sharing
3707c478bd9Sstevel@tonic-gate  * Changes must be communicated to contract-2003-523@sun.com
3717c478bd9Sstevel@tonic-gate  */
3727c478bd9Sstevel@tonic-gate #ifndef lint
3737c478bd9Sstevel@tonic-gate enum sizecheck { SIZEVAL } sizecheckvar;	/* used to find the size of */
3747c478bd9Sstevel@tonic-gate 						/* an enum */
3757c478bd9Sstevel@tonic-gate #endif
3767c478bd9Sstevel@tonic-gate bool_t
xdr_enum(XDR * xdrs,enum_t * ep)3777c478bd9Sstevel@tonic-gate xdr_enum(XDR *xdrs, enum_t *ep)
3787c478bd9Sstevel@tonic-gate {
3797c478bd9Sstevel@tonic-gate #ifndef lint
3807c478bd9Sstevel@tonic-gate 	/*
3817c478bd9Sstevel@tonic-gate 	 * enums are treated as ints
3827c478bd9Sstevel@tonic-gate 	 */
3837c478bd9Sstevel@tonic-gate 	if (sizeof (sizecheckvar) == sizeof (int32_t)) {
3847c478bd9Sstevel@tonic-gate 		return (xdr_int(xdrs, (int32_t *)ep));
3857c478bd9Sstevel@tonic-gate 	} else if (sizeof (sizecheckvar) == sizeof (short)) {
3867c478bd9Sstevel@tonic-gate 		return (xdr_short(xdrs, (short *)ep));
3877c478bd9Sstevel@tonic-gate 	} else {
3887c478bd9Sstevel@tonic-gate 		return (FALSE);
3897c478bd9Sstevel@tonic-gate 	}
3907c478bd9Sstevel@tonic-gate #else
3917c478bd9Sstevel@tonic-gate 	(void) (xdr_short(xdrs, (short *)ep));
3927c478bd9Sstevel@tonic-gate 	return (xdr_int(xdrs, (int32_t *)ep));
3937c478bd9Sstevel@tonic-gate #endif
3947c478bd9Sstevel@tonic-gate }
3957c478bd9Sstevel@tonic-gate 
3967c478bd9Sstevel@tonic-gate /*
3977c478bd9Sstevel@tonic-gate  * XDR opaque data
3987c478bd9Sstevel@tonic-gate  * Allows the specification of a fixed size sequence of opaque bytes.
3997c478bd9Sstevel@tonic-gate  * cp points to the opaque object and cnt gives the byte length.
4007c478bd9Sstevel@tonic-gate  *
4017c478bd9Sstevel@tonic-gate  * PSARC 2003/523 Contract Private Interface
4027c478bd9Sstevel@tonic-gate  * xdr_opaque
4037c478bd9Sstevel@tonic-gate  * Changes must be reviewed by Solaris File Sharing
4047c478bd9Sstevel@tonic-gate  * Changes must be communicated to contract-2003-523@sun.com
4057c478bd9Sstevel@tonic-gate  */
4067c478bd9Sstevel@tonic-gate bool_t
xdr_opaque(XDR * xdrs,caddr_t cp,const uint_t cnt)4077c478bd9Sstevel@tonic-gate xdr_opaque(XDR *xdrs, caddr_t cp, const uint_t cnt)
4087c478bd9Sstevel@tonic-gate {
4097c478bd9Sstevel@tonic-gate 	uint_t rndup;
4107c478bd9Sstevel@tonic-gate 	static char crud[BYTES_PER_XDR_UNIT];
4117c478bd9Sstevel@tonic-gate 
4127c478bd9Sstevel@tonic-gate 	/*
4137c478bd9Sstevel@tonic-gate 	 * if no data we are done
4147c478bd9Sstevel@tonic-gate 	 */
4157c478bd9Sstevel@tonic-gate 	if (cnt == 0)
4167c478bd9Sstevel@tonic-gate 		return (TRUE);
4177c478bd9Sstevel@tonic-gate 
4187c478bd9Sstevel@tonic-gate 	/*
4197c478bd9Sstevel@tonic-gate 	 * round byte count to full xdr units
4207c478bd9Sstevel@tonic-gate 	 */
4217c478bd9Sstevel@tonic-gate 	rndup = cnt % BYTES_PER_XDR_UNIT;
4227c478bd9Sstevel@tonic-gate 	if (rndup != 0)
4237c478bd9Sstevel@tonic-gate 		rndup = BYTES_PER_XDR_UNIT - rndup;
4247c478bd9Sstevel@tonic-gate 
4257c478bd9Sstevel@tonic-gate 	if (xdrs->x_op == XDR_DECODE) {
4267c478bd9Sstevel@tonic-gate 		if (!XDR_GETBYTES(xdrs, cp, cnt)) {
4277c478bd9Sstevel@tonic-gate 			return (FALSE);
4287c478bd9Sstevel@tonic-gate 		}
4297c478bd9Sstevel@tonic-gate 		if (rndup == 0)
4307c478bd9Sstevel@tonic-gate 			return (TRUE);
4317c478bd9Sstevel@tonic-gate 		return (XDR_GETBYTES(xdrs, (caddr_t)crud, rndup));
4327c478bd9Sstevel@tonic-gate 	}
4337c478bd9Sstevel@tonic-gate 
4347c478bd9Sstevel@tonic-gate 	if (xdrs->x_op == XDR_ENCODE) {
4357c478bd9Sstevel@tonic-gate 		if (!XDR_PUTBYTES(xdrs, cp, cnt)) {
4367c478bd9Sstevel@tonic-gate 			return (FALSE);
4377c478bd9Sstevel@tonic-gate 		}
4387c478bd9Sstevel@tonic-gate 		if (rndup == 0)
4397c478bd9Sstevel@tonic-gate 			return (TRUE);
4407c478bd9Sstevel@tonic-gate 		return (XDR_PUTBYTES(xdrs, xdr_zero, rndup));
4417c478bd9Sstevel@tonic-gate 	}
4427c478bd9Sstevel@tonic-gate 
4437c478bd9Sstevel@tonic-gate 	if (xdrs->x_op == XDR_FREE)
4447c478bd9Sstevel@tonic-gate 		return (TRUE);
4457c478bd9Sstevel@tonic-gate 
4467c478bd9Sstevel@tonic-gate 	return (FALSE);
4477c478bd9Sstevel@tonic-gate }
4487c478bd9Sstevel@tonic-gate 
4497c478bd9Sstevel@tonic-gate /*
4507c478bd9Sstevel@tonic-gate  * XDR counted bytes
4517c478bd9Sstevel@tonic-gate  * *cpp is a pointer to the bytes, *sizep is the count.
4527c478bd9Sstevel@tonic-gate  * If *cpp is NULL maxsize bytes are allocated
4537c478bd9Sstevel@tonic-gate  *
4547c478bd9Sstevel@tonic-gate  * PSARC 2003/523 Contract Private Interface
4557c478bd9Sstevel@tonic-gate  * xdr_bytes
4567c478bd9Sstevel@tonic-gate  * Changes must be reviewed by Solaris File Sharing
4577c478bd9Sstevel@tonic-gate  * Changes must be communicated to contract-2003-523@sun.com
4587c478bd9Sstevel@tonic-gate  */
4597c478bd9Sstevel@tonic-gate bool_t
xdr_bytes(XDR * xdrs,char ** cpp,uint_t * sizep,const uint_t maxsize)4607c478bd9Sstevel@tonic-gate xdr_bytes(XDR *xdrs, char **cpp, uint_t *sizep, const uint_t maxsize)
4617c478bd9Sstevel@tonic-gate {
4627c478bd9Sstevel@tonic-gate 	char *sp = *cpp;  /* sp is the actual string pointer */
4637c478bd9Sstevel@tonic-gate 	uint_t nodesize;
4647c478bd9Sstevel@tonic-gate 
4657c478bd9Sstevel@tonic-gate 	/*
4667c478bd9Sstevel@tonic-gate 	 * first deal with the length since xdr bytes are counted
4677c478bd9Sstevel@tonic-gate 	 */
4687c478bd9Sstevel@tonic-gate 	if (!xdr_u_int(xdrs, sizep)) {
4697c478bd9Sstevel@tonic-gate 		return (FALSE);
4707c478bd9Sstevel@tonic-gate 	}
4717c478bd9Sstevel@tonic-gate 	nodesize = *sizep;
4727c478bd9Sstevel@tonic-gate 	if ((nodesize > maxsize) && (xdrs->x_op != XDR_FREE)) {
4737c478bd9Sstevel@tonic-gate 		return (FALSE);
4747c478bd9Sstevel@tonic-gate 	}
4757c478bd9Sstevel@tonic-gate 
4767c478bd9Sstevel@tonic-gate 	/*
4777c478bd9Sstevel@tonic-gate 	 * now deal with the actual bytes
4787c478bd9Sstevel@tonic-gate 	 */
4797c478bd9Sstevel@tonic-gate 	switch (xdrs->x_op) {
4807c478bd9Sstevel@tonic-gate 	case XDR_DECODE:
4817c478bd9Sstevel@tonic-gate 		if (nodesize == 0)
4827c478bd9Sstevel@tonic-gate 			return (TRUE);
4837c478bd9Sstevel@tonic-gate 		if (sp == NULL)
4847c478bd9Sstevel@tonic-gate 			*cpp = sp = (char *)mem_alloc(nodesize);
4857c478bd9Sstevel@tonic-gate 		/* FALLTHROUGH */
4867c478bd9Sstevel@tonic-gate 
4877c478bd9Sstevel@tonic-gate 	case XDR_ENCODE:
4887c478bd9Sstevel@tonic-gate 		return (xdr_opaque(xdrs, sp, nodesize));
4897c478bd9Sstevel@tonic-gate 
4907c478bd9Sstevel@tonic-gate 	case XDR_FREE:
4917c478bd9Sstevel@tonic-gate 		if (sp != NULL) {
4927c478bd9Sstevel@tonic-gate 			mem_free(sp, nodesize);
4937c478bd9Sstevel@tonic-gate 			*cpp = NULL;
4947c478bd9Sstevel@tonic-gate 		}
4957c478bd9Sstevel@tonic-gate 		return (TRUE);
4967c478bd9Sstevel@tonic-gate 	}
4977c478bd9Sstevel@tonic-gate 	return (FALSE);
4987c478bd9Sstevel@tonic-gate }
4997c478bd9Sstevel@tonic-gate 
5007c478bd9Sstevel@tonic-gate /*
5017c478bd9Sstevel@tonic-gate  * Implemented here due to commonality of the object.
5027c478bd9Sstevel@tonic-gate  */
5037c478bd9Sstevel@tonic-gate bool_t
xdr_netobj(XDR * xdrs,struct netobj * np)5047c478bd9Sstevel@tonic-gate xdr_netobj(XDR *xdrs, struct netobj *np)
5057c478bd9Sstevel@tonic-gate {
5067c478bd9Sstevel@tonic-gate 	return (xdr_bytes(xdrs, &np->n_bytes, &np->n_len, MAX_NETOBJ_SZ));
5077c478bd9Sstevel@tonic-gate }
5087c478bd9Sstevel@tonic-gate 
5097c478bd9Sstevel@tonic-gate /*
5107c478bd9Sstevel@tonic-gate  * XDR a descriminated union
5117c478bd9Sstevel@tonic-gate  * Support routine for discriminated unions.
5127c478bd9Sstevel@tonic-gate  * You create an array of xdrdiscrim structures, terminated with
5137c478bd9Sstevel@tonic-gate  * an entry with a null procedure pointer.  The routine gets
5147c478bd9Sstevel@tonic-gate  * the discriminant value and then searches the array of xdrdiscrims
5157c478bd9Sstevel@tonic-gate  * looking for that value.  It calls the procedure given in the xdrdiscrim
5167c478bd9Sstevel@tonic-gate  * to handle the discriminant.  If there is no specific routine a default
5177c478bd9Sstevel@tonic-gate  * routine may be called.
5187c478bd9Sstevel@tonic-gate  * If there is no specific or default routine an error is returned.
5197c478bd9Sstevel@tonic-gate  */
5207c478bd9Sstevel@tonic-gate bool_t
xdr_union(XDR * xdrs,enum_t * dscmp,char * unp,const struct xdr_discrim * choices,const xdrproc_t dfault)5217c478bd9Sstevel@tonic-gate xdr_union(XDR *xdrs, enum_t *dscmp, char *unp,
5227c478bd9Sstevel@tonic-gate 	const struct xdr_discrim *choices, const xdrproc_t dfault)
5237c478bd9Sstevel@tonic-gate {
5247c478bd9Sstevel@tonic-gate 	enum_t dscm;
5257c478bd9Sstevel@tonic-gate 
5267c478bd9Sstevel@tonic-gate 	/*
5277c478bd9Sstevel@tonic-gate 	 * we deal with the discriminator;  it's an enum
5287c478bd9Sstevel@tonic-gate 	 */
5297c478bd9Sstevel@tonic-gate 	if (!xdr_enum(xdrs, dscmp)) {
5307c478bd9Sstevel@tonic-gate 		return (FALSE);
5317c478bd9Sstevel@tonic-gate 	}
5327c478bd9Sstevel@tonic-gate 	dscm = *dscmp;
5337c478bd9Sstevel@tonic-gate 
5347c478bd9Sstevel@tonic-gate 	/*
5357c478bd9Sstevel@tonic-gate 	 * search choices for a value that matches the discriminator.
5367c478bd9Sstevel@tonic-gate 	 * if we find one, execute the xdr routine for that value.
5377c478bd9Sstevel@tonic-gate 	 */
5387c478bd9Sstevel@tonic-gate 	for (; choices->proc != NULL_xdrproc_t; choices++) {
5397c478bd9Sstevel@tonic-gate 		if (choices->value == dscm)
5407c478bd9Sstevel@tonic-gate 			return ((*(choices->proc))(xdrs, unp, LASTUNSIGNED));
5417c478bd9Sstevel@tonic-gate 	}
5427c478bd9Sstevel@tonic-gate 
5437c478bd9Sstevel@tonic-gate 	/*
5447c478bd9Sstevel@tonic-gate 	 * no match - execute the default xdr routine if there is one
5457c478bd9Sstevel@tonic-gate 	 */
5467c478bd9Sstevel@tonic-gate 	return ((dfault == NULL_xdrproc_t) ? FALSE :
5477c478bd9Sstevel@tonic-gate 	    (*dfault)(xdrs, unp, LASTUNSIGNED));
5487c478bd9Sstevel@tonic-gate }
5497c478bd9Sstevel@tonic-gate 
5507c478bd9Sstevel@tonic-gate 
5517c478bd9Sstevel@tonic-gate /*
5527c478bd9Sstevel@tonic-gate  * Non-portable xdr primitives.
5537c478bd9Sstevel@tonic-gate  * Care should be taken when moving these routines to new architectures.
5547c478bd9Sstevel@tonic-gate  */
5557c478bd9Sstevel@tonic-gate 
5567c478bd9Sstevel@tonic-gate 
5577c478bd9Sstevel@tonic-gate /*
5587c478bd9Sstevel@tonic-gate  * XDR null terminated ASCII strings
5597c478bd9Sstevel@tonic-gate  * xdr_string deals with "C strings" - arrays of bytes that are
5607c478bd9Sstevel@tonic-gate  * terminated by a NULL character.  The parameter cpp references a
5617c478bd9Sstevel@tonic-gate  * pointer to storage; If the pointer is null, then the necessary
5627c478bd9Sstevel@tonic-gate  * storage is allocated.  The last parameter is the max allowed length
5637c478bd9Sstevel@tonic-gate  * of the string as specified by a protocol.
5647c478bd9Sstevel@tonic-gate  */
5657c478bd9Sstevel@tonic-gate bool_t
xdr_string(XDR * xdrs,char ** cpp,const uint_t maxsize)5667c478bd9Sstevel@tonic-gate xdr_string(XDR *xdrs, char **cpp, const uint_t maxsize)
5677c478bd9Sstevel@tonic-gate {
5687c478bd9Sstevel@tonic-gate 	char *sp = *cpp;  /* sp is the actual string pointer */
5697c478bd9Sstevel@tonic-gate 	uint_t size;
5707c478bd9Sstevel@tonic-gate 	uint_t nodesize;
5717c478bd9Sstevel@tonic-gate 
5727c478bd9Sstevel@tonic-gate 	/*
5737c478bd9Sstevel@tonic-gate 	 * first deal with the length since xdr strings are counted-strings
5747c478bd9Sstevel@tonic-gate 	 */
5757c478bd9Sstevel@tonic-gate 	switch (xdrs->x_op) {
5767c478bd9Sstevel@tonic-gate 	case XDR_FREE:
5777c478bd9Sstevel@tonic-gate 		if (sp == NULL)
5787c478bd9Sstevel@tonic-gate 			return (TRUE);	/* already free */
5797c478bd9Sstevel@tonic-gate 		/* FALLTHROUGH */
5807c478bd9Sstevel@tonic-gate 	case XDR_ENCODE:
5817c478bd9Sstevel@tonic-gate 		size = (sp != NULL) ? (uint_t)strlen(sp) : 0;
5827c478bd9Sstevel@tonic-gate 		break;
5837c478bd9Sstevel@tonic-gate 	case XDR_DECODE:
5847c478bd9Sstevel@tonic-gate 		break;
5857c478bd9Sstevel@tonic-gate 	}
5867c478bd9Sstevel@tonic-gate 	if (!xdr_u_int(xdrs, &size)) {
5877c478bd9Sstevel@tonic-gate 		return (FALSE);
5887c478bd9Sstevel@tonic-gate 	}
5897c478bd9Sstevel@tonic-gate 	if (size > maxsize) {
5907c478bd9Sstevel@tonic-gate 		return (FALSE);
5917c478bd9Sstevel@tonic-gate 	}
5927c478bd9Sstevel@tonic-gate 	nodesize = size + 1;
5937c478bd9Sstevel@tonic-gate 
5947c478bd9Sstevel@tonic-gate 	/*
5957c478bd9Sstevel@tonic-gate 	 * now deal with the actual bytes
5967c478bd9Sstevel@tonic-gate 	 */
5977c478bd9Sstevel@tonic-gate 	switch (xdrs->x_op) {
5987c478bd9Sstevel@tonic-gate 	case XDR_DECODE:
5997c478bd9Sstevel@tonic-gate 		if (nodesize == 0)
6007c478bd9Sstevel@tonic-gate 			return (TRUE);
6017c478bd9Sstevel@tonic-gate 		if (sp == NULL)
6027c478bd9Sstevel@tonic-gate 			sp = (char *)mem_alloc(nodesize);
6037c478bd9Sstevel@tonic-gate 		sp[size] = 0;
6047c478bd9Sstevel@tonic-gate 		if (!xdr_opaque(xdrs, sp, size)) {
6057c478bd9Sstevel@tonic-gate 			/*
6067c478bd9Sstevel@tonic-gate 			 * free up memory if allocated here
6077c478bd9Sstevel@tonic-gate 			 */
6087c478bd9Sstevel@tonic-gate 			if (*cpp == NULL) {
6097c478bd9Sstevel@tonic-gate 				mem_free(sp, nodesize);
6107c478bd9Sstevel@tonic-gate 			}
6117c478bd9Sstevel@tonic-gate 			return (FALSE);
6127c478bd9Sstevel@tonic-gate 		}
6137c478bd9Sstevel@tonic-gate 		if (strlen(sp) != size) {
6147c478bd9Sstevel@tonic-gate 			if (*cpp == NULL) {
6157c478bd9Sstevel@tonic-gate 				mem_free(sp, nodesize);
6167c478bd9Sstevel@tonic-gate 			}
6177c478bd9Sstevel@tonic-gate 			return (FALSE);
6187c478bd9Sstevel@tonic-gate 		}
6197c478bd9Sstevel@tonic-gate 		*cpp = sp;
6207c478bd9Sstevel@tonic-gate 		return (TRUE);
6217c478bd9Sstevel@tonic-gate 
6227c478bd9Sstevel@tonic-gate 	case XDR_ENCODE:
6237c478bd9Sstevel@tonic-gate 		return (xdr_opaque(xdrs, sp, size));
6247c478bd9Sstevel@tonic-gate 
6257c478bd9Sstevel@tonic-gate 	case XDR_FREE:
6267c478bd9Sstevel@tonic-gate 		mem_free(sp, nodesize);
6277c478bd9Sstevel@tonic-gate 		*cpp = NULL;
6287c478bd9Sstevel@tonic-gate 		return (TRUE);
6297c478bd9Sstevel@tonic-gate 	}
6307c478bd9Sstevel@tonic-gate 	return (FALSE);
6317c478bd9Sstevel@tonic-gate }
6327c478bd9Sstevel@tonic-gate 
6337c478bd9Sstevel@tonic-gate /*
634*1fcced4cSJordan Brown  * xdr_vector():
635*1fcced4cSJordan Brown  *
636*1fcced4cSJordan Brown  * XDR a fixed length array. Unlike variable-length arrays, the storage
637*1fcced4cSJordan Brown  * of fixed length arrays is static and unfreeable.
638*1fcced4cSJordan Brown  * > basep: base of the array
639*1fcced4cSJordan Brown  * > size: size of the array
640*1fcced4cSJordan Brown  * > elemsize: size of each element
641*1fcced4cSJordan Brown  * > xdr_elem: routine to XDR each element
642*1fcced4cSJordan Brown  */
643*1fcced4cSJordan Brown bool_t
xdr_vector(XDR * xdrs,char * basep,const uint_t nelem,const uint_t elemsize,const xdrproc_t xdr_elem)644*1fcced4cSJordan Brown xdr_vector(XDR *xdrs, char *basep, const uint_t nelem,
645*1fcced4cSJordan Brown 	const uint_t elemsize, const xdrproc_t xdr_elem)
646*1fcced4cSJordan Brown {
647*1fcced4cSJordan Brown 	uint_t i;
648*1fcced4cSJordan Brown 	char *elptr;
649*1fcced4cSJordan Brown 
650*1fcced4cSJordan Brown 	elptr = basep;
651*1fcced4cSJordan Brown 	for (i = 0; i < nelem; i++) {
652*1fcced4cSJordan Brown 		if (!(*xdr_elem)(xdrs, elptr, LASTUNSIGNED))
653*1fcced4cSJordan Brown 			return (FALSE);
654*1fcced4cSJordan Brown 		elptr += elemsize;
655*1fcced4cSJordan Brown 	}
656*1fcced4cSJordan Brown 	return (TRUE);
657*1fcced4cSJordan Brown }
658*1fcced4cSJordan Brown 
659*1fcced4cSJordan Brown /*
6607c478bd9Sstevel@tonic-gate  * Wrapper for xdr_string that can be called directly from
6617c478bd9Sstevel@tonic-gate  * routines like clnt_call
6627c478bd9Sstevel@tonic-gate  */
6637c478bd9Sstevel@tonic-gate bool_t
xdr_wrapstring(XDR * xdrs,char ** cpp)6647c478bd9Sstevel@tonic-gate xdr_wrapstring(XDR *xdrs, char **cpp)
6657c478bd9Sstevel@tonic-gate {
6667c478bd9Sstevel@tonic-gate 	if (xdr_string(xdrs, cpp, LASTUNSIGNED))
6677c478bd9Sstevel@tonic-gate 		return (TRUE);
6687c478bd9Sstevel@tonic-gate 	return (FALSE);
6697c478bd9Sstevel@tonic-gate }
670