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>
37 * xdr_mem.h, XDR implementation using memory buffers.
39 * Copyright (C) 1984, Sun Microsystems, Inc.
41 * If you have some data to be interpreted as external data representation
42 * or to be converted to external data representation in a memory buffer,
43 * then this is the package for you.
49 #include <netinet/in.h>
52 static bool_t xdrmem_getint32();
53 static bool_t xdrmem_putint32();
54 static bool_t xdrmem_getbytes();
55 static bool_t xdrmem_putbytes();
56 static u_int xdrmem_getpos();
57 static bool_t xdrmem_setpos();
58 static afs_int32 * xdrmem_inline();
59 static void xdrmem_destroy();
61 static struct xdr_ops xdrmem_ops = {
73 * The procedure xdrmem_create initializes a stream descriptor for a
77 xdrmem_create(xdrs, addr, size, op)
85 xdrs->x_ops = &xdrmem_ops;
86 xdrs->x_private = xdrs->x_base = addr;
91 xdrmem_destroy(/*xdrs*/)
97 xdrmem_getint32(xdrs, lp)
102 if ((xdrs->x_handy -= sizeof(afs_int32)) < 0)
104 *lp = ntohl(*((afs_int32 *)(xdrs->x_private)));
105 xdrs->x_private += sizeof(afs_int32);
110 xdrmem_putint32(xdrs, lp)
115 if ((xdrs->x_handy -= sizeof(afs_int32)) < 0)
117 *(afs_int32 *)xdrs->x_private = htonl(*lp);
118 xdrs->x_private += sizeof(afs_int32);
123 xdrmem_getbytes(xdrs, addr, len)
129 if ((xdrs->x_handy -= len) < 0)
131 bcopy(xdrs->x_private, addr, len);
132 xdrs->x_private += len;
137 xdrmem_putbytes(xdrs, addr, len)
143 if ((xdrs->x_handy -= len) < 0)
145 bcopy(addr, xdrs->x_private, len);
146 xdrs->x_private += len;
155 return ((u_int)xdrs->x_private - (u_int)xdrs->x_base);
159 xdrmem_setpos(xdrs, pos)
163 register caddr_t newaddr = xdrs->x_base + pos;
164 register caddr_t lastaddr = xdrs->x_private + xdrs->x_handy;
166 if ((afs_int32)newaddr > (afs_int32)lastaddr)
168 xdrs->x_private = newaddr;
169 xdrs->x_handy = (int)lastaddr - (int)newaddr;
174 xdrmem_inline(xdrs, len)
180 if (xdrs->x_handy >= len) {
181 xdrs->x_handy -= len;
182 buf = (afs_int32 *) xdrs->x_private;
183 xdrs->x_private += len;