Main Page   Modules   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

/projects/cubeos/src_current/net/rpc/xdr_mem.c

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

Generated on Thu Feb 20 15:38:46 2003 for cubeOS by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002