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 $
31 * SPANS Signalling Manager
32 * ---------------------------
34 * Kernel XDR (External Data Representation) routines
38 #include <netatm/kern_include.h>
41 __RCSID("@(#) $FreeBSD: src/sys/netatm/spans/spans_kxdr.c,v 1.3 1999/08/28 00:48:50 peter Exp $");
45 * This file contains code that has been copied and/or modified from
46 * the following FreeBSD files:
48 * /usr/src/lib/libc/xdr/xdr.c
49 * /usr/src/lib/libc/xdr/xdr_mem.c
51 * which are covered by the copyright notice below.
55 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
56 * unrestricted use provided that this legend is included on all tape
57 * media and as a part of the software program in whole or part. Users
58 * may copy or modify Sun RPC without charge, but are not authorized
59 * to license or distribute it to anyone else except as part of a product or
60 * program developed by the user.
62 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
63 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
64 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
66 * Sun RPC is provided with no support and without any obligation on the
67 * part of Sun Microsystems, Inc. to assist in its use, correction,
68 * modification or enhancement.
70 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
71 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
72 * OR ANY PART THEREOF.
74 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
75 * or profits or other special, indirect and consequential damages, even if
76 * Sun has been advised of the possibility of such damages.
78 * Sun Microsystems, Inc.
80 * Mountain View, California 94043
85 #if defined(LIBC_SCCS) && !defined(lint)
86 /*static char *sccsid = "from: @(#)xdr.c 1.35 87/08/12";*/
87 /*static char *sccsid = "from: @(#)xdr.c 2.1 88/07/29 4.0 RPCSRC";*/
88 /*static char *rcsid = "Id: xdr.c,v 1.2.4.2 1996/06/05 02:52:02 jkh Exp";*/
92 * xdr.c, Generic XDR routines implementation.
94 * Copyright (C) 1986, Sun Microsystems, Inc.
96 * These are the "generic" xdr routines used to serialize and de-serialize
97 * most common data items. See xdr.h for more info on the interface to
101 #include <rpc/types.h>
105 * constants specific to the xdr "protocol"
107 #define XDR_FALSE ((long) 0)
108 #define XDR_TRUE ((long) 1)
109 #define LASTUNSIGNED ((u_int) 0-1)
114 static char xdr_zero[BYTES_PER_XDR_UNIT] = { 0, 0, 0, 0 };
126 (void) (xdr_short(xdrs, (short *)ip));
127 return (xdr_long(xdrs, (long *)ip));
129 if (sizeof (int) == sizeof (long)) {
130 return (xdr_long(xdrs, (long *)ip));
132 return (xdr_short(xdrs, (short *)ip));
138 * XDR unsigned integers
147 (void) (xdr_short(xdrs, (short *)up));
148 return (xdr_u_long(xdrs, (u_long *)up));
150 if (sizeof (u_int) == sizeof (u_long)) {
151 return (xdr_u_long(xdrs, (u_long *)up));
153 return (xdr_short(xdrs, (short *)up));
160 * same as xdr_u_long - open coded to save a proc call!
168 if (xdrs->x_op == XDR_ENCODE)
169 return (XDR_PUTLONG(xdrs, lp));
171 if (xdrs->x_op == XDR_DECODE)
172 return (XDR_GETLONG(xdrs, lp));
174 if (xdrs->x_op == XDR_FREE)
181 * XDR unsigned long integers
182 * same as xdr_long - open coded to save a proc call!
185 xdr_u_long(xdrs, ulp)
190 if (xdrs->x_op == XDR_DECODE)
191 return (XDR_GETLONG(xdrs, (long *)ulp));
192 if (xdrs->x_op == XDR_ENCODE)
193 return (XDR_PUTLONG(xdrs, (long *)ulp));
194 if (xdrs->x_op == XDR_FREE)
209 switch (xdrs->x_op) {
213 return (XDR_PUTLONG(xdrs, &l));
216 if (!XDR_GETLONG(xdrs, &l)) {
229 * XDR unsigned short integers
232 xdr_u_short(xdrs, usp)
238 switch (xdrs->x_op) {
242 return (XDR_PUTLONG(xdrs, &l));
245 if (!XDR_GETLONG(xdrs, &l)) {
269 if (!xdr_int(xdrs, &i)) {
277 * XDR an unsigned char
287 if (!xdr_u_int(xdrs, &u)) {
304 switch (xdrs->x_op) {
307 lb = *bp ? XDR_TRUE : XDR_FALSE;
308 return (XDR_PUTLONG(xdrs, &lb));
311 if (!XDR_GETLONG(xdrs, &lb)) {
314 *bp = (lb == XDR_FALSE) ? FALSE : TRUE;
332 enum sizecheck { SIZEVAL }; /* used to find the size of an enum */
335 * enums are treated as ints
337 if (sizeof (enum sizecheck) == sizeof (long)) {
338 return (xdr_long(xdrs, (long *)ep));
339 } else if (sizeof (enum sizecheck) == sizeof (short)) {
340 return (xdr_short(xdrs, (short *)ep));
345 (void) (xdr_short(xdrs, (short *)ep));
346 return (xdr_long(xdrs, (long *)ep));
352 * Allows the specification of a fixed size sequence of opaque bytes.
353 * cp points to the opaque object and cnt gives the byte length.
356 xdr_opaque(xdrs, cp, cnt)
361 register u_int rndup;
362 static char crud[BYTES_PER_XDR_UNIT];
365 * if no data we are done
371 * round byte count to full xdr units
373 rndup = cnt % BYTES_PER_XDR_UNIT;
375 rndup = BYTES_PER_XDR_UNIT - rndup;
377 if (xdrs->x_op == XDR_DECODE) {
378 if (!XDR_GETBYTES(xdrs, cp, cnt)) {
383 return (XDR_GETBYTES(xdrs, crud, rndup));
386 if (xdrs->x_op == XDR_ENCODE) {
387 if (!XDR_PUTBYTES(xdrs, cp, cnt)) {
392 return (XDR_PUTBYTES(xdrs, xdr_zero, rndup));
395 if (xdrs->x_op == XDR_FREE) {
404 * XDR implementation using kernel buffers
407 #if defined(LIBC_SCCS) && !defined(lint)
408 /*static char *sccsid = "from: @(#)xdr_mem.c 1.19 87/08/11 Copyr 1984 Sun Micro";*/
409 /*static char *sccsid = "from: @(#)xdr_mem.c 2.1 88/07/29 4.0 RPCSRC";*/
410 /*static char *rcsid = "Id: xdr_mem.c,v 1.2.4.2 1996/06/05 02:52:04 jkh Exp";*/
414 * xdr_mem.h, XDR implementation using memory buffers.
416 * Copyright (C) 1984, Sun Microsystems, Inc.
418 * If you have some data to be interpreted as external data representation
419 * or to be converted to external data representation in a memory buffer,
420 * then this is the package for you.
425 void xdrmbuf_init __P((XDR *, KBuffer *, enum xdr_op));
426 static bool_t xdrmbuf_getlong __P((XDR *, long *));
427 static bool_t xdrmbuf_putlong __P((XDR *, long *));
428 static bool_t xdrmbuf_getbytes __P((XDR *, caddr_t, u_int));
429 static bool_t xdrmbuf_putbytes __P((XDR *, caddr_t, u_int));
430 static u_int xdrmbuf_getpos __P((XDR *));
432 static struct xdr_ops xdrmbuf_ops = {
444 * The procedure xdrmbuf_init initializes a stream descriptor for a
448 xdrmbuf_init(xdrs, m, op)
455 xdrs->x_ops = &xdrmbuf_ops;
456 xdrs->x_base = (caddr_t)m;
457 KB_DATASTART(m, xdrs->x_private, caddr_t);
458 xdrs->x_handy = KB_LEN(m);
462 xdrmbuf_getlong(xdrs, lp)
468 * See if long is contained in this buffer
470 if ((xdrs->x_handy -= sizeof(long)) < 0) {
474 * We (currently) don't allow a long to span a buffer
476 if (xdrs->x_handy != -sizeof(long)) {
477 printf("xdrmbuf_getlong: data spans buffers\n");
482 * Try to move to a chained buffer
484 if ((m = (KBuffer *)(xdrs->x_base)) != NULL) {
486 xdrs->x_base = (caddr_t)m;
490 * Setup new buffer's info
492 KB_DATASTART(m, xdrs->x_private, caddr_t);
493 if ((xdrs->x_handy = KB_LEN(m) - sizeof(long)) < 0) {
494 printf("xdrmbuf_getlong: short buffer\n");
506 * Return the long value
508 *lp = (long)ntohl((u_long)(*((long *)(xdrs->x_private))));
511 * Advance the data stream
513 xdrs->x_private += sizeof(long);
518 xdrmbuf_putlong(xdrs, lp)
524 * See if long will fit in this buffer
526 if ((xdrs->x_handy -= sizeof(long)) < 0) {
530 * We (currently) don't allow a long to span a buffer
532 if (xdrs->x_handy != -sizeof(long)) {
533 printf("xdrmbuf_putlong: data spans buffers\n");
538 * Try to move to a chained buffer
540 if ((m = (KBuffer *)(xdrs->x_base)) != NULL) {
542 xdrs->x_base = (caddr_t)m;
546 * Setup new buffer's info
548 KB_DATASTART(m, xdrs->x_private, caddr_t);
549 if ((xdrs->x_handy = KB_LEN(m) - sizeof(long)) < 0) {
550 printf("xdrmbuf_putlong: short buffer\n");
562 * Store the long value into our buffer
564 *(long *)xdrs->x_private = (long)htonl((u_long)(*lp));
567 * Advance the data stream
569 xdrs->x_private += sizeof(long);
574 xdrmbuf_getbytes(xdrs, addr, len)
583 if (xdrs->x_handy <= 0) {
587 * No data in current buffer, move to a chained buffer
589 if ((m = (KBuffer *)(xdrs->x_base)) != NULL) {
591 xdrs->x_base = (caddr_t)m;
595 * Setup new buffer's info
597 KB_DATASTART(m, xdrs->x_private, caddr_t);
598 xdrs->x_handy = KB_LEN(m);
608 * Copy from buffer to user's space
610 copy = MIN(len, xdrs->x_handy);
611 KM_COPY(xdrs->x_private, addr, copy);
614 * Update data stream controls
616 xdrs->x_private += copy;
617 xdrs->x_handy -= copy;
625 xdrmbuf_putbytes(xdrs, addr, len)
634 if (xdrs->x_handy <= 0) {
638 * No data in current buffer, move to a chained buffer
640 if ((m = (KBuffer *)(xdrs->x_base)) != NULL) {
642 xdrs->x_base = (caddr_t)m;
646 * Setup new buffer's info
648 KB_DATASTART(m, xdrs->x_private, caddr_t);
649 xdrs->x_handy = KB_LEN(m);
659 * Copy from user's space into buffer
661 copy = MIN(len, xdrs->x_handy);
662 KM_COPY(addr, xdrs->x_private, copy);
665 * Update data stream controls
667 xdrs->x_private += copy;
668 xdrs->x_handy -= copy;
680 return ((u_int)xdrs->x_private - (u_int)xdrs->x_base);
683 #endif /* !defined(sun) */