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>
36 * xdr_mem.h, XDR implementation using memory buffers.
38 * Copyright (C) 1984, Sun Microsystems, Inc.
40 * If you have some data to be interpreted as external data representation
41 * or to be converted to external data representation in a memory buffer,
42 * then this is the package for you.
49 # include <netinet/in.h>
54 static bool_t xdrmem_getint32(AFS_XDRS_T, afs_int32 *);
55 static bool_t xdrmem_putint32(AFS_XDRS_T, afs_int32 *);
56 static bool_t xdrmem_getbytes(AFS_XDRS_T, caddr_t, u_int);
57 static bool_t xdrmem_putbytes(AFS_XDRS_T, caddr_t, u_int);
58 static u_int xdrmem_getpos(AFS_XDRS_T);
59 static bool_t xdrmem_setpos(AFS_XDRS_T, u_int);
60 static afs_int32 *xdrmem_inline(AFS_XDRS_T, u_int);
61 static void xdrmem_destroy(AFS_XDRS_T);
63 static struct xdr_ops xdrmem_ops = {
64 #if defined(AFS_NT40_ENV) || (defined(AFS_SGI_ENV) && !defined(__c99))
65 /* Windows does not support labeled assigments */
66 xdrmem_getint32, /* deserialize an afs_int32 */
67 xdrmem_putint32, /* serialize an afs_int32 */
68 xdrmem_getbytes, /* deserialize counted bytes */
69 xdrmem_putbytes, /* serialize counted bytes */
70 xdrmem_getpos, /* get offset in the stream: not supported. */
71 xdrmem_setpos, /* set offset in the stream: not supported. */
72 xdrmem_inline, /* prime stream for inline macros */
73 xdrmem_destroy /* destroy stream */
75 .x_getint32 = xdrmem_getint32,
76 .x_putint32 = xdrmem_putint32,
77 .x_getbytes = xdrmem_getbytes,
78 .x_putbytes = xdrmem_putbytes,
79 .x_getpostn = xdrmem_getpos,
80 .x_setpostn = xdrmem_setpos,
81 .x_inline = xdrmem_inline,
82 .x_destroy = xdrmem_destroy
87 * The procedure xdrmem_create initializes a stream descriptor for a
91 xdrmem_create(XDR * xdrs, caddr_t addr, u_int size, enum xdr_op op)
94 xdrs->x_ops = &xdrmem_ops;
95 xdrs->x_private = xdrs->x_base = addr;
96 xdrs->x_handy = (size > INT_MAX) ? INT_MAX : size; /* XXX */
100 xdrmem_destroy(AFS_XDRS_T axdrs)
105 xdrmem_getint32(AFS_XDRS_T axdrs, afs_int32 * lp)
107 XDR * xdrs = (XDR *)axdrs;
109 if (xdrs->x_handy < sizeof(afs_int32))
112 xdrs->x_handy -= sizeof(afs_int32);
113 *lp = ntohl(*((afs_int32 *) (xdrs->x_private)));
114 xdrs->x_private += sizeof(afs_int32);
119 xdrmem_putint32(AFS_XDRS_T axdrs, afs_int32 * lp)
121 XDR * xdrs = (XDR *)axdrs;
123 if (xdrs->x_handy < sizeof(afs_int32))
126 xdrs->x_handy -= sizeof(afs_int32);
127 *(afs_int32 *) xdrs->x_private = htonl(*lp);
128 xdrs->x_private += sizeof(afs_int32);
133 xdrmem_getbytes(AFS_XDRS_T axdrs, caddr_t addr, u_int len)
135 XDR * xdrs = (XDR *)axdrs;
137 if (xdrs->x_handy < len)
140 xdrs->x_handy -= len;
141 memcpy(addr, xdrs->x_private, len);
142 xdrs->x_private += len;
147 xdrmem_putbytes(AFS_XDRS_T axdrs, caddr_t addr, u_int len)
149 XDR * xdrs = (XDR *)axdrs;
151 if (xdrs->x_handy < len)
154 xdrs->x_handy -= len;
155 memcpy(xdrs->x_private, addr, len);
156 xdrs->x_private += len;
161 xdrmem_getpos(AFS_XDRS_T axdrs)
163 XDR * xdrs = (XDR *)axdrs;
165 return ((u_int)(xdrs->x_private - xdrs->x_base));
169 xdrmem_setpos(AFS_XDRS_T axdrs, u_int pos)
171 XDR * xdrs = (XDR *)axdrs;
173 caddr_t newaddr = xdrs->x_base + pos;
174 caddr_t lastaddr = xdrs->x_private + xdrs->x_handy;
176 if (newaddr > lastaddr)
178 xdrs->x_private = newaddr;
179 xdrs->x_handy = (int)(lastaddr - newaddr);
184 xdrmem_inline(AFS_XDRS_T axdrs, u_int len)
186 XDR * xdrs = (XDR *)axdrs;
190 if (len >= 0 && xdrs->x_handy >= len) {
191 xdrs->x_handy -= len;
192 buf = (afs_int32 *) xdrs->x_private;
193 xdrs->x_private += len;