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.4 2003/08/07 21:54:34 dillon 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
81 #if defined(LIBC_SCCS) && !defined(lint)
82 /*static char *sccsid = "from: @(#)xdr.c 1.35 87/08/12";*/
83 /*static char *sccsid = "from: @(#)xdr.c 2.1 88/07/29 4.0 RPCSRC";*/
84 /*static char *rcsid = "Id: xdr.c,v 1.2.4.2 1996/06/05 02:52:02 jkh Exp";*/
88 * xdr.c, Generic XDR routines implementation.
90 * Copyright (C) 1986, Sun Microsystems, Inc.
92 * These are the "generic" xdr routines used to serialize and de-serialize
93 * most common data items. See xdr.h for more info on the interface to
97 #include <rpc/types.h>
101 * constants specific to the xdr "protocol"
103 #define XDR_FALSE ((long) 0)
104 #define XDR_TRUE ((long) 1)
105 #define LASTUNSIGNED ((u_int) 0-1)
110 static char xdr_zero[BYTES_PER_XDR_UNIT] = { 0, 0, 0, 0 };
122 (void) (xdr_short(xdrs, (short *)ip));
123 return (xdr_long(xdrs, (long *)ip));
125 if (sizeof (int) == sizeof (long)) {
126 return (xdr_long(xdrs, (long *)ip));
128 return (xdr_short(xdrs, (short *)ip));
134 * XDR unsigned integers
143 (void) (xdr_short(xdrs, (short *)up));
144 return (xdr_u_long(xdrs, (u_long *)up));
146 if (sizeof (u_int) == sizeof (u_long)) {
147 return (xdr_u_long(xdrs, (u_long *)up));
149 return (xdr_short(xdrs, (short *)up));
156 * same as xdr_u_long - open coded to save a proc call!
164 if (xdrs->x_op == XDR_ENCODE)
165 return (XDR_PUTLONG(xdrs, lp));
167 if (xdrs->x_op == XDR_DECODE)
168 return (XDR_GETLONG(xdrs, lp));
170 if (xdrs->x_op == XDR_FREE)
177 * XDR unsigned long integers
178 * same as xdr_long - open coded to save a proc call!
181 xdr_u_long(xdrs, ulp)
186 if (xdrs->x_op == XDR_DECODE)
187 return (XDR_GETLONG(xdrs, (long *)ulp));
188 if (xdrs->x_op == XDR_ENCODE)
189 return (XDR_PUTLONG(xdrs, (long *)ulp));
190 if (xdrs->x_op == XDR_FREE)
205 switch (xdrs->x_op) {
209 return (XDR_PUTLONG(xdrs, &l));
212 if (!XDR_GETLONG(xdrs, &l)) {
225 * XDR unsigned short integers
228 xdr_u_short(xdrs, usp)
234 switch (xdrs->x_op) {
238 return (XDR_PUTLONG(xdrs, &l));
241 if (!XDR_GETLONG(xdrs, &l)) {
265 if (!xdr_int(xdrs, &i)) {
273 * XDR an unsigned char
283 if (!xdr_u_int(xdrs, &u)) {
300 switch (xdrs->x_op) {
303 lb = *bp ? XDR_TRUE : XDR_FALSE;
304 return (XDR_PUTLONG(xdrs, &lb));
307 if (!XDR_GETLONG(xdrs, &lb)) {
310 *bp = (lb == XDR_FALSE) ? FALSE : TRUE;
328 enum sizecheck { SIZEVAL }; /* used to find the size of an enum */
331 * enums are treated as ints
333 if (sizeof (enum sizecheck) == sizeof (long)) {
334 return (xdr_long(xdrs, (long *)ep));
335 } else if (sizeof (enum sizecheck) == sizeof (short)) {
336 return (xdr_short(xdrs, (short *)ep));
341 (void) (xdr_short(xdrs, (short *)ep));
342 return (xdr_long(xdrs, (long *)ep));
348 * Allows the specification of a fixed size sequence of opaque bytes.
349 * cp points to the opaque object and cnt gives the byte length.
352 xdr_opaque(xdrs, cp, cnt)
358 static char crud[BYTES_PER_XDR_UNIT];
361 * if no data we are done
367 * round byte count to full xdr units
369 rndup = cnt % BYTES_PER_XDR_UNIT;
371 rndup = BYTES_PER_XDR_UNIT - rndup;
373 if (xdrs->x_op == XDR_DECODE) {
374 if (!XDR_GETBYTES(xdrs, cp, cnt)) {
379 return (XDR_GETBYTES(xdrs, crud, rndup));
382 if (xdrs->x_op == XDR_ENCODE) {
383 if (!XDR_PUTBYTES(xdrs, cp, cnt)) {
388 return (XDR_PUTBYTES(xdrs, xdr_zero, rndup));
391 if (xdrs->x_op == XDR_FREE) {
400 * XDR implementation using kernel buffers
403 #if defined(LIBC_SCCS) && !defined(lint)
404 /*static char *sccsid = "from: @(#)xdr_mem.c 1.19 87/08/11 Copyr 1984 Sun Micro";*/
405 /*static char *sccsid = "from: @(#)xdr_mem.c 2.1 88/07/29 4.0 RPCSRC";*/
406 /*static char *rcsid = "Id: xdr_mem.c,v 1.2.4.2 1996/06/05 02:52:04 jkh Exp";*/
410 * xdr_mem.h, XDR implementation using memory buffers.
412 * Copyright (C) 1984, Sun Microsystems, Inc.
414 * If you have some data to be interpreted as external data representation
415 * or to be converted to external data representation in a memory buffer,
416 * then this is the package for you.
421 void xdrmbuf_init __P((XDR *, KBuffer *, enum xdr_op));
422 static bool_t xdrmbuf_getlong __P((XDR *, long *));
423 static bool_t xdrmbuf_putlong __P((XDR *, long *));
424 static bool_t xdrmbuf_getbytes __P((XDR *, caddr_t, u_int));
425 static bool_t xdrmbuf_putbytes __P((XDR *, caddr_t, u_int));
426 static u_int xdrmbuf_getpos __P((XDR *));
428 static struct xdr_ops xdrmbuf_ops = {
440 * The procedure xdrmbuf_init initializes a stream descriptor for a
444 xdrmbuf_init(xdrs, m, op)
451 xdrs->x_ops = &xdrmbuf_ops;
452 xdrs->x_base = (caddr_t)m;
453 KB_DATASTART(m, xdrs->x_private, caddr_t);
454 xdrs->x_handy = KB_LEN(m);
458 xdrmbuf_getlong(xdrs, lp)
464 * See if long is contained in this buffer
466 if ((xdrs->x_handy -= sizeof(long)) < 0) {
470 * We (currently) don't allow a long to span a buffer
472 if (xdrs->x_handy != -sizeof(long)) {
473 printf("xdrmbuf_getlong: data spans buffers\n");
478 * Try to move to a chained buffer
480 if ((m = (KBuffer *)(xdrs->x_base)) != NULL) {
482 xdrs->x_base = (caddr_t)m;
486 * Setup new buffer's info
488 KB_DATASTART(m, xdrs->x_private, caddr_t);
489 if ((xdrs->x_handy = KB_LEN(m) - sizeof(long)) < 0) {
490 printf("xdrmbuf_getlong: short buffer\n");
502 * Return the long value
504 *lp = (long)ntohl((u_long)(*((long *)(xdrs->x_private))));
507 * Advance the data stream
509 xdrs->x_private += sizeof(long);
514 xdrmbuf_putlong(xdrs, lp)
520 * See if long will fit in this buffer
522 if ((xdrs->x_handy -= sizeof(long)) < 0) {
526 * We (currently) don't allow a long to span a buffer
528 if (xdrs->x_handy != -sizeof(long)) {
529 printf("xdrmbuf_putlong: data spans buffers\n");
534 * Try to move to a chained buffer
536 if ((m = (KBuffer *)(xdrs->x_base)) != NULL) {
538 xdrs->x_base = (caddr_t)m;
542 * Setup new buffer's info
544 KB_DATASTART(m, xdrs->x_private, caddr_t);
545 if ((xdrs->x_handy = KB_LEN(m) - sizeof(long)) < 0) {
546 printf("xdrmbuf_putlong: short buffer\n");
558 * Store the long value into our buffer
560 *(long *)xdrs->x_private = (long)htonl((u_long)(*lp));
563 * Advance the data stream
565 xdrs->x_private += sizeof(long);
570 xdrmbuf_getbytes(xdrs, addr, len)
579 if (xdrs->x_handy <= 0) {
583 * No data in current buffer, move to a chained buffer
585 if ((m = (KBuffer *)(xdrs->x_base)) != NULL) {
587 xdrs->x_base = (caddr_t)m;
591 * Setup new buffer's info
593 KB_DATASTART(m, xdrs->x_private, caddr_t);
594 xdrs->x_handy = KB_LEN(m);
604 * Copy from buffer to user's space
606 copy = MIN(len, xdrs->x_handy);
607 KM_COPY(xdrs->x_private, addr, copy);
610 * Update data stream controls
612 xdrs->x_private += copy;
613 xdrs->x_handy -= copy;
621 xdrmbuf_putbytes(xdrs, addr, len)
630 if (xdrs->x_handy <= 0) {
634 * No data in current buffer, move to a chained buffer
636 if ((m = (KBuffer *)(xdrs->x_base)) != NULL) {
638 xdrs->x_base = (caddr_t)m;
642 * Setup new buffer's info
644 KB_DATASTART(m, xdrs->x_private, caddr_t);
645 xdrs->x_handy = KB_LEN(m);
655 * Copy from user's space into buffer
657 copy = MIN(len, xdrs->x_handy);
658 KM_COPY(addr, xdrs->x_private, copy);
661 * Update data stream controls
663 xdrs->x_private += copy;
664 xdrs->x_handy -= copy;
676 return ((u_int)xdrs->x_private - (u_int)xdrs->x_base);
679 #endif /* !defined(sun) */