1: /*
   2:  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
   3:  * unrestricted use provided that this legend is included on all tape
   4:  * media and as a part of the software program in whole or part.  Users
   5:  * may copy or modify Sun RPC without charge, but are not authorized
   6:  * to license or distribute it to anyone else except as part of a product or
   7:  * program developed by the user.
   8:  *
   9:  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  10:  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  11:  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
  12:  *
  13:  * Sun RPC is provided with no support and without any obligation on the
  14:  * part of Sun Microsystems, Inc. to assist in its use, correction,
  15:  * modification or enhancement.
  16:  *
  17:  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  18:  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
  19:  * OR ANY PART THEREOF.
  20:  *
  21:  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
  22:  * or profits or other special, indirect and consequential damages, even if
  23:  * Sun has been advised of the possibility of such damages.
  24:  *
  25:  * Sun Microsystems, Inc.
  26:  * 2550 Garcia Avenue
  27:  * Mountain View, California  94043
  28:  */
  29: #ifndef lint
  30: static char sccsid[] = "@(#)pmap_prot.c 1.2 85/02/08 Copyr 1984 Sun Micro";
  31: #endif
  32: 
  33: /*
  34:  * pmap_prot.c
  35:  * Protocol for the local binder service, or pmap.
  36:  *
  37:  * Copyright (C) 1984, Sun Microsystems, Inc.
  38:  */
  39: 
  40: #include "types.h"
  41: #include "xdr.h"
  42: #include "pmap_prot.h"
  43: 
  44: #define NULL ((struct pmaplist *)0)
  45: 
  46: bool_t
  47: xdr_pmap(xdrs, regs)
  48:     XDR *xdrs;
  49:     struct pmap *regs;
  50: {
  51: 
  52:     if (xdr_u_long(xdrs, &regs->pm_prog) &&
  53:         xdr_u_long(xdrs, &regs->pm_vers) &&
  54:         xdr_u_long(xdrs, &regs->pm_prot))
  55:         return (xdr_u_long(xdrs, &regs->pm_port));
  56:     return (FALSE);
  57: }
  58: 
  59: /*
  60:  * What is going on with linked lists? (!)
  61:  * First recall the link list declaration from pmap_prot.h:
  62:  *
  63:  * struct pmaplist {
  64:  *	struct pmap pml_map;
  65:  *	struct pmaplist *pml_map;
  66:  * };
  67:  *
  68:  * Compare that declaration with a corresponding xdr declaration that
  69:  * is (a) pointer-less, and (b) recursive:
  70:  *
  71:  * typedef union switch (bool_t) {
  72:  *
  73:  *	case TRUE: struct {
  74:  *		struct pmap;
  75:  * 		pmaplist_t foo;
  76:  *	};
  77:  *
  78:  *	case FALSE: struct {};
  79:  * } pmaplist_t;
  80:  *
  81:  * Notice that the xdr declaration has no nxt pointer while
  82:  * the C declaration has no bool_t variable.  The bool_t can be
  83:  * interpreted as ``more data follows me''; if FALSE then nothing
  84:  * follows this bool_t; if TRUE then the bool_t is followed by
  85:  * an actual struct pmap, and then (recursively) by the
  86:  * xdr union, pamplist_t.
  87:  *
  88:  * This could be implemented via the xdr_union primitive, though this
  89:  * would cause a one recursive call per element in the list.  Rather than do
  90:  * that we can ``unwind'' the recursion
  91:  * into a while loop and do the union arms in-place.
  92:  *
  93:  * The head of the list is what the C programmer wishes to past around
  94:  * the net, yet is the data that the pointer points to which is interesting;
  95:  * this sounds like a job for xdr_reference!
  96:  */
  97: bool_t
  98: xdr_pmaplist(xdrs, rp)
  99:     register XDR *xdrs;
 100:     register struct pmaplist **rp;
 101: {
 102:     /*
 103: 	 * more_elements is pre-computed in case the direction is
 104: 	 * XDR_ENCODE or XDR_FREE.  more_elements is overwritten by
 105: 	 * xdr_bool when the direction is XDR_DECODE.
 106: 	 */
 107:     bool_t more_elements;
 108:     register int freeing = (xdrs->x_op == XDR_FREE);
 109:     register struct pmaplist **next;
 110: 
 111:     while (TRUE) {
 112:         more_elements = (bool_t)(*rp != NULL);
 113:         if (! xdr_bool(xdrs, &more_elements))
 114:             return (FALSE);
 115:         if (! more_elements)
 116:             return (TRUE);  /* we are done */
 117:         /*
 118: 		 * the unfortunate side effect of non-recursion is that in
 119: 		 * the case of freeing we must remember the next object
 120: 		 * before we free the current object ...
 121: 		 */
 122:         if (freeing)
 123:             next = &((*rp)->pml_next);
 124:         if (! xdr_reference(xdrs, (caddr_t *)rp,
 125:             (u_int)sizeof(struct pmaplist), xdr_pmap))
 126:             return (FALSE);
 127:         rp = (freeing) ? next : &((*rp)->pml_next);
 128:     }
 129: }

Defined functions

xdr_pmap defined in line 46; used 2 times
xdr_pmaplist defined in line 97; used 1 times

Defined variables

sccsid defined in line 30; never used

Defined macros

NULL defined in line 44; used 1 times
Last modified: 1985-04-19
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 927
Valid CSS Valid XHTML 1.0 Strict