1 /*********************************************************************
2 * RPC for the Windows NT Operating System
3 * 1993 by Martin F. Gergeleit
4 * Users may use, copy or modify Sun RPC for the Windows NT Operating
5 * System according to the Sun copyright below.
7 * RPC for the Windows NT Operating System COMES WITH ABSOLUTELY NO
8 * WARRANTY, NOR WILL I BE LIABLE FOR ANY DAMAGES INCURRED FROM THE
9 * USE OF. USE ENTIRELY AT YOUR OWN RISK!!!
10 *********************************************************************/
12 /* @(#)xdr_mem.c 2.1 88/07/29 4.0 RPCSRC */
14 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
15 * unrestricted use provided that this legend is included on all tape
16 * media and as a part of the software program in whole or part. Users
17 * may copy or modify Sun RPC without charge, but are not authorized
18 * to license or distribute it to anyone else except as part of a product or
19 * program developed by the user.
21 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
22 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
25 * Sun RPC is provided with no support and without any obligation on the
26 * part of Sun Microsystems, Inc. to assist in its use, correction,
27 * modification or enhancement.
29 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
30 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
31 * OR ANY PART THEREOF.
33 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
34 * or profits or other special, indirect and consequential damages, even if
35 * Sun has been advised of the possibility of such damages.
37 * Sun Microsystems, Inc.
39 * Mountain View, California 94043
41 #if !defined(lint) && defined(SCCSIDS)
42 static char sccsid[] = "@(#)xdr_mem.c 1.19 87/08/11 Copyr 1984 Sun Micro";
46 * xdr_mem.h, XDR implementation using memory buffers.
48 * Copyright (C) 1984, Sun Microsystems, Inc.
50 * If you have some data to be interpreted as external data representation
51 * or to be converted to external data representation in a memory buffer,
52 * then this is the package for you.
61 #include <rpc/types.h>
63 #include <netinet/in.h>
66 static bool_t xdrmem_getlong();
67 static bool_t xdrmem_putlong();
68 static bool_t xdrmem_getbytes();
69 static bool_t xdrmem_putbytes();
70 static u_int xdrmem_getpos();
71 static bool_t xdrmem_setpos();
72 static long * xdrmem_inline();
73 static void xdrmem_destroy();
75 static struct xdr_ops xdrmem_ops = {
87 * The procedure xdrmem_create initializes a stream descriptor for a
91 xdrmem_create(xdrs, addr, size, op)
99 xdrs->x_ops = &xdrmem_ops;
100 xdrs->x_private = xdrs->x_base = addr;
101 xdrs->x_handy = size;
105 xdrmem_destroy(/*xdrs*/)
111 xdrmem_getlong(xdrs, lp)
116 if (xdrs->x_handy < sizeof(long))
118 xdrs->x_handy -= sizeof(long);
119 *lp = (long)ntohl((u_long)(*((long *)(xdrs->x_private))));
120 xdrs->x_private += sizeof(long);
125 xdrmem_putlong(xdrs, lp)
130 if (xdrs->x_handy < sizeof(long))
132 xdrs->x_handy -= sizeof(long);
133 *(long *)xdrs->x_private = (long)htonl((u_long)(*lp));
134 xdrs->x_private += sizeof(long);
139 xdrmem_getbytes(xdrs, addr, len)
145 if (xdrs->x_handy < len)
147 xdrs->x_handy -= len;
148 bcopy(xdrs->x_private, addr, len);
149 xdrs->x_private += len;
154 xdrmem_putbytes(xdrs, addr, len)
160 if (xdrs->x_handy < len)
162 xdrs->x_handy -= len;
163 bcopy(addr, xdrs->x_private, len);
164 xdrs->x_private += len;
173 return ((u_int)xdrs->x_private - (u_int)xdrs->x_base);
177 xdrmem_setpos(xdrs, pos)
181 register caddr_t newaddr = xdrs->x_base + pos;
182 register caddr_t lastaddr = xdrs->x_private + xdrs->x_handy;
184 if (newaddr > lastaddr)
186 xdrs->x_private = newaddr;
187 xdrs->x_handy = (u_int)(lastaddr - newaddr);
192 xdrmem_inline(xdrs, len)
198 if (xdrs->x_handy >= len) {
199 xdrs->x_handy -= len;
200 buf = (long *) xdrs->x_private;
201 xdrs->x_private += len;