Main Page   Class Hierarchy   Alphabetical List   Data Structures   File List   Data Fields   Globals  

xdr_mem.c

Go to the documentation of this file.
00001 /*********************************************************************
00002  * RPC for the Windows NT Operating System
00003  * 1993 by Martin F. Gergeleit
00004  * Users may use, copy or modify Sun RPC for the Windows NT Operating
00005  * System according to the Sun copyright below.
00006  *
00007  * RPC for the Windows NT Operating System COMES WITH ABSOLUTELY NO
00008  * WARRANTY, NOR WILL I BE LIABLE FOR ANY DAMAGES INCURRED FROM THE
00009  * USE OF. USE ENTIRELY AT YOUR OWN RISK!!!
00010  *********************************************************************/
00011 
00012 /* @(#)xdr_mem.c        2.1 88/07/29 4.0 RPCSRC */
00013 /*
00014  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
00015  * unrestricted use provided that this legend is included on all tape
00016  * media and as a part of the software program in whole or part.  Users
00017  * may copy or modify Sun RPC without charge, but are not authorized
00018  * to license or distribute it to anyone else except as part of a product or
00019  * program developed by the user.
00020  *
00021  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
00022  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
00023  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
00024  *
00025  * Sun RPC is provided with no support and without any obligation on the
00026  * part of Sun Microsystems, Inc. to assist in its use, correction,
00027  * modification or enhancement.
00028  *
00029  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
00030  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
00031  * OR ANY PART THEREOF.
00032  *
00033  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
00034  * or profits or other special, indirect and consequential damages, even if
00035  * Sun has been advised of the possibility of such damages.
00036  *
00037  * Sun Microsystems, Inc.
00038  * 2550 Garcia Avenue
00039  * Mountain View, California  94043
00040  */
00041 #if !defined(lint) && defined(SCCSIDS)
00042 static char sccsid[] = "@(#)xdr_mem.c 1.19 87/08/11 Copyr 1984 Sun Micro";
00043 #endif
00044 
00045 /*
00046  * xdr_mem.h, XDR implementation using memory buffers.
00047  *
00048  * Copyright (C) 1984, Sun Microsystems, Inc.
00049  *
00050  * If you have some data to be interpreted as external data representation
00051  * or to be converted to external data representation in a memory buffer,
00052  * then this is the package for you.
00053  *
00054  */
00055 
00056 #include <stdlib.h>             /* malloc(), free() */
00057 #include <string.h>             /* memcpy() */
00058 
00059 #ifdef UNDER_CE
00060 #include <windows.h>
00061 #include <winsock.h>
00062 #else
00063 #include <winsock2.h>           /* ntohl(), htonl() */
00064 #endif
00065 
00066 #include "xdr.h"
00067 
00068 static bool_t   xdrmem_getlong();
00069 static bool_t   xdrmem_putlong();
00070 static bool_t   xdrmem_getbytes();
00071 static bool_t   xdrmem_putbytes();
00072 static u_int    xdrmem_getpos();
00073 static bool_t   xdrmem_setpos();
00074 static long *   xdrmem_inline();
00075 static void     xdrmem_destroy();
00076 
00077 static struct   xdr_ops xdrmem_ops = {
00078         xdrmem_getlong,
00079         xdrmem_putlong,
00080         xdrmem_getbytes,
00081         xdrmem_putbytes,
00082         xdrmem_getpos,
00083         xdrmem_setpos,
00084         xdrmem_inline,
00085         xdrmem_destroy
00086 };
00087 
00088 /*
00089  * The procedure xdrmem_create initializes a stream descriptor for a
00090  * memory buffer.
00091  */
00092 void
00093 xdrmem_create(xdrs, addr, size, op)
00094         register XDR *xdrs;
00095         caddr_t addr;
00096         u_int size;
00097         enum xdr_op op;
00098 {
00099 
00100         xdrs->x_op = op;
00101         xdrs->x_ops = &xdrmem_ops;
00102         xdrs->x_private = xdrs->x_base = addr;
00103         xdrs->x_handy = size;
00104 }
00105 
00106 static void
00107 xdrmem_destroy(/*xdrs*/)
00108         /*XDR *xdrs;*/
00109 {
00110 }
00111 
00112 static bool_t
00113 xdrmem_getlong(xdrs, lp)
00114         register XDR *xdrs;
00115         long *lp;
00116 {
00117 
00118         if ((xdrs->x_handy -= sizeof(long)) < 0)
00119                 return (FALSE);
00120         *lp = (long)ntohl((u_long)(*((long *)(xdrs->x_private))));
00121         xdrs->x_private += sizeof(long);
00122         return (TRUE);
00123 }
00124 
00125 static bool_t
00126 xdrmem_putlong(xdrs, lp)
00127         register XDR *xdrs;
00128         long *lp;
00129 {
00130 
00131         if ((xdrs->x_handy -= sizeof(long)) < 0)
00132                 return (FALSE);
00133         *(long *)xdrs->x_private = (long)htonl((u_long)(*lp));
00134         xdrs->x_private += sizeof(long);
00135         return (TRUE);
00136 }
00137 
00138 static bool_t
00139 xdrmem_getbytes(xdrs, addr, len)
00140         register XDR *xdrs;
00141         caddr_t addr;
00142         register u_int len;
00143 {
00144 
00145         if ((xdrs->x_handy -= len) < 0)
00146                 return (FALSE);
00147         memcpy(addr, xdrs->x_private, len);
00148         xdrs->x_private += len;
00149         return (TRUE);
00150 }
00151 
00152 static bool_t
00153 xdrmem_putbytes(xdrs, addr, len)
00154         register XDR *xdrs;
00155         caddr_t addr;
00156         register u_int len;
00157 {
00158 
00159         if ((xdrs->x_handy -= len) < 0)
00160                 return (FALSE);
00161         memcpy(xdrs->x_private, addr, len);
00162         xdrs->x_private += len;
00163         return (TRUE);
00164 }
00165 
00166 static u_int
00167 xdrmem_getpos(xdrs)
00168         register XDR *xdrs;
00169 {
00170 
00171         return ((u_int)xdrs->x_private - (u_int)xdrs->x_base);
00172 }
00173 
00174 static bool_t
00175 xdrmem_setpos(xdrs, pos)
00176         register XDR *xdrs;
00177         u_int pos;
00178 {
00179         register caddr_t newaddr = xdrs->x_base + pos;
00180         register caddr_t lastaddr = xdrs->x_private + xdrs->x_handy;
00181 
00182         if ((long)newaddr > (long)lastaddr)
00183                 return (FALSE);
00184         xdrs->x_private = newaddr;
00185         xdrs->x_handy = (int)lastaddr - (int)newaddr;
00186         return (TRUE);
00187 }
00188 
00189 static long *
00190 xdrmem_inline(xdrs, len)
00191         register XDR *xdrs;
00192         int len;
00193 {
00194         long *buf = 0;
00195 
00196         if (xdrs->x_handy >= len) {
00197                 xdrs->x_handy -= len;
00198                 buf = (long *) xdrs->x_private;
00199                 xdrs->x_private += len;
00200         }
00201         return (buf);
00202 }

Generated on Sun Dec 2 15:56:54 2001 for rcslib by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001