xref: /freebsd/include/rpc/xdr.h (revision 5a1d1441)
18360efbdSAlfred Perlstein /*	$NetBSD: xdr.h,v 1.19 2000/07/17 05:00:45 matt Exp $	*/
28360efbdSAlfred Perlstein 
32e322d37SHiroki Sato /*-
42321c474SPedro F. Giffuni  * SPDX-License-Identifier: BSD-3-Clause
52321c474SPedro F. Giffuni  *
62e322d37SHiroki Sato  * Copyright (c) 2009, Sun Microsystems, Inc.
72e322d37SHiroki Sato  * All rights reserved.
8dba7a33eSGarrett Wollman  *
92e322d37SHiroki Sato  * Redistribution and use in source and binary forms, with or without
102e322d37SHiroki Sato  * modification, are permitted provided that the following conditions are met:
112e322d37SHiroki Sato  * - Redistributions of source code must retain the above copyright notice,
122e322d37SHiroki Sato  *   this list of conditions and the following disclaimer.
132e322d37SHiroki Sato  * - Redistributions in binary form must reproduce the above copyright notice,
142e322d37SHiroki Sato  *   this list of conditions and the following disclaimer in the documentation
152e322d37SHiroki Sato  *   and/or other materials provided with the distribution.
162e322d37SHiroki Sato  * - Neither the name of Sun Microsystems, Inc. nor the names of its
172e322d37SHiroki Sato  *   contributors may be used to endorse or promote products derived
182e322d37SHiroki Sato  *   from this software without specific prior written permission.
19dba7a33eSGarrett Wollman  *
202e322d37SHiroki Sato  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
212e322d37SHiroki Sato  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
222e322d37SHiroki Sato  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
232e322d37SHiroki Sato  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
242e322d37SHiroki Sato  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
252e322d37SHiroki Sato  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
262e322d37SHiroki Sato  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
272e322d37SHiroki Sato  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
282e322d37SHiroki Sato  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
292e322d37SHiroki Sato  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
302e322d37SHiroki Sato  * POSSIBILITY OF SUCH DAMAGE.
31dba7a33eSGarrett Wollman  */
32dba7a33eSGarrett Wollman 
33dba7a33eSGarrett Wollman /*
34dba7a33eSGarrett Wollman  * xdr.h, External Data Representation Serialization Routines.
35dba7a33eSGarrett Wollman  *
36dba7a33eSGarrett Wollman  * Copyright (C) 1984, Sun Microsystems, Inc.
37dba7a33eSGarrett Wollman  */
38dba7a33eSGarrett Wollman 
3986b9a9ccSGarrett Wollman #ifndef _RPC_XDR_H
4086b9a9ccSGarrett Wollman #define _RPC_XDR_H
4186b9a9ccSGarrett Wollman #include <sys/cdefs.h>
42dba7a33eSGarrett Wollman 
43dba7a33eSGarrett Wollman /*
44dba7a33eSGarrett Wollman  * XDR provides a conventional way for converting between C data
45dba7a33eSGarrett Wollman  * types and an external bit-string representation.  Library supplied
46dba7a33eSGarrett Wollman  * routines provide for the conversion on built-in C data types.  These
47dba7a33eSGarrett Wollman  * routines and utility routines defined here are used to help implement
48dba7a33eSGarrett Wollman  * a type encode/decode routine for each user-defined type.
49dba7a33eSGarrett Wollman  *
50dba7a33eSGarrett Wollman  * Each data type provides a single procedure which takes two arguments:
51dba7a33eSGarrett Wollman  *
52dba7a33eSGarrett Wollman  *	bool_t
53dba7a33eSGarrett Wollman  *	xdrproc(xdrs, argresp)
54dba7a33eSGarrett Wollman  *		XDR *xdrs;
55dba7a33eSGarrett Wollman  *		<type> *argresp;
56dba7a33eSGarrett Wollman  *
57dba7a33eSGarrett Wollman  * xdrs is an instance of a XDR handle, to which or from which the data
58dba7a33eSGarrett Wollman  * type is to be converted.  argresp is a pointer to the structure to be
59dba7a33eSGarrett Wollman  * converted.  The XDR handle contains an operation field which indicates
60dba7a33eSGarrett Wollman  * which of the operations (ENCODE, DECODE * or FREE) is to be performed.
61dba7a33eSGarrett Wollman  *
62dba7a33eSGarrett Wollman  * XDR_DECODE may allocate space if the pointer argresp is null.  This
63dba7a33eSGarrett Wollman  * data can be freed with the XDR_FREE operation.
64dba7a33eSGarrett Wollman  *
65dba7a33eSGarrett Wollman  * We write only one procedure per data type to make it easy
66dba7a33eSGarrett Wollman  * to keep the encode and decode procedures for a data type consistent.
67dba7a33eSGarrett Wollman  * In many cases the same code performs all operations on a user defined type,
68dba7a33eSGarrett Wollman  * because all the hard work is done in the component type routines.
69dba7a33eSGarrett Wollman  * decode as a series of calls on the nested data types.
70dba7a33eSGarrett Wollman  */
71dba7a33eSGarrett Wollman 
72dba7a33eSGarrett Wollman /*
73dba7a33eSGarrett Wollman  * Xdr operations.  XDR_ENCODE causes the type to be encoded into the
74dba7a33eSGarrett Wollman  * stream.  XDR_DECODE causes the type to be extracted from the stream.
75dba7a33eSGarrett Wollman  * XDR_FREE can be used to release the space allocated by an XDR_DECODE
76dba7a33eSGarrett Wollman  * request.
77dba7a33eSGarrett Wollman  */
78dba7a33eSGarrett Wollman enum xdr_op {
79dba7a33eSGarrett Wollman 	XDR_ENCODE=0,
80dba7a33eSGarrett Wollman 	XDR_DECODE=1,
81dba7a33eSGarrett Wollman 	XDR_FREE=2
82dba7a33eSGarrett Wollman };
83dba7a33eSGarrett Wollman 
84dba7a33eSGarrett Wollman /*
85dba7a33eSGarrett Wollman  * This is the number of bytes per unit of external data.
86dba7a33eSGarrett Wollman  */
87dba7a33eSGarrett Wollman #define BYTES_PER_XDR_UNIT	(4)
88dba7a33eSGarrett Wollman #define RNDUP(x)  ((((x) + BYTES_PER_XDR_UNIT - 1) / BYTES_PER_XDR_UNIT) \
89dba7a33eSGarrett Wollman 		    * BYTES_PER_XDR_UNIT)
90dba7a33eSGarrett Wollman 
91dba7a33eSGarrett Wollman /*
92dba7a33eSGarrett Wollman  * The XDR handle.
93dba7a33eSGarrett Wollman  * Contains operation which is being applied to the stream,
9471d9c781SMike Pritchard  * an operations vector for the particular implementation (e.g. see xdr_mem.c),
9571d9c781SMike Pritchard  * and two private fields for the use of the particular implementation.
96dba7a33eSGarrett Wollman  */
97370c6ad8SPedro F. Giffuni typedef struct XDR {
98dba7a33eSGarrett Wollman 	enum xdr_op	x_op;		/* operation; fast additional param */
998360efbdSAlfred Perlstein 	const struct xdr_ops {
10070de0abfSPeter Wemm 		/* get a long from underlying stream */
101370c6ad8SPedro F. Giffuni 		bool_t	(*x_getlong)(struct XDR *, long *);
1028360efbdSAlfred Perlstein 		/* put a long to " */
103370c6ad8SPedro F. Giffuni 		bool_t	(*x_putlong)(struct XDR *, const long *);
1048360efbdSAlfred Perlstein 		/* get some bytes from " */
105370c6ad8SPedro F. Giffuni 		bool_t	(*x_getbytes)(struct XDR *, char *, u_int);
1068360efbdSAlfred Perlstein 		/* put some bytes to " */
107370c6ad8SPedro F. Giffuni 		bool_t	(*x_putbytes)(struct XDR *, const char *, u_int);
10870de0abfSPeter Wemm 		/* returns bytes off from beginning */
109370c6ad8SPedro F. Giffuni 		u_int	(*x_getpostn)(struct XDR *);
11070de0abfSPeter Wemm 		/* lets you reposition the stream */
111370c6ad8SPedro F. Giffuni 		bool_t  (*x_setpostn)(struct XDR *, u_int);
11270de0abfSPeter Wemm 		/* buf quick ptr to buffered data */
113370c6ad8SPedro F. Giffuni 		int32_t *(*x_inline)(struct XDR *, u_int);
11470de0abfSPeter Wemm 		/* free privates of this xdr_stream */
115370c6ad8SPedro F. Giffuni 		void	(*x_destroy)(struct XDR *);
116370c6ad8SPedro F. Giffuni 		bool_t	(*x_control)(struct XDR *, int, void *);
117dba7a33eSGarrett Wollman 	} *x_ops;
1188360efbdSAlfred Perlstein 	char *	 	x_public;	/* users' data */
1198360efbdSAlfred Perlstein 	void *		x_private;	/* pointer to private data */
1208360efbdSAlfred Perlstein 	char * 		x_base;		/* private used for position info */
121d7f15c94SJacques Vidrine 	u_int		x_handy;	/* extra private word */
122dba7a33eSGarrett Wollman } XDR;
123dba7a33eSGarrett Wollman 
124dba7a33eSGarrett Wollman /*
12570de0abfSPeter Wemm  * A xdrproc_t exists for each data type which is to be encoded or decoded.
12670de0abfSPeter Wemm  *
12770de0abfSPeter Wemm  * The second argument to the xdrproc_t is a pointer to an opaque pointer.
12870de0abfSPeter Wemm  * The opaque pointer generally points to a structure of the data type
12970de0abfSPeter Wemm  * to be decoded.  If this pointer is 0, then the type routines should
13070de0abfSPeter Wemm  * allocate dynamic storage of the appropriate size and return it.
131edea2cc3SAlfred Perlstein  */
132edea2cc3SAlfred Perlstein #ifdef _KERNEL
133bb28f3c2SWarner Losh typedef	bool_t (*xdrproc_t)(XDR *, void *, u_int);
134edea2cc3SAlfred Perlstein #else
135edea2cc3SAlfred Perlstein /*
1368360efbdSAlfred Perlstein  * XXX can't actually prototype it, because some take three args!!!
137e9e8de06SNick Sayer  */
138f249dbccSDag-Erling Smørgrav typedef	bool_t (*xdrproc_t)(XDR *, ...);
139edea2cc3SAlfred Perlstein #endif
14070de0abfSPeter Wemm 
14170de0abfSPeter Wemm /*
142dba7a33eSGarrett Wollman  * Operations defined on a XDR handle
143dba7a33eSGarrett Wollman  *
144dba7a33eSGarrett Wollman  * XDR		*xdrs;
145dba7a33eSGarrett Wollman  * long		*longp;
1468360efbdSAlfred Perlstein  * char *	 addr;
147dba7a33eSGarrett Wollman  * u_int	 len;
148dba7a33eSGarrett Wollman  * u_int	 pos;
149dba7a33eSGarrett Wollman  */
150dba7a33eSGarrett Wollman #define XDR_GETLONG(xdrs, longp)			\
151dba7a33eSGarrett Wollman 	(*(xdrs)->x_ops->x_getlong)(xdrs, longp)
152dba7a33eSGarrett Wollman #define xdr_getlong(xdrs, longp)			\
153dba7a33eSGarrett Wollman 	(*(xdrs)->x_ops->x_getlong)(xdrs, longp)
154dba7a33eSGarrett Wollman 
155dba7a33eSGarrett Wollman #define XDR_PUTLONG(xdrs, longp)			\
156dba7a33eSGarrett Wollman 	(*(xdrs)->x_ops->x_putlong)(xdrs, longp)
157dba7a33eSGarrett Wollman #define xdr_putlong(xdrs, longp)			\
158dba7a33eSGarrett Wollman 	(*(xdrs)->x_ops->x_putlong)(xdrs, longp)
159dba7a33eSGarrett Wollman 
1608360efbdSAlfred Perlstein static __inline int
xdr_getint32(XDR * xdrs,int32_t * ip)1618360efbdSAlfred Perlstein xdr_getint32(XDR *xdrs, int32_t *ip)
1628360efbdSAlfred Perlstein {
1638360efbdSAlfred Perlstein 	long l;
1648360efbdSAlfred Perlstein 
1658360efbdSAlfred Perlstein 	if (!xdr_getlong(xdrs, &l))
1668360efbdSAlfred Perlstein 		return (FALSE);
1678360efbdSAlfred Perlstein 	*ip = (int32_t)l;
1688360efbdSAlfred Perlstein 	return (TRUE);
1698360efbdSAlfred Perlstein }
1708360efbdSAlfred Perlstein 
1718360efbdSAlfred Perlstein static __inline int
xdr_putint32(XDR * xdrs,int32_t * ip)1728360efbdSAlfred Perlstein xdr_putint32(XDR *xdrs, int32_t *ip)
1738360efbdSAlfred Perlstein {
1748360efbdSAlfred Perlstein 	long l;
1758360efbdSAlfred Perlstein 
1768360efbdSAlfred Perlstein 	l = (long)*ip;
1778360efbdSAlfred Perlstein 	return xdr_putlong(xdrs, &l);
1788360efbdSAlfred Perlstein }
1798360efbdSAlfred Perlstein 
1808360efbdSAlfred Perlstein #define XDR_GETINT32(xdrs, int32p)	xdr_getint32(xdrs, int32p)
1818360efbdSAlfred Perlstein #define XDR_PUTINT32(xdrs, int32p)	xdr_putint32(xdrs, int32p)
1828360efbdSAlfred Perlstein 
183dba7a33eSGarrett Wollman #define XDR_GETBYTES(xdrs, addr, len)			\
184dba7a33eSGarrett Wollman 	(*(xdrs)->x_ops->x_getbytes)(xdrs, addr, len)
185dba7a33eSGarrett Wollman #define xdr_getbytes(xdrs, addr, len)			\
186dba7a33eSGarrett Wollman 	(*(xdrs)->x_ops->x_getbytes)(xdrs, addr, len)
187dba7a33eSGarrett Wollman 
188dba7a33eSGarrett Wollman #define XDR_PUTBYTES(xdrs, addr, len)			\
189dba7a33eSGarrett Wollman 	(*(xdrs)->x_ops->x_putbytes)(xdrs, addr, len)
190dba7a33eSGarrett Wollman #define xdr_putbytes(xdrs, addr, len)			\
191dba7a33eSGarrett Wollman 	(*(xdrs)->x_ops->x_putbytes)(xdrs, addr, len)
192dba7a33eSGarrett Wollman 
193dba7a33eSGarrett Wollman #define XDR_GETPOS(xdrs)				\
194dba7a33eSGarrett Wollman 	(*(xdrs)->x_ops->x_getpostn)(xdrs)
195dba7a33eSGarrett Wollman #define xdr_getpos(xdrs)				\
196dba7a33eSGarrett Wollman 	(*(xdrs)->x_ops->x_getpostn)(xdrs)
197dba7a33eSGarrett Wollman 
198dba7a33eSGarrett Wollman #define XDR_SETPOS(xdrs, pos)				\
199dba7a33eSGarrett Wollman 	(*(xdrs)->x_ops->x_setpostn)(xdrs, pos)
200dba7a33eSGarrett Wollman #define xdr_setpos(xdrs, pos)				\
201dba7a33eSGarrett Wollman 	(*(xdrs)->x_ops->x_setpostn)(xdrs, pos)
202dba7a33eSGarrett Wollman 
203dba7a33eSGarrett Wollman #define	XDR_INLINE(xdrs, len)				\
204dba7a33eSGarrett Wollman 	(*(xdrs)->x_ops->x_inline)(xdrs, len)
205dba7a33eSGarrett Wollman #define	xdr_inline(xdrs, len)				\
206dba7a33eSGarrett Wollman 	(*(xdrs)->x_ops->x_inline)(xdrs, len)
207dba7a33eSGarrett Wollman 
208dba7a33eSGarrett Wollman #define	XDR_DESTROY(xdrs)				\
209dba7a33eSGarrett Wollman 	if ((xdrs)->x_ops->x_destroy) 			\
210dba7a33eSGarrett Wollman 		(*(xdrs)->x_ops->x_destroy)(xdrs)
211dba7a33eSGarrett Wollman #define	xdr_destroy(xdrs)				\
212dba7a33eSGarrett Wollman 	if ((xdrs)->x_ops->x_destroy) 			\
213dba7a33eSGarrett Wollman 		(*(xdrs)->x_ops->x_destroy)(xdrs)
214dba7a33eSGarrett Wollman 
2158360efbdSAlfred Perlstein #define XDR_CONTROL(xdrs, req, op)			\
2168360efbdSAlfred Perlstein 	if ((xdrs)->x_ops->x_control)			\
2178360efbdSAlfred Perlstein 		(*(xdrs)->x_ops->x_control)(xdrs, req, op)
2188360efbdSAlfred Perlstein #define xdr_control(xdrs, req, op) XDR_CONTROL(xdrs, req, op)
2198360efbdSAlfred Perlstein 
220d1bd689dSPedro F. Giffuni #define xdr_rpcvers(xdrs, versp) xdr_u_int32_t(xdrs, versp)
221d1bd689dSPedro F. Giffuni #define xdr_rpcprog(xdrs, progp) xdr_u_int32_t(xdrs, progp)
222d1bd689dSPedro F. Giffuni #define xdr_rpcproc(xdrs, procp) xdr_u_int32_t(xdrs, procp)
223d1bd689dSPedro F. Giffuni #define xdr_rpcprot(xdrs, protp) xdr_u_int32_t(xdrs, protp)
224d1bd689dSPedro F. Giffuni #define xdr_rpcport(xdrs, portp) xdr_u_int32_t(xdrs, portp)
2258360efbdSAlfred Perlstein 
226dba7a33eSGarrett Wollman /*
227dba7a33eSGarrett Wollman  * Support struct for discriminated unions.
228dba7a33eSGarrett Wollman  * You create an array of xdrdiscrim structures, terminated with
2299d5abbddSJens Schweikhardt  * an entry with a null procedure pointer.  The xdr_union routine gets
230dba7a33eSGarrett Wollman  * the discriminant value and then searches the array of structures
231dba7a33eSGarrett Wollman  * for a matching value.  If a match is found the associated xdr routine
232dba7a33eSGarrett Wollman  * is called to handle that part of the union.  If there is
233dba7a33eSGarrett Wollman  * no match, then a default routine may be called.
234dba7a33eSGarrett Wollman  * If there is no match and no default routine it is an error.
235dba7a33eSGarrett Wollman  */
236dba7a33eSGarrett Wollman #define NULL_xdrproc_t ((xdrproc_t)0)
237dba7a33eSGarrett Wollman struct xdr_discrim {
238dba7a33eSGarrett Wollman 	int	value;
239dba7a33eSGarrett Wollman 	xdrproc_t proc;
240dba7a33eSGarrett Wollman };
241dba7a33eSGarrett Wollman 
242dba7a33eSGarrett Wollman /*
24371d9c781SMike Pritchard  * In-line routines for fast encode/decode of primitive data types.
244dba7a33eSGarrett Wollman  * Caveat emptor: these use single memory cycles to get the
245dba7a33eSGarrett Wollman  * data from the underlying buffer, and will fail to operate
246dba7a33eSGarrett Wollman  * properly if the data is not aligned.  The standard way to use these
247dba7a33eSGarrett Wollman  * is to say:
248dba7a33eSGarrett Wollman  *	if ((buf = XDR_INLINE(xdrs, count)) == NULL)
249dba7a33eSGarrett Wollman  *		return (FALSE);
250dba7a33eSGarrett Wollman  *	<<< macro calls >>>
251dba7a33eSGarrett Wollman  * where ``count'' is the number of bytes of data occupied
252dba7a33eSGarrett Wollman  * by the primitive data types.
253dba7a33eSGarrett Wollman  *
254dba7a33eSGarrett Wollman  * N.B. and frozen for all time: each data type here uses 4 bytes
255dba7a33eSGarrett Wollman  * of external representation.
256dba7a33eSGarrett Wollman  */
257fd8e4ebcSMike Barcroft #define IXDR_GET_INT32(buf)		((int32_t)__ntohl((u_int32_t)*(buf)++))
258fd8e4ebcSMike Barcroft #define IXDR_PUT_INT32(buf, v)		(*(buf)++ =(int32_t)__htonl((u_int32_t)v))
2598360efbdSAlfred Perlstein #define IXDR_GET_U_INT32(buf)		((u_int32_t)IXDR_GET_INT32(buf))
2608360efbdSAlfred Perlstein #define IXDR_PUT_U_INT32(buf, v)	IXDR_PUT_INT32((buf), ((int32_t)(v)))
2618360efbdSAlfred Perlstein 
262fd8e4ebcSMike Barcroft #define IXDR_GET_LONG(buf)		((long)__ntohl((u_int32_t)*(buf)++))
263fd8e4ebcSMike Barcroft #define IXDR_PUT_LONG(buf, v)		(*(buf)++ =(int32_t)__htonl((u_int32_t)v))
264dba7a33eSGarrett Wollman 
265dba7a33eSGarrett Wollman #define IXDR_GET_BOOL(buf)		((bool_t)IXDR_GET_LONG(buf))
266dba7a33eSGarrett Wollman #define IXDR_GET_ENUM(buf, t)		((t)IXDR_GET_LONG(buf))
267dba7a33eSGarrett Wollman #define IXDR_GET_U_LONG(buf)		((u_long)IXDR_GET_LONG(buf))
268dba7a33eSGarrett Wollman #define IXDR_GET_SHORT(buf)		((short)IXDR_GET_LONG(buf))
269dba7a33eSGarrett Wollman #define IXDR_GET_U_SHORT(buf)		((u_short)IXDR_GET_LONG(buf))
270dba7a33eSGarrett Wollman 
2718360efbdSAlfred Perlstein #define IXDR_PUT_BOOL(buf, v)		IXDR_PUT_LONG((buf), (v))
2728360efbdSAlfred Perlstein #define IXDR_PUT_ENUM(buf, v)		IXDR_PUT_LONG((buf), (v))
2738360efbdSAlfred Perlstein #define IXDR_PUT_U_LONG(buf, v)		IXDR_PUT_LONG((buf), (v))
2748360efbdSAlfred Perlstein #define IXDR_PUT_SHORT(buf, v)		IXDR_PUT_LONG((buf), (v))
2758360efbdSAlfred Perlstein #define IXDR_PUT_U_SHORT(buf, v)	IXDR_PUT_LONG((buf), (v))
276dba7a33eSGarrett Wollman 
277dba7a33eSGarrett Wollman /*
278dba7a33eSGarrett Wollman  * These are the "generic" xdr routines.
279dba7a33eSGarrett Wollman  */
28086b9a9ccSGarrett Wollman __BEGIN_DECLS
281bb28f3c2SWarner Losh extern bool_t	xdr_void(void);
282bb28f3c2SWarner Losh extern bool_t	xdr_int(XDR *, int *);
283bb28f3c2SWarner Losh extern bool_t	xdr_u_int(XDR *, u_int *);
284bb28f3c2SWarner Losh extern bool_t	xdr_long(XDR *, long *);
285bb28f3c2SWarner Losh extern bool_t	xdr_u_long(XDR *, u_long *);
286bb28f3c2SWarner Losh extern bool_t	xdr_short(XDR *, short *);
287bb28f3c2SWarner Losh extern bool_t	xdr_u_short(XDR *, u_short *);
288bb28f3c2SWarner Losh extern bool_t	xdr_int16_t(XDR *, int16_t *);
289bb28f3c2SWarner Losh extern bool_t	xdr_u_int16_t(XDR *, u_int16_t *);
290a9148abdSDoug Rabson extern bool_t	xdr_uint16_t(XDR *, u_int16_t *);
291bb28f3c2SWarner Losh extern bool_t	xdr_int32_t(XDR *, int32_t *);
292bb28f3c2SWarner Losh extern bool_t	xdr_u_int32_t(XDR *, u_int32_t *);
293a9148abdSDoug Rabson extern bool_t	xdr_uint32_t(XDR *, u_int32_t *);
294bb28f3c2SWarner Losh extern bool_t	xdr_int64_t(XDR *, int64_t *);
295bb28f3c2SWarner Losh extern bool_t	xdr_u_int64_t(XDR *, u_int64_t *);
296a9148abdSDoug Rabson extern bool_t	xdr_uint64_t(XDR *, u_int64_t *);
297bb28f3c2SWarner Losh extern bool_t	xdr_bool(XDR *, bool_t *);
298bb28f3c2SWarner Losh extern bool_t	xdr_enum(XDR *, enum_t *);
299d0b2bb9eSKevin Lo extern bool_t	xdr_array(XDR *, char **, u_int *, u_int, u_int, xdrproc_t);
300bb28f3c2SWarner Losh extern bool_t	xdr_bytes(XDR *, char **, u_int *, u_int);
301bb28f3c2SWarner Losh extern bool_t	xdr_opaque(XDR *, char *, u_int);
302bb28f3c2SWarner Losh extern bool_t	xdr_string(XDR *, char **, u_int);
303d0b2bb9eSKevin Lo extern bool_t	xdr_union(XDR *, enum_t *, char *, const struct xdr_discrim *, xdrproc_t);
304bb28f3c2SWarner Losh extern bool_t	xdr_char(XDR *, char *);
305bb28f3c2SWarner Losh extern bool_t	xdr_u_char(XDR *, u_char *);
306bb28f3c2SWarner Losh extern bool_t	xdr_vector(XDR *, char *, u_int, u_int, xdrproc_t);
307bb28f3c2SWarner Losh extern bool_t	xdr_float(XDR *, float *);
308bb28f3c2SWarner Losh extern bool_t	xdr_double(XDR *, double *);
309bb28f3c2SWarner Losh extern bool_t	xdr_quadruple(XDR *, long double *);
310bb28f3c2SWarner Losh extern bool_t	xdr_reference(XDR *, char **, u_int, xdrproc_t);
311bb28f3c2SWarner Losh extern bool_t	xdr_pointer(XDR *, char **, u_int, xdrproc_t);
312bb28f3c2SWarner Losh extern bool_t	xdr_wrapstring(XDR *, char **);
313f249dbccSDag-Erling Smørgrav extern void	xdr_free(xdrproc_t, void *);
314bb28f3c2SWarner Losh extern bool_t	xdr_hyper(XDR *, quad_t *);
315bb28f3c2SWarner Losh extern bool_t	xdr_u_hyper(XDR *, u_quad_t *);
316bb28f3c2SWarner Losh extern bool_t	xdr_longlong_t(XDR *, quad_t *);
317bb28f3c2SWarner Losh extern bool_t	xdr_u_longlong_t(XDR *, u_quad_t *);
318d98b6d6eSKevin Lo extern unsigned long	xdr_sizeof(xdrproc_t, void *);
31986b9a9ccSGarrett Wollman __END_DECLS
320dba7a33eSGarrett Wollman 
321dba7a33eSGarrett Wollman /*
322dba7a33eSGarrett Wollman  * Common opaque bytes objects used by many rpc protocols;
323dba7a33eSGarrett Wollman  * declared here due to commonality.
324dba7a33eSGarrett Wollman  */
325dba7a33eSGarrett Wollman #define MAX_NETOBJ_SZ 1024
326dba7a33eSGarrett Wollman struct netobj {
327dba7a33eSGarrett Wollman 	u_int	n_len;
328dba7a33eSGarrett Wollman 	char	*n_bytes;
329dba7a33eSGarrett Wollman };
330dba7a33eSGarrett Wollman typedef struct netobj netobj;
331bb28f3c2SWarner Losh extern bool_t   xdr_netobj(XDR *, struct netobj *);
332dba7a33eSGarrett Wollman 
333dba7a33eSGarrett Wollman /*
334dba7a33eSGarrett Wollman  * These are the public routines for the various implementations of
335dba7a33eSGarrett Wollman  * xdr streams.
336dba7a33eSGarrett Wollman  */
33786b9a9ccSGarrett Wollman __BEGIN_DECLS
33886b9a9ccSGarrett Wollman /* XDR using memory buffers */
339bb28f3c2SWarner Losh extern void   xdrmem_create(XDR *, char *, u_int, enum xdr_op);
340dba7a33eSGarrett Wollman 
34186b9a9ccSGarrett Wollman /* XDR using stdio library */
3428360efbdSAlfred Perlstein #ifdef _STDIO_H_
343bb28f3c2SWarner Losh extern void   xdrstdio_create(XDR *, FILE *, enum xdr_op);
34486b9a9ccSGarrett Wollman #endif
34586b9a9ccSGarrett Wollman 
34686b9a9ccSGarrett Wollman /* XDR pseudo records for tcp */
347f249dbccSDag-Erling Smørgrav extern void   xdrrec_create(XDR *, u_int, u_int, void *,
348f249dbccSDag-Erling Smørgrav 			    int (*)(void *, void *, int),
349f249dbccSDag-Erling Smørgrav 			    int (*)(void *, void *, int));
35086b9a9ccSGarrett Wollman 
35186b9a9ccSGarrett Wollman /* make end of xdr record */
352bb28f3c2SWarner Losh extern bool_t xdrrec_endofrecord(XDR *, int);
35386b9a9ccSGarrett Wollman 
35486b9a9ccSGarrett Wollman /* move to beginning of next record */
355bb28f3c2SWarner Losh extern bool_t xdrrec_skiprecord(XDR *);
35686b9a9ccSGarrett Wollman 
35786b9a9ccSGarrett Wollman /* true if no more input */
358bb28f3c2SWarner Losh extern bool_t xdrrec_eof(XDR *);
359bb28f3c2SWarner Losh extern u_int xdrrec_readbytes(XDR *, caddr_t, u_int);
36086b9a9ccSGarrett Wollman __END_DECLS
36186b9a9ccSGarrett Wollman 
36286b9a9ccSGarrett Wollman #endif /* !_RPC_XDR_H */
363