2 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
3 * unrestricted use provided that this legend is included on all tape
4 * media and as a part of the software program in whole or part. Users
5 * may copy or modify Sun RPC without charge, but are not authorized
6 * to license or distribute it to anyone else except as part of a product or
7 * program developed by the user.
9 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
10 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
11 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
13 * Sun RPC is provided with no support and without any obligation on the
14 * part of Sun Microsystems, Inc. to assist in its use, correction,
15 * modification or enhancement.
17 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
18 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
19 * OR ANY PART THEREOF.
21 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
22 * or profits or other special, indirect and consequential damages, even if
23 * Sun has been advised of the possibility of such damages.
25 * Sun Microsystems, Inc.
27 * Mountain View, California 94043
29 #include <afsconfig.h>
30 #include <afs/param.h>
38 * xdr_mem.h, XDR implementation using memory buffers.
40 * Copyright (C) 1984, Sun Microsystems, Inc.
42 * If you have some data to be interpreted as external data representation
43 * or to be converted to external data representation in a memory buffer,
44 * then this is the package for you.
50 #include <netinet/in.h>
55 static bool_t xdrmem_getint32();
56 static bool_t xdrmem_putint32();
57 static bool_t xdrmem_getbytes();
58 static bool_t xdrmem_putbytes();
59 static u_int xdrmem_getpos();
60 static bool_t xdrmem_setpos();
61 static afs_int32 *xdrmem_inline();
62 static void xdrmem_destroy();
64 static struct xdr_ops xdrmem_ops = {
76 * The procedure xdrmem_create initializes a stream descriptor for a
80 xdrmem_create(XDR * xdrs, caddr_t addr, u_int size, enum xdr_op op)
83 xdrs->x_ops = &xdrmem_ops;
84 xdrs->x_private = xdrs->x_base = addr;
85 xdrs->x_handy = (size > INT_MAX) ? INT_MAX : size; /* XXX */
94 xdrmem_getint32(XDR * xdrs, afs_int32 * lp)
96 if (xdrs->x_handy < sizeof(afs_int32))
99 xdrs->x_handy -= sizeof(afs_int32);
100 *lp = ntohl(*((afs_int32 *) (xdrs->x_private)));
101 xdrs->x_private += sizeof(afs_int32);
106 xdrmem_putint32(XDR * xdrs, afs_int32 * lp)
108 if (xdrs->x_handy < sizeof(afs_int32))
111 xdrs->x_handy -= sizeof(afs_int32);
112 *(afs_int32 *) xdrs->x_private = htonl(*lp);
113 xdrs->x_private += sizeof(afs_int32);
118 xdrmem_getbytes(XDR * xdrs, caddr_t addr, u_int len)
120 if (xdrs->x_handy < len)
123 xdrs->x_handy -= len;
124 memcpy(addr, xdrs->x_private, len);
125 xdrs->x_private += len;
130 xdrmem_putbytes(XDR * xdrs, caddr_t addr, u_int len)
132 if (xdrs->x_handy < len)
135 xdrs->x_handy -= len;
136 memcpy(xdrs->x_private, addr, len);
137 xdrs->x_private += len;
142 xdrmem_getpos(XDR * xdrs)
144 return ((u_int)(xdrs->x_private - xdrs->x_base));
148 xdrmem_setpos(XDR * xdrs, u_int pos)
150 caddr_t newaddr = xdrs->x_base + pos;
151 caddr_t lastaddr = xdrs->x_private + xdrs->x_handy;
153 if (newaddr > lastaddr)
155 xdrs->x_private = newaddr;
156 xdrs->x_handy = (int)(lastaddr - newaddr);
161 xdrmem_inline(XDR * xdrs, int len)
165 if (len >= 0 && xdrs->x_handy >= len) {
166 xdrs->x_handy -= len;
167 buf = (afs_int32 *) xdrs->x_private;
168 xdrs->x_private += len;