1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
|
/*
* DIS/x : An implementation of the IEEE 1278.1 protocol
*
* Copyright (C) 1996, Riley Rainey (rainey@netcom.com)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of either:
*
* a) the GNU Library General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your
* option) any later version. A description of the terms and conditions
* of the GLPL may be found in the "COPYING.LIB" file.
*
* b) the "Artistic License" which comes with this Kit. Information
* about this license may be found in the "Artistic" file.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License or the Artistic License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* Information describing how to contact the author can be found in the
* README file.
*/
#include <rpc/types.h>
#include <rpc/xdr.h>
#include <sys/types.h>
#ifndef WIN32
#include <netinet/in.h>
#endif
bool_t xdr_byte_opaque(XDR * xdrs, caddr_t cp, u_int cnt);
/*
* These xdr_byte_ routines act just as their xdr_ equivalents except that
* input data is not required to be aligned on a 4-byte boundary. This
* implies that data alignment is the responsibility of the protocol
* designer.
*/
bool_t
xdr_byte_long(XDR * xdrs, void *vcp)
{
long u;
long int *cp = (long int *) vcp;
u = htonl(*cp);
if (!xdr_byte_opaque(xdrs, (caddr_t) & u, 4)) {
return (FALSE);
}
*cp = ntohl(u);
return (TRUE);
}
bool_t
xdr_byte_u_long(XDR * xdrs, void * vcp)
{
u_long u, *cp = (u_long *) vcp;
u = htonl(*cp);
if (!xdr_byte_opaque(xdrs, (caddr_t) & u, 4)) {
return (FALSE);
}
*cp = ntohl(u);
return (TRUE);
}
bool_t
xdr_byte_short(XDR * xdrs, void *vcp)
{
short u;
short *cp = (short *) vcp;
u = htons(*cp);
if (!xdr_byte_opaque(xdrs, (caddr_t) & u, 2)) {
return (FALSE);
}
*cp = ntohs(u);
return (TRUE);
}
bool_t
xdr_byte_u_short(XDR * xdrs, void * vcp)
{
u_short u;
u_short *cp = (u_short *) vcp;
u = htons(*cp);
if (!xdr_byte_opaque(xdrs, (caddr_t) & u, 2)) {
return (FALSE);
}
*cp = ntohs(u);
return (TRUE);
}
bool_t
xdr_byte_char(XDR * xdrs, void *vcp)
{
char i, *cp = (char *) vcp;
i = (*cp);
if (!xdr_byte_opaque(xdrs, &i, 1)) {
return (FALSE);
}
*cp = i;
return (TRUE);
}
bool_t
xdr_byte_u_char(XDR * xdrs, void * vcp)
{
u_char u, *cp = (u_char *) vcp;
u = (*cp);
if (!xdr_byte_opaque(xdrs, &u, 1)) {
return (FALSE);
}
*cp = u;
return (TRUE);
}
bool_t
xdr_byte_opaque(register XDR * xdrs, caddr_t cp, register u_int cnt)
{
/*
* if no data we are done
*/
if (cnt == 0)
return (TRUE);
if (xdrs->x_op == XDR_DECODE) {
if (!XDR_GETBYTES(xdrs, cp, cnt)) {
return (FALSE);
}
return (TRUE);
}
if (xdrs->x_op == XDR_ENCODE) {
if (!XDR_PUTBYTES(xdrs, cp, cnt)) {
return (FALSE);
}
return (TRUE);
}
if (xdrs->x_op == XDR_FREE) {
return (TRUE);
}
return (FALSE);
}
|