/* * xdr.c, Generic XDR routines implementation. * * Copyright (C) 1986, Sun Microsystems, Inc. * * These are the "generic" xdr routines used to serialize and de-serialize * most common data items. See xdr.h for more info on the interface to * xdr. */ #include #include #include /* * Free a data structure using XDR * Not a filter, but a convenient utility nonetheless */ void Xdr_free(proc, objp) xdrproc_t proc; char *objp; { XDR x; x.x_op = XDR_FREE; (*proc)(&x, objp); } /* * XDR nothing */ bool_t Xdr_void(/* xdrs, addr */) /* XDR *xdrs; */ /* caddr_t addr; */ { return (TRUE); } /* * XDR integers */ bool_t Xdr_int(xdrs, ip) XDR *xdrs; int *ip; { if (sizeof (int) == sizeof (long)) { return (Xdr_long(xdrs, (long *)ip)); } else { return (Xdr_short(xdrs, (short *)ip)); } } /* * XDR long integers * same as Xdr_u_long - open coded to save a proc call! */ bool_t Xdr_long(xdrs, lp) register XDR *xdrs; long *lp; { if (xdrs->x_op == XDR_ENCODE) return (XDR_PUTLONG(xdrs, lp)); if (xdrs->x_op == XDR_DECODE) return (XDR_GETLONG(xdrs, lp)); if (xdrs->x_op == XDR_FREE) return (TRUE); return (FALSE); } /* * XDR short integers */ bool_t Xdr_short(xdrs, sp) register XDR *xdrs; short *sp; { long l; switch (xdrs->x_op) { case XDR_ENCODE: l = (long) *sp; return (XDR_PUTLONG(xdrs, &l)); case XDR_DECODE: if (!XDR_GETLONG(xdrs, &l)) { return (FALSE); } *sp = (short) l; return (TRUE); case XDR_FREE: return (TRUE); } return (FALSE); } /* * XDR a char */ bool_t Xdr_char(xdrs, cp) XDR *xdrs; char *cp; { int i; i = (*cp); if (!Xdr_int(xdrs, &i)) { return (FALSE); } *cp = i; return (TRUE); } bool_t Xdr_callhdr(xdrs, cmsg) register XDR *xdrs; register struct rpc_msg *cmsg; { cmsg->rm_direction = CALL; cmsg->rm_call.cb_rpcvers = RPC_MSG_VERSION; if ( (xdrs->x_op == XDR_ENCODE) && Xdr_long(xdrs, &(cmsg->rm_xid)) && Xdr_enum(xdrs, (enum_t *)&(cmsg->rm_direction)) && Xdr_long(xdrs, &(cmsg->rm_call.cb_rpcvers)) && Xdr_long(xdrs, &(cmsg->rm_call.cb_prog)) ) return (Xdr_long(xdrs, &(cmsg->rm_call.cb_vers))); return (FALSE); }