3 * ===================================
4 * HARP | Host ATM Research Platform
5 * ===================================
8 * This Host ATM Research Platform ("HARP") file (the "Software") is
9 * made available by Network Computing Services, Inc. ("NetworkCS")
10 * "AS IS". NetworkCS does not provide maintenance, improvements or
11 * support of any kind.
13 * NETWORKCS MAKES NO WARRANTIES OR REPRESENTATIONS, EXPRESS OR IMPLIED,
14 * INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY
15 * AND FITNESS FOR A PARTICULAR PURPOSE, AS TO ANY ELEMENT OF THE
16 * SOFTWARE OR ANY SUPPORT PROVIDED IN CONNECTION WITH THIS SOFTWARE.
17 * In no event shall NetworkCS be responsible for any damages, including
18 * but not limited to consequential damages, arising from or relating to
19 * any use of the Software or related support.
21 * Copyright 1994-1998 Network Computing Services, Inc.
23 * Copies of this Software may be made, however, the above copyright
24 * notice must be reproduced on all copies.
26 * @(#) $FreeBSD: src/sys/netatm/spans/spans_kxdr.c,v 1.3 1999/08/28 00:48:50 peter Exp $
27 * @(#) $DragonFly: src/sys/netproto/atm/spans/spans_kxdr.c,v 1.6 2005/02/01 00:51:50 joerg Exp $
31 * SPANS Signalling Manager
32 * ---------------------------
34 * Kernel XDR (External Data Representation) routines
38 #include <netproto/atm/kern_include.h>
41 * This file contains code that has been copied and/or modified from
42 * the following FreeBSD files:
44 * /usr/src/lib/libc/xdr/xdr.c
45 * /usr/src/lib/libc/xdr/xdr_mem.c
47 * which are covered by the copyright notice below.
51 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
52 * unrestricted use provided that this legend is included on all tape
53 * media and as a part of the software program in whole or part. Users
54 * may copy or modify Sun RPC without charge, but are not authorized
55 * to license or distribute it to anyone else except as part of a product or
56 * program developed by the user.
58 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
59 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
60 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
62 * Sun RPC is provided with no support and without any obligation on the
63 * part of Sun Microsystems, Inc. to assist in its use, correction,
64 * modification or enhancement.
66 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
67 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
68 * OR ANY PART THEREOF.
70 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
71 * or profits or other special, indirect and consequential damages, even if
72 * Sun has been advised of the possibility of such damages.
74 * Sun Microsystems, Inc.
76 * Mountain View, California 94043
79 #if defined(LIBC_SCCS) && !defined(lint)
80 /*static char *sccsid = "from: @(#)xdr.c 1.35 87/08/12";*/
81 /*static char *sccsid = "from: @(#)xdr.c 2.1 88/07/29 4.0 RPCSRC";*/
82 /*static char *rcsid = "Id: xdr.c,v 1.2.4.2 1996/06/05 02:52:02 jkh Exp";*/
86 * xdr.c, Generic XDR routines implementation.
88 * Copyright (C) 1986, Sun Microsystems, Inc.
90 * These are the "generic" xdr routines used to serialize and de-serialize
91 * most common data items. See xdr.h for more info on the interface to
95 #include <rpc/types.h>
99 * constants specific to the xdr "protocol"
101 #define XDR_FALSE ((long) 0)
102 #define XDR_TRUE ((long) 1)
103 #define LASTUNSIGNED ((u_int) 0-1)
108 static char xdr_zero[BYTES_PER_XDR_UNIT] = { 0, 0, 0, 0 };
120 (void) (xdr_short(xdrs, (short *)ip));
121 return (xdr_long(xdrs, (long *)ip));
123 if (sizeof (int) == sizeof (long)) {
124 return (xdr_long(xdrs, (long *)ip));
126 return (xdr_short(xdrs, (short *)ip));
132 * XDR unsigned integers
141 (void) (xdr_short(xdrs, (short *)up));
142 return (xdr_u_long(xdrs, (u_long *)up));
144 if (sizeof (u_int) == sizeof (u_long)) {
145 return (xdr_u_long(xdrs, (u_long *)up));
147 return (xdr_short(xdrs, (short *)up));
154 * same as xdr_u_long - open coded to save a proc call!
162 if (xdrs->x_op == XDR_ENCODE)
163 return (XDR_PUTLONG(xdrs, lp));
165 if (xdrs->x_op == XDR_DECODE)
166 return (XDR_GETLONG(xdrs, lp));
168 if (xdrs->x_op == XDR_FREE)
175 * XDR unsigned long integers
176 * same as xdr_long - open coded to save a proc call!
179 xdr_u_long(xdrs, ulp)
184 if (xdrs->x_op == XDR_DECODE)
185 return (XDR_GETLONG(xdrs, (long *)ulp));
186 if (xdrs->x_op == XDR_ENCODE)
187 return (XDR_PUTLONG(xdrs, (long *)ulp));
188 if (xdrs->x_op == XDR_FREE)
203 switch (xdrs->x_op) {
207 return (XDR_PUTLONG(xdrs, &l));
210 if (!XDR_GETLONG(xdrs, &l)) {
223 * XDR unsigned short integers
226 xdr_u_short(xdrs, usp)
232 switch (xdrs->x_op) {
236 return (XDR_PUTLONG(xdrs, &l));
239 if (!XDR_GETLONG(xdrs, &l)) {
263 if (!xdr_int(xdrs, &i)) {
271 * XDR an unsigned char
281 if (!xdr_u_int(xdrs, &u)) {
298 switch (xdrs->x_op) {
301 lb = *bp ? XDR_TRUE : XDR_FALSE;
302 return (XDR_PUTLONG(xdrs, &lb));
305 if (!XDR_GETLONG(xdrs, &lb)) {
308 *bp = (lb == XDR_FALSE) ? FALSE : TRUE;
326 enum sizecheck { SIZEVAL }; /* used to find the size of an enum */
329 * enums are treated as ints
331 if (sizeof (enum sizecheck) == sizeof (long)) {
332 return (xdr_long(xdrs, (long *)ep));
333 } else if (sizeof (enum sizecheck) == sizeof (short)) {
334 return (xdr_short(xdrs, (short *)ep));
339 (void) (xdr_short(xdrs, (short *)ep));
340 return (xdr_long(xdrs, (long *)ep));
346 * Allows the specification of a fixed size sequence of opaque bytes.
347 * cp points to the opaque object and cnt gives the byte length.
350 xdr_opaque(xdrs, cp, cnt)
356 static char crud[BYTES_PER_XDR_UNIT];
359 * if no data we are done
365 * round byte count to full xdr units
367 rndup = cnt % BYTES_PER_XDR_UNIT;
369 rndup = BYTES_PER_XDR_UNIT - rndup;
371 if (xdrs->x_op == XDR_DECODE) {
372 if (!XDR_GETBYTES(xdrs, cp, cnt)) {
377 return (XDR_GETBYTES(xdrs, crud, rndup));
380 if (xdrs->x_op == XDR_ENCODE) {
381 if (!XDR_PUTBYTES(xdrs, cp, cnt)) {
386 return (XDR_PUTBYTES(xdrs, xdr_zero, rndup));
389 if (xdrs->x_op == XDR_FREE) {
398 * XDR implementation using kernel buffers
401 #if defined(LIBC_SCCS) && !defined(lint)
402 /*static char *sccsid = "from: @(#)xdr_mem.c 1.19 87/08/11 Copyr 1984 Sun Micro";*/
403 /*static char *sccsid = "from: @(#)xdr_mem.c 2.1 88/07/29 4.0 RPCSRC";*/
404 /*static char *rcsid = "Id: xdr_mem.c,v 1.2.4.2 1996/06/05 02:52:04 jkh Exp";*/
408 * xdr_mem.h, XDR implementation using memory buffers.
410 * Copyright (C) 1984, Sun Microsystems, Inc.
412 * If you have some data to be interpreted as external data representation
413 * or to be converted to external data representation in a memory buffer,
414 * then this is the package for you.
419 void xdrmbuf_init (XDR *, KBuffer *, enum xdr_op);
420 static bool_t xdrmbuf_getlong (XDR *, long *);
421 static bool_t xdrmbuf_putlong (XDR *, long *);
422 static bool_t xdrmbuf_getbytes (XDR *, caddr_t, u_int);
423 static bool_t xdrmbuf_putbytes (XDR *, caddr_t, u_int);
424 static u_int xdrmbuf_getpos (XDR *);
426 static struct xdr_ops xdrmbuf_ops = {
438 * The procedure xdrmbuf_init initializes a stream descriptor for a
442 xdrmbuf_init(xdrs, m, op)
449 xdrs->x_ops = &xdrmbuf_ops;
450 xdrs->x_base = (caddr_t)m;
451 KB_DATASTART(m, xdrs->x_private, caddr_t);
452 xdrs->x_handy = KB_LEN(m);
456 xdrmbuf_getlong(xdrs, lp)
462 * See if long is contained in this buffer
464 if ((xdrs->x_handy -= sizeof(long)) < 0) {
468 * We (currently) don't allow a long to span a buffer
470 if (xdrs->x_handy != -sizeof(long)) {
471 printf("xdrmbuf_getlong: data spans buffers\n");
476 * Try to move to a chained buffer
478 if ((m = (KBuffer *)(xdrs->x_base)) != NULL) {
480 xdrs->x_base = (caddr_t)m;
484 * Setup new buffer's info
486 KB_DATASTART(m, xdrs->x_private, caddr_t);
487 if ((xdrs->x_handy = KB_LEN(m) - sizeof(long)) < 0) {
488 printf("xdrmbuf_getlong: short buffer\n");
500 * Return the long value
502 *lp = (long)ntohl((u_long)(*((long *)(xdrs->x_private))));
505 * Advance the data stream
507 xdrs->x_private += sizeof(long);
512 xdrmbuf_putlong(xdrs, lp)
518 * See if long will fit in this buffer
520 if ((xdrs->x_handy -= sizeof(long)) < 0) {
524 * We (currently) don't allow a long to span a buffer
526 if (xdrs->x_handy != -sizeof(long)) {
527 printf("xdrmbuf_putlong: data spans buffers\n");
532 * Try to move to a chained buffer
534 if ((m = (KBuffer *)(xdrs->x_base)) != NULL) {
536 xdrs->x_base = (caddr_t)m;
540 * Setup new buffer's info
542 KB_DATASTART(m, xdrs->x_private, caddr_t);
543 if ((xdrs->x_handy = KB_LEN(m) - sizeof(long)) < 0) {
544 printf("xdrmbuf_putlong: short buffer\n");
556 * Store the long value into our buffer
558 *(long *)xdrs->x_private = (long)htonl((u_long)(*lp));
561 * Advance the data stream
563 xdrs->x_private += sizeof(long);
568 xdrmbuf_getbytes(xdrs, addr, len)
577 if (xdrs->x_handy <= 0) {
581 * No data in current buffer, move to a chained buffer
583 if ((m = (KBuffer *)(xdrs->x_base)) != NULL) {
585 xdrs->x_base = (caddr_t)m;
589 * Setup new buffer's info
591 KB_DATASTART(m, xdrs->x_private, caddr_t);
592 xdrs->x_handy = KB_LEN(m);
602 * Copy from buffer to user's space
604 copy = MIN(len, xdrs->x_handy);
605 KM_COPY(xdrs->x_private, addr, copy);
608 * Update data stream controls
610 xdrs->x_private += copy;
611 xdrs->x_handy -= copy;
619 xdrmbuf_putbytes(xdrs, addr, len)
628 if (xdrs->x_handy <= 0) {
632 * No data in current buffer, move to a chained buffer
634 if ((m = (KBuffer *)(xdrs->x_base)) != NULL) {
636 xdrs->x_base = (caddr_t)m;
640 * Setup new buffer's info
642 KB_DATASTART(m, xdrs->x_private, caddr_t);
643 xdrs->x_handy = KB_LEN(m);
653 * Copy from user's space into buffer
655 copy = MIN(len, xdrs->x_handy);
656 KM_COPY(addr, xdrs->x_private, copy);
659 * Update data stream controls
661 xdrs->x_private += copy;
662 xdrs->x_handy -= copy;
674 return ((u_int)xdrs->x_private - (u_int)xdrs->x_base);