]> CyberLeo.Net >> Repos - FreeBSD/releng/7.2.git/blob - sys/cddl/compat/opensolaris/rpc/xdr.h
Create releng/7.2 from stable/7 in preparation for 7.2-RELEASE.
[FreeBSD/releng/7.2.git] / sys / cddl / compat / opensolaris / rpc / xdr.h
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  *
22  * $FreeBSD$
23  */
24 /*
25  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
26  * Use is subject to license terms.
27  */
28
29 /*      Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T     */
30 /*        All Rights Reserved   */
31
32 /*
33  * Portions of this source code were derived from Berkeley 4.3 BSD
34  * under license from the Regents of the University of California.
35  */
36
37 #ifndef _OPENSOLARIS_RPC_XDR_H_
38 #define _OPENSOLARIS_RPC_XDR_H_
39
40 #include_next <rpc/xdr.h>
41
42 #ifndef _KERNEL
43 #include_next <rpc/xdr.h>
44
45 /*
46  * Strangely, my glibc version (2.3.6) doesn't have xdr_control(), so
47  * we have to hack it in here (source taken from OpenSolaris).
48  * By the way, it is assumed the xdrmem implementation is used.
49  */
50
51 #undef xdr_control
52 #define xdr_control(a,b,c) xdrmem_control(a,b,c)
53
54 /*
55  * These are XDR control operators
56  */
57
58 #define XDR_GET_BYTES_AVAIL 1
59
60 struct xdr_bytesrec {
61         bool_t xc_is_last_record;
62         size_t xc_num_avail;
63 };
64
65 typedef struct xdr_bytesrec xdr_bytesrec;
66
67 /*
68  * These are the request arguments to XDR_CONTROL.
69  *
70  * XDR_PEEK - returns the contents of the next XDR unit on the XDR stream.
71  * XDR_SKIPBYTES - skips the next N bytes in the XDR stream.
72  * XDR_RDMAGET - for xdr implementation over RDMA, gets private flags from
73  *               the XDR stream being moved over RDMA
74  * XDR_RDMANOCHUNK - for xdr implementaion over RDMA, sets private flags in
75  *                   the XDR stream moving over RDMA.
76  */
77 #define XDR_PEEK      2
78 #define XDR_SKIPBYTES 3
79 #define XDR_RDMAGET   4
80 #define XDR_RDMASET   5
81
82 /* FIXME: probably doesn't work */
83 static __inline bool_t
84 xdrmem_control(XDR *xdrs, int request, void *info)
85 {
86         xdr_bytesrec *xptr;
87         int32_t *int32p;
88         int len;
89
90         switch (request) {
91
92         case XDR_GET_BYTES_AVAIL:
93                 xptr = (xdr_bytesrec *)info;
94                 xptr->xc_is_last_record = TRUE;
95                 xptr->xc_num_avail = xdrs->x_handy;
96                 return (TRUE);
97
98         case XDR_PEEK:
99                 /*
100                  * Return the next 4 byte unit in the XDR stream.
101                  */
102                 if (xdrs->x_handy < sizeof (int32_t))
103                         return (FALSE);
104                 int32p = (int32_t *)info;
105                 *int32p = (int32_t)ntohl((uint32_t)
106                     (*((int32_t *)(xdrs->x_private))));
107                 return (TRUE);
108
109         case XDR_SKIPBYTES:
110                 /*
111                  * Skip the next N bytes in the XDR stream.
112                  */
113                 int32p = (int32_t *)info;
114                 len = RNDUP((int)(*int32p));
115                 if ((xdrs->x_handy -= len) < 0)
116                         return (FALSE);
117                 xdrs->x_private += len;
118                 return (TRUE);
119
120         }
121         return (FALSE);
122 }
123 #endif  /* !_KERNEL */
124
125 #endif  /* !_OPENSOLARIS_RPC_XDR_H_ */