xref: /illumos-gate/usr/src/uts/common/rpc/xdr.h (revision 275c9da86e89f8abf71135cf63d9fc23671b2e60)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  *
22  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
26 /* All Rights Reserved */
27 /*
28  * Portions of this source code were derived from Berkeley
29  * 4.3 BSD under license from the Regents of the University of
30  * California.
31  */
32 
33 /*
34  * xdr.h, External Data Representation Serialization Routines.
35  *
36  */
37 
38 #ifndef _RPC_XDR_H
39 #define	_RPC_XDR_H
40 
41 #pragma ident	"%Z%%M%	%I%	%E% SMI"
42 
43 #include <sys/byteorder.h>	/* For all ntoh* and hton*() kind of macros */
44 #include <rpc/types.h>	/* For all ntoh* and hton*() kind of macros */
45 #ifndef _KERNEL
46 #include <stdio.h> /* defines FILE *, used in ANSI C function prototypes */
47 #endif
48 #ifdef _KERNEL
49 #include <sys/stream.h>
50 #endif
51 
52 #ifdef __cplusplus
53 extern "C" {
54 #endif
55 
56 /*
57  * XDR provides a conventional way for converting between C data
58  * types and an external bit-string representation.  Library supplied
59  * routines provide for the conversion on built-in C data types.  These
60  * routines and utility routines defined here are used to help implement
61  * a type encode/decode routine for each user-defined type.
62  *
63  * Each data type provides a single procedure which takes two arguments:
64  *
65  *	bool_t
66  *	xdrproc(xdrs, argresp)
67  *		XDR *xdrs;
68  *		<type> *argresp;
69  *
70  * xdrs is an instance of a XDR handle, to which or from which the data
71  * type is to be converted.  argresp is a pointer to the structure to be
72  * converted.  The XDR handle contains an operation field which indicates
73  * which of the operations (ENCODE, DECODE * or FREE) is to be performed.
74  *
75  * XDR_DECODE may allocate space if the pointer argresp is null.  This
76  * data can be freed with the XDR_FREE operation.
77  *
78  * We write only one procedure per data type to make it easy
79  * to keep the encode and decode procedures for a data type consistent.
80  * In many cases the same code performs all operations on a user defined type,
81  * because all the hard work is done in the component type routines.
82  * decode as a series of calls on the nested data types.
83  */
84 
85 /*
86  * Xdr operations.  XDR_ENCODE causes the type to be encoded into the
87  * stream.  XDR_DECODE causes the type to be extracted from the stream.
88  * XDR_FREE can be used to release the space allocated by an XDR_DECODE
89  * request.
90  */
91 enum xdr_op {
92 	XDR_ENCODE = 0,
93 	XDR_DECODE = 1,
94 	XDR_FREE = 2
95 };
96 
97 /*
98  * This is the number of bytes per unit of external data.
99  */
100 #define	BYTES_PER_XDR_UNIT	(4)
101 #define	RNDUP(x)  ((((x) + BYTES_PER_XDR_UNIT - 1) / BYTES_PER_XDR_UNIT) \
102 		    * BYTES_PER_XDR_UNIT)
103 
104 /*
105  * The XDR handle.
106  * Contains operation which is being applied to the stream,
107  * an operations vector for the paticular implementation (e.g. see xdr_mem.c),
108  * and two private fields for the use of the particular impelementation.
109  *
110  * PSARC 2003/523 Contract Private Interface
111  * XDR
112  * Changes must be reviewed by Solaris File Sharing
113  * Changes must be communicated to contract-2003-523@sun.com
114  */
115 typedef struct XDR {
116 	enum xdr_op	x_op;	/* operation; fast additional param */
117 	struct xdr_ops *x_ops;
118 	caddr_t 	x_public; /* users' data */
119 	caddr_t		x_private; /* pointer to private data */
120 	caddr_t 	x_base;	/* private used for position info */
121 	int		x_handy; /* extra private word */
122 } XDR;
123 
124 /*
125  * PSARC 2003/523 Contract Private Interface
126  * xdr_ops
127  * Changes must be reviewed by Solaris File Sharing
128  * Changes must be communicated to contract-2003-523@sun.com
129  */
130 struct xdr_ops {
131 #ifdef __STDC__
132 #if !defined(_KERNEL)
133 		bool_t	(*x_getlong)(struct XDR *, long *);
134 		/* get a long from underlying stream */
135 		bool_t	(*x_putlong)(struct XDR *, long *);
136 		/* put a long to " */
137 #endif /* KERNEL */
138 		bool_t	(*x_getbytes)(struct XDR *, caddr_t, int);
139 		/* get some bytes from " */
140 		bool_t	(*x_putbytes)(struct XDR *, caddr_t, int);
141 		/* put some bytes to " */
142 		uint_t	(*x_getpostn)(struct XDR *);
143 		/* returns bytes off from beginning */
144 		bool_t  (*x_setpostn)(struct XDR *, uint_t);
145 		/* lets you reposition the stream */
146 		rpc_inline_t *(*x_inline)(struct XDR *, int);
147 		/* buf quick ptr to buffered data */
148 		void	(*x_destroy)(struct XDR *);
149 		/* free privates of this xdr_stream */
150 		bool_t	(*x_control)(struct XDR *, int, void *);
151 #if defined(_LP64) || defined(_KERNEL)
152 		bool_t	(*x_getint32)(struct XDR *, int32_t *);
153 		/* get a int from underlying stream */
154 		bool_t	(*x_putint32)(struct XDR *, int32_t *);
155 		/* put an int to " */
156 #endif /* _LP64 || _KERNEL */
157 #else
158 #if !defined(_KERNEL)
159 		bool_t	(*x_getlong)();	/* get a long from underlying stream */
160 		bool_t	(*x_putlong)();	/* put a long to " */
161 #endif /* KERNEL */
162 		bool_t	(*x_getbytes)(); /* get some bytes from " */
163 		bool_t	(*x_putbytes)(); /* put some bytes to " */
164 		uint_t	(*x_getpostn)(); /* returns bytes off from beginning */
165 		bool_t  (*x_setpostn)(); /* lets you reposition the stream */
166 		rpc_inline_t *(*x_inline)();
167 				/* buf quick ptr to buffered data */
168 		void	(*x_destroy)();	/* free privates of this xdr_stream */
169 		bool_t	(*x_control)();
170 #if defined(_LP64) || defined(_KERNEL)
171 		bool_t	(*x_getint32)();
172 		bool_t	(*x_putint32)();
173 #endif /* _LP64 || defined(_KERNEL) */
174 #endif
175 };
176 
177 /*
178  * Operations defined on a XDR handle
179  *
180  * XDR		*xdrs;
181  * long		*longp;
182  * caddr_t	 addr;
183  * uint_t	 len;
184  * uint_t	 pos;
185  */
186 #if !defined(_KERNEL)
187 #define	XDR_GETLONG(xdrs, longp)			\
188 	(*(xdrs)->x_ops->x_getlong)(xdrs, longp)
189 #define	xdr_getlong(xdrs, longp)			\
190 	(*(xdrs)->x_ops->x_getlong)(xdrs, longp)
191 
192 #define	XDR_PUTLONG(xdrs, longp)			\
193 	(*(xdrs)->x_ops->x_putlong)(xdrs, longp)
194 #define	xdr_putlong(xdrs, longp)			\
195 	(*(xdrs)->x_ops->x_putlong)(xdrs, longp)
196 #endif /* KERNEL */
197 
198 
199 #if !defined(_LP64) && !defined(_KERNEL)
200 
201 /*
202  * For binary compatability on ILP32 we do not change the shape
203  * of the XDR structure and the GET/PUTINT32 functions just use
204  * the get/putlong vectors which operate on identically-sized
205  * units of data.
206  */
207 
208 #define	XDR_GETINT32(xdrs, int32p)			\
209 	(*(xdrs)->x_ops->x_getlong)(xdrs, (long *)int32p)
210 #define	xdr_getint32(xdrs, int32p)			\
211 	(*(xdrs)->x_ops->x_getlong)(xdrs, (long *)int32p)
212 
213 #define	XDR_PUTINT32(xdrs, int32p)			\
214 	(*(xdrs)->x_ops->x_putlong)(xdrs, (long *)int32p)
215 #define	xdr_putint32(xdrs, int32p)			\
216 	(*(xdrs)->x_ops->x_putlong)(xdrs, (long *)int32p)
217 
218 #else /* !_LP64 && !_KERNEL */
219 
220 #define	XDR_GETINT32(xdrs, int32p)			\
221 	(*(xdrs)->x_ops->x_getint32)(xdrs, int32p)
222 #define	xdr_getint32(xdrs, int32p)			\
223 	(*(xdrs)->x_ops->x_getint32)(xdrs, int32p)
224 
225 #define	XDR_PUTINT32(xdrs, int32p)			\
226 	(*(xdrs)->x_ops->x_putint32)(xdrs, int32p)
227 #define	xdr_putint32(xdrs, int32p)			\
228 	(*(xdrs)->x_ops->x_putint32)(xdrs, int32p)
229 
230 #endif /* !_LP64 && !_KERNEL */
231 
232 #define	XDR_GETBYTES(xdrs, addr, len)			\
233 	(*(xdrs)->x_ops->x_getbytes)(xdrs, addr, len)
234 #define	xdr_getbytes(xdrs, addr, len)			\
235 	(*(xdrs)->x_ops->x_getbytes)(xdrs, addr, len)
236 
237 #define	XDR_PUTBYTES(xdrs, addr, len)			\
238 	(*(xdrs)->x_ops->x_putbytes)(xdrs, addr, len)
239 #define	xdr_putbytes(xdrs, addr, len)			\
240 	(*(xdrs)->x_ops->x_putbytes)(xdrs, addr, len)
241 
242 #define	XDR_GETPOS(xdrs)				\
243 	(*(xdrs)->x_ops->x_getpostn)(xdrs)
244 #define	xdr_getpos(xdrs)				\
245 	(*(xdrs)->x_ops->x_getpostn)(xdrs)
246 
247 #define	XDR_SETPOS(xdrs, pos)				\
248 	(*(xdrs)->x_ops->x_setpostn)(xdrs, pos)
249 #define	xdr_setpos(xdrs, pos)				\
250 	(*(xdrs)->x_ops->x_setpostn)(xdrs, pos)
251 
252 #define	XDR_INLINE(xdrs, len)				\
253 	(*(xdrs)->x_ops->x_inline)(xdrs, len)
254 #define	xdr_inline(xdrs, len)				\
255 	(*(xdrs)->x_ops->x_inline)(xdrs, len)
256 
257 #define	XDR_DESTROY(xdrs)				\
258 	(*(xdrs)->x_ops->x_destroy)(xdrs)
259 #define	xdr_destroy(xdrs)				\
260 	(*(xdrs)->x_ops->x_destroy)(xdrs)
261 
262 #define	XDR_CONTROL(xdrs, req, op)			\
263 	(*(xdrs)->x_ops->x_control)(xdrs, req, op)
264 #define	xdr_control(xdrs, req, op)			\
265 	(*(xdrs)->x_ops->x_control)(xdrs, req, op)
266 
267 /*
268  * Support struct for discriminated unions.
269  * You create an array of xdrdiscrim structures, terminated with
270  * a entry with a null procedure pointer.  The xdr_union routine gets
271  * the discriminant value and then searches the array of structures
272  * for a matching value.  If a match is found the associated xdr routine
273  * is called to handle that part of the union.  If there is
274  * no match, then a default routine may be called.
275  * If there is no match and no default routine it is an error.
276  */
277 
278 
279 /*
280  * A xdrproc_t exists for each data type which is to be encoded or decoded.
281  *
282  * The second argument to the xdrproc_t is a pointer to an opaque pointer.
283  * The opaque pointer generally points to a structure of the data type
284  * to be decoded.  If this pointer is 0, then the type routines should
285  * allocate dynamic storage of the appropriate size and return it.
286  * bool_t	(*xdrproc_t)(XDR *, void *);
287  */
288 #ifdef __cplusplus
289 typedef bool_t (*xdrproc_t)(XDR *, void *);
290 #else
291 #ifdef __STDC__
292 typedef bool_t (*xdrproc_t)(); /* For Backward compatibility */
293 #else
294 typedef	bool_t (*xdrproc_t)();
295 #endif
296 #endif
297 
298 #define	NULL_xdrproc_t ((xdrproc_t)0)
299 
300 #if defined(_LP64) || defined(_I32LPx)
301 #define	xdr_rpcvers(xdrs, versp)	xdr_u_int(xdrs, versp)
302 #define	xdr_rpcprog(xdrs, progp)	xdr_u_int(xdrs, progp)
303 #define	xdr_rpcproc(xdrs, procp)	xdr_u_int(xdrs, procp)
304 #define	xdr_rpcprot(xdrs, protp)	xdr_u_int(xdrs, protp)
305 #define	xdr_rpcport(xdrs, portp)	xdr_u_int(xdrs, portp)
306 #else
307 #define	xdr_rpcvers(xdrs, versp)	xdr_u_long(xdrs, versp)
308 #define	xdr_rpcprog(xdrs, progp)	xdr_u_long(xdrs, progp)
309 #define	xdr_rpcproc(xdrs, procp)	xdr_u_long(xdrs, procp)
310 #define	xdr_rpcprot(xdrs, protp)	xdr_u_long(xdrs, protp)
311 #define	xdr_rpcport(xdrs, portp)	xdr_u_long(xdrs, portp)
312 #endif
313 
314 struct xdr_discrim {
315 	int	value;
316 	xdrproc_t proc;
317 };
318 
319 /*
320  * In-line routines for fast encode/decode of primitve data types.
321  * Caveat emptor: these use single memory cycles to get the
322  * data from the underlying buffer, and will fail to operate
323  * properly if the data is not aligned.  The standard way to use these
324  * is to say:
325  *	if ((buf = XDR_INLINE(xdrs, count)) == NULL)
326  *		return (FALSE);
327  *	<<< macro calls >>>
328  * where ``count'' is the number of bytes of data occupied
329  * by the primitive data types.
330  *
331  * N.B. and frozen for all time: each data type here uses 4 bytes
332  * of external representation.
333  */
334 
335 #define	IXDR_GET_INT32(buf)		((int32_t)ntohl((uint32_t)*(buf)++))
336 #define	IXDR_PUT_INT32(buf, v)		(*(buf)++ = (int32_t)htonl((uint32_t)v))
337 #define	IXDR_GET_U_INT32(buf)		((uint32_t)IXDR_GET_INT32(buf))
338 #define	IXDR_PUT_U_INT32(buf, v)	IXDR_PUT_INT32((buf), ((int32_t)(v)))
339 
340 #if !defined(_KERNEL) && !defined(_LP64)
341 
342 #define	IXDR_GET_LONG(buf)		((long)ntohl((ulong_t)*(buf)++))
343 #define	IXDR_PUT_LONG(buf, v)		(*(buf)++ = (long)htonl((ulong_t)v))
344 #define	IXDR_GET_U_LONG(buf)		((ulong_t)IXDR_GET_LONG(buf))
345 #define	IXDR_PUT_U_LONG(buf, v)		IXDR_PUT_LONG((buf), ((long)(v)))
346 
347 #define	IXDR_GET_BOOL(buf)		((bool_t)IXDR_GET_LONG(buf))
348 #define	IXDR_GET_ENUM(buf, t)		((t)IXDR_GET_LONG(buf))
349 #define	IXDR_GET_SHORT(buf)		((short)IXDR_GET_LONG(buf))
350 #define	IXDR_GET_U_SHORT(buf)		((ushort_t)IXDR_GET_LONG(buf))
351 
352 #define	IXDR_PUT_BOOL(buf, v)		IXDR_PUT_LONG((buf), ((long)(v)))
353 #define	IXDR_PUT_ENUM(buf, v)		IXDR_PUT_LONG((buf), ((long)(v)))
354 #define	IXDR_PUT_SHORT(buf, v)		IXDR_PUT_LONG((buf), ((long)(v)))
355 #define	IXDR_PUT_U_SHORT(buf, v)	IXDR_PUT_LONG((buf), ((long)(v)))
356 
357 #else
358 
359 #define	IXDR_GET_BOOL(buf)		((bool_t)IXDR_GET_INT32(buf))
360 #define	IXDR_GET_ENUM(buf, t)		((t)IXDR_GET_INT32(buf))
361 #define	IXDR_GET_SHORT(buf)		((short)IXDR_GET_INT32(buf))
362 #define	IXDR_GET_U_SHORT(buf)		((ushort_t)IXDR_GET_INT32(buf))
363 
364 #define	IXDR_PUT_BOOL(buf, v)		IXDR_PUT_INT32((buf), ((int)(v)))
365 #define	IXDR_PUT_ENUM(buf, v)		IXDR_PUT_INT32((buf), ((int)(v)))
366 #define	IXDR_PUT_SHORT(buf, v)		IXDR_PUT_INT32((buf), ((int)(v)))
367 #define	IXDR_PUT_U_SHORT(buf, v)	IXDR_PUT_INT32((buf), ((int)(v)))
368 
369 #endif
370 
371 #ifndef _LITTLE_ENDIAN
372 #define	IXDR_GET_HYPER(buf, v)	{ \
373 			*((int32_t *)(&v)) = ntohl(*(uint32_t *)buf++); \
374 			*((int32_t *)(((char *)&v) + BYTES_PER_XDR_UNIT)) \
375 			= ntohl(*(uint32_t *)buf++); \
376 			}
377 #define	IXDR_PUT_HYPER(buf, v)	{ \
378 			*(buf)++ = (int32_t)htonl(*(uint32_t *) \
379 				((char *)&v)); \
380 			*(buf)++ = \
381 				(int32_t)htonl(*(uint32_t *)(((char *)&v) \
382 				+ BYTES_PER_XDR_UNIT)); \
383 			}
384 #else
385 
386 #define	IXDR_GET_HYPER(buf, v)	{ \
387 			*((int32_t *)(((char *)&v) + \
388 				BYTES_PER_XDR_UNIT)) \
389 				= ntohl(*(uint32_t *)buf++); \
390 			*((int32_t *)(&v)) = \
391 				ntohl(*(uint32_t *)buf++); \
392 			}
393 
394 #define	IXDR_PUT_HYPER(buf, v)	{ \
395 			*(buf)++ = \
396 				(int32_t)htonl(*(uint32_t *)(((char *)&v) + \
397 				BYTES_PER_XDR_UNIT)); \
398 			*(buf)++ = \
399 				(int32_t)htonl(*(uint32_t *)((char *)&v)); \
400 			}
401 #endif
402 #define	IXDR_GET_U_HYPER(buf, v)	IXDR_GET_HYPER(buf, v)
403 #define	IXDR_PUT_U_HYPER(buf, v)	IXDR_PUT_HYPER(buf, v)
404 
405 
406 /*
407  * These are the "generic" xdr routines.
408  */
409 #ifdef __STDC__
410 extern bool_t	xdr_void(void);
411 extern bool_t	xdr_int(XDR *, int *);
412 extern bool_t	xdr_u_int(XDR *, uint_t *);
413 extern bool_t	xdr_long(XDR *, long *);
414 extern bool_t	xdr_u_long(XDR *, ulong_t *);
415 extern bool_t	xdr_short(XDR *, short *);
416 extern bool_t	xdr_u_short(XDR *, ushort_t *);
417 extern bool_t	xdr_bool(XDR *, bool_t *);
418 extern bool_t	xdr_enum(XDR *, enum_t *);
419 extern bool_t	xdr_array(XDR *, caddr_t *, uint_t *, const uint_t,
420 		    const uint_t, const xdrproc_t);
421 extern bool_t	xdr_bytes(XDR *, char **, uint_t *, const uint_t);
422 extern bool_t	xdr_opaque(XDR *, caddr_t, const uint_t);
423 extern bool_t	xdr_string(XDR *, char **, const uint_t);
424 extern bool_t	xdr_union(XDR *, enum_t *, char *,
425 		    const struct xdr_discrim *, const xdrproc_t);
426 extern unsigned int  xdr_sizeof(xdrproc_t, void *);
427 
428 extern bool_t   xdr_hyper(XDR *, longlong_t *);
429 extern bool_t   xdr_longlong_t(XDR *, longlong_t *);
430 extern bool_t   xdr_u_hyper(XDR *, u_longlong_t *);
431 extern bool_t   xdr_u_longlong_t(XDR *, u_longlong_t *);
432 
433 extern bool_t	xdr_char(XDR *, char *);
434 extern bool_t	xdr_wrapstring(XDR *, char **);
435 extern bool_t	xdr_reference(XDR *, caddr_t *, uint_t, const xdrproc_t);
436 extern bool_t	xdr_pointer(XDR *, char **, uint_t, const xdrproc_t);
437 extern void	xdr_free(xdrproc_t, char *);
438 extern bool_t	xdr_time_t(XDR *, time_t *);
439 
440 extern bool_t	xdr_int8_t(XDR *, int8_t *);
441 extern bool_t	xdr_uint8_t(XDR *, uint8_t *);
442 extern bool_t	xdr_int16_t(XDR *, int16_t *);
443 extern bool_t	xdr_uint16_t(XDR *, uint16_t *);
444 extern bool_t	xdr_int32_t(XDR *, int32_t *);
445 extern bool_t	xdr_uint32_t(XDR *, uint32_t *);
446 #if defined(_INT64_TYPE)
447 extern bool_t	xdr_int64_t(XDR *, int64_t *);
448 extern bool_t	xdr_uint64_t(XDR *, uint64_t *);
449 #endif
450 
451 #ifndef _KERNEL
452 extern bool_t	xdr_u_char(XDR *, uchar_t *);
453 extern bool_t	xdr_vector(XDR *, char *, const uint_t, const uint_t, const
454 xdrproc_t);
455 extern bool_t	xdr_float(XDR *, float *);
456 extern bool_t	xdr_double(XDR *, double *);
457 extern bool_t	xdr_quadruple(XDR *, long double *);
458 #endif /* !_KERNEL */
459 #else
460 extern bool_t	xdr_void();
461 extern bool_t	xdr_int();
462 extern bool_t	xdr_u_int();
463 extern bool_t	xdr_long();
464 extern bool_t	xdr_u_long();
465 extern bool_t	xdr_short();
466 extern bool_t	xdr_u_short();
467 extern bool_t	xdr_bool();
468 extern bool_t	xdr_enum();
469 extern bool_t	xdr_array();
470 extern bool_t	xdr_bytes();
471 extern bool_t	xdr_opaque();
472 extern bool_t	xdr_string();
473 extern bool_t	xdr_union();
474 
475 extern bool_t   xdr_hyper();
476 extern bool_t   xdr_longlong_t();
477 extern bool_t   xdr_u_hyper();
478 extern bool_t   xdr_u_longlong_t();
479 extern bool_t	xdr_char();
480 extern bool_t	xdr_reference();
481 extern bool_t	xdr_pointer();
482 extern void	xdr_free();
483 extern bool_t	xdr_wrapstring();
484 extern bool_t	xdr_time_t();
485 
486 extern bool_t	xdr_int8_t();
487 extern bool_t	xdr_uint8_t();
488 extern bool_t	xdr_int16_t();
489 extern bool_t	xdr_uint16_t();
490 extern bool_t	xdr_int32_t();
491 extern bool_t	xdr_uint32_t();
492 #if defined(_INT64_TYPE)
493 extern bool_t	xdr_int64_t();
494 extern bool_t	xdr_uint64_t();
495 #endif
496 
497 #ifndef _KERNEL
498 extern bool_t	xdr_u_char();
499 extern bool_t	xdr_vector();
500 extern bool_t	xdr_float();
501 extern bool_t	xdr_double();
502 extern bool_t   xdr_quadruple();
503 #endif /* !_KERNEL */
504 #endif
505 
506 /*
507  * Common opaque bytes objects used by many rpc protocols;
508  * declared here due to commonality.
509  */
510 #define	MAX_NETOBJ_SZ 1024
511 struct netobj {
512 	uint_t	n_len;
513 	char	*n_bytes;
514 };
515 typedef struct netobj netobj;
516 
517 #ifdef __STDC__
518 extern bool_t   xdr_netobj(XDR *, netobj *);
519 #else
520 extern bool_t   xdr_netobj();
521 #endif
522 
523 /*
524  * These are XDR control operators
525  */
526 
527 #define	XDR_GET_BYTES_AVAIL 1
528 
529 struct xdr_bytesrec {
530 	bool_t xc_is_last_record;
531 	size_t xc_num_avail;
532 };
533 
534 typedef struct xdr_bytesrec xdr_bytesrec;
535 
536 /*
537  * These are the request arguments to XDR_CONTROL.
538  *
539  * XDR_PEEK - returns the contents of the next XDR unit on the XDR stream.
540  * XDR_SKIPBYTES - skips the next N bytes in the XDR stream.
541  * XDR_RDMAGET - for xdr implementation over RDMA, gets private flags from
542  *		 the XDR stream being moved over RDMA
543  * XDR_RDMANOCHUNK - for xdr implementaion over RDMA, sets private flags in
544  *                   the XDR stream moving over RDMA.
545  */
546 #ifdef _KERNEL
547 #define	XDR_PEEK		2
548 #define	XDR_SKIPBYTES		3
549 #define	XDR_RDMAGET		4
550 #define	XDR_RDMASET		5
551 #endif
552 
553 /*
554  * These are the public routines for the various implementations of
555  * xdr streams.
556  */
557 #ifndef _KERNEL
558 #ifdef __STDC__
559 extern void   xdrmem_create(XDR *, const caddr_t, const uint_t, const enum
560 xdr_op);
561 	/* XDR using memory buffers */
562 extern void   xdrstdio_create(XDR *, FILE *, const enum xdr_op);
563 /* XDR using stdio library */
564 extern void   xdrrec_create(XDR *, const uint_t, const uint_t, const caddr_t,
565 int (*) (void *, caddr_t, int), int (*) (void *, caddr_t, int));
566 /* XDR pseudo records for tcp */
567 extern bool_t xdrrec_endofrecord(XDR *, bool_t);
568 /* make end of xdr record */
569 extern bool_t xdrrec_skiprecord(XDR *);
570 /* move to beginning of next record */
571 extern bool_t xdrrec_eof(XDR *);
572 extern uint_t xdrrec_readbytes(XDR *, caddr_t, uint_t);
573 /* true if no more input */
574 #else
575 extern void   xdrmem_create();
576 extern void   xdrstdio_create();
577 extern void   xdrrec_create();
578 extern bool_t xdrrec_endofrecord();
579 extern bool_t xdrrec_skiprecord();
580 extern bool_t xdrrec_eof();
581 extern uint_t xdrrec_readbytes();
582 #endif
583 #else
584 
585 extern void	xdrmem_create(XDR *, caddr_t, uint_t, enum xdr_op);
586 extern void	xdrmblk_init(XDR *, mblk_t *, enum xdr_op, int);
587 extern bool_t	xdrmblk_getmblk(XDR *, mblk_t **, uint_t *);
588 extern bool_t	xdrmblk_putmblk(XDR *, mblk_t *, uint_t);
589 
590 extern struct xdr_ops xdrmblk_ops;
591 
592 struct rpc_msg;
593 extern bool_t	xdr_callmsg(XDR *, struct rpc_msg *);
594 extern bool_t	xdr_replymsg_body(XDR *, struct rpc_msg *);
595 extern bool_t	xdr_replymsg_hdr(XDR *, struct rpc_msg *);
596 
597 #endif /* !_KERNEL */
598 
599 #ifdef __cplusplus
600 }
601 #endif
602 
603 #endif	/* !_RPC_XDR_H */
604