(FILECREATED "27-Jul-85 21:57:06" {ERIS}<LISPCORE>SOURCES>LLETHER.;12 94455  

      changes to:  (FNS \SETETHERFLAGS)

      previous date: " 2-Jul-85 11:22:39" {ERIS}<LISPCORE>SOURCES>LLETHER.;11)


(* Copyright (c) 1982, 1983, 1984, 1985 by Xerox Corporation. All rights reserved.)

(PRETTYCOMPRINT LLETHERCOMS)

(RPAQQ LLETHERCOMS ((COMS (* Stuff which should be somwhere else!)
			  (INITVARS (ERRORMESSAGESTREAM T)
				    (PROMPTWINDOW T))
			  (GLOBALVARS ERRORMESSAGESTREAM PROMPTWINDOW)
			  (COMS (* Queue management for data which can be chain-linked through the 
				   first cell)
				(DECLARE: DONTCOPY (EXPORT (RECORDS SYSQUEUE QABLEITEM)
							   (MACROS \QUEUEHEAD)))
				(INITRECORDS SYSQUEUE)
				(SYSRECORDS SYSQUEUE)
				(FNS \ENQUEUE \DEQUEUE \QUEUELENGTH \ONQUEUE \UNQUEUE)
				(* Queue management constructed by TCONC)
				(EXPORT (MACROS \DETCONC \ENTCONC \PEEKTCONC))))
	(COMS (* General packet management)
	      (DECLARE: DONTCOPY (* * Skeletal ether packet. Other users define with respect to)
			(EXPORT (RECORDS ETHERPACKET ETHERAUX)
				(CONSTANTS \EPT.PUP \EPT.XIP \3MBTYPE.XIP \10MBTYPE.XIP \EPT.10TO3 
					   \3MBTYPE.10TO3 \EPT.UNKNOWN))
			(GLOBALVARS \FREE.PACKET.QUEUE))
	      (INITRECORDS ETHERPACKET)
	      (SYSRECORDS ETHERPACKET)
	      (FNS \ALLOCATE.ETHERPACKET \RELEASE.ETHERPACKET RELEASE.PUP \FLUSH.PACKET.QUEUE 
		   \REQUEUE.ETHERPACKET \EP.PUT.AUX)
	      (INITVARS (\FREE.PACKET.QUEUE (NCREATE (QUOTE SYSQUEUE)))
			(\NEWPACKETCOUNTER 5)))
	(COMS (INITRECORDS NSADDRESS)
	      (INITVARS (\MY.NSHOSTNUMBER NIL)
			(\MY.NSNETNUMBER NIL)
			(\MY.NSADDRESS NIL))
	      (VARS BROADCASTNSHOSTNUMBER)
	      (FNS \SETLOCALNSNUMBERS \LOADNSADDRESS \STORENSADDRESS \PRINTNSADDRESS 
		   \NSADDRESS.DEFPRINT \LOADNSHOSTNUMBER \STORENSHOSTNUMBER PRINTNSHOSTNUMBER)
	      (DECLARE: EVAL@COMPILE DONTCOPY (COMS * NSADDRESSCOMS))
	      (DECLARE: DONTEVAL@LOAD DOCOPY (P (DEFPRINT (QUOTE NSADDRESS)
							  (QUOTE \NSADDRESS.DEFPRINT)))))
	(COMS (* Assorted Level 0)
	      (FNS \ETHERINIT \ETHEREVENTFN \SETETHERFLAGS \FLUSHNDBS \FLUSH.NDB.QUEUE)
	      (FNS \CHECKSUM \HANDLE.RAW.OTHER \HANDLE.RAW.PACKET \ADD.PACKET.FILTER 
		   \DEL.PACKET.FILTER)
	      (DECLARE: DONTCOPY (EXPORT (CONSTANTS (\NULLCHECKSUM 65535)))
			(GLOBALVARS \PACKET.FILTERS \ETHERLIGHTNING))
	      (INITVARS (\PACKET.FILTERS NIL)
			(\ETHERLIGHTNING))
	      (DECLARE: DONTEVAL@LOAD DOCOPY (P (\ETHERINIT)
						(MOVD? (QUOTE NILL)
						       (QUOTE BLOCK))
						(MOVD? (QUOTE NILL)
						       (QUOTE \STASH.PASSWORDS)))))
	(COMS (* Assorted routing stuff)
	      (DECLARE: DONTCOPY (EXPORT (RECORDS NDB ROUTING))
			(CONSTANTS \RT.INFINITY)
			(MACROS ENCAPSULATE.ETHERPACKET TRANSMIT.ETHERPACKET BROADCASTP .RTLOOKUP.)
			(GLOBALVARS \RT.TIMEOUTINTERVAL \RT.AGEINTERVAL \RT.PURGEFLG \GATEWAYFLG)
			(GLOBALVARS \3MBFLG \10MBFLG \3MBLOCALNDB \10MBLOCALNDB \LOCALNDBS \NSFLG 
				    \IPFLG \NS.ROUTING.TABLE \PUP.ROUTING.TABLE \NS.READY \PUP.READY 
				    \IP.READY))
	      (INITRECORDS NDB)
	      (SYSRECORDS NDB)
	      (FNS \AGE.ROUTING.TABLE \FLUSH.ROUTING.TABLE PRINTROUTINGTABLE \MAP.ROUTING.TABLE)
	      (FNS ENCAPSULATE.ETHERPACKET TRANSMIT.ETHERPACKET)
	      (INITVARS (\RT.TIMEOUTINTERVAL 90000)
			(\RT.AGEINTERVAL 30000)
			(\RT.PURGEFLG T)
			(\GATEWAYFLG))
	      (INITVARS (\3MBFLG T)
			(\10MBFLG)
			(\3MBLOCALNDB)
			(\10MBLOCALNDB)
			(\LOCALNDBS)
			(\NSFLG)
			(\IPFLG)))
	(COMS (* 10 to 3 translation ugliness)
	      (FNS \TRANSLATE.10TO3 \NOTE.10TO3 \HANDLE.RAW.10TO3)
	      (DECLARE: DONTCOPY (RECORDS ETHERTRANS)
			(CONSTANTS \TRANS.OP.REQUEST \TRANS.OP.RESPONSE \TRANS.DATALENGTH)
			(* The \TRANS.DATALENGTH includes the space for 10TO3OPERATION and two 
			   3-word/1-word translation pairs.)))
	(COMS (* Printing routines for packets)
	      (FNS PRINTPACKET \MAYBEPRINTPACKET PRINT10TO3 PRINTPACKETDATA PRINTPACKETQUEUE 
		   TIME.SINCE.PACKET)
	      (INITVARS (\RAWTRACING))
	      (ADDVARS (\PACKET.PRINTERS (512 . PRINTPUP)
					 (1537 . PRINT10TO3)))
	      (GLOBALVARS \RAWTRACING \PACKET.PRINTERS PUPTRACEFILE XIPTRACEFILE))
	(COMS (* 3MB stuff, which is not needed in DandeLion)
	      (FNS \3MBGETPACKET \3MB.CREATENDB \3MBSENDPACKET \3MBWATCHER \3MBENCAPSULATE 
		   \3MB.BROADCASTP \3MBFLUSH)
	      (INITVARS (\MAXWATCHERGETS 5))
	      (DECLARE: DONTCOPY (RECORDS 3MBENCAPSULATION PBI)
			(EXPORT (MACROS \SERIALNUMBER))
			(CONSTANTS \3MBENCAPSULATION.WORDS \3MBTYPE.PUP)
			(GLOBALVARS \MAXWATCHERGETS)))
	(COMS (* Debugging)
	      (FNS ASSURE.ETHER.ON INITPUPLEVEL1 TURN.ON.ETHER RESTART.ETHER TURN.OFF.ETHER 
		   PRINTWORDS)
	      (VARS ROUTINGINFOMACRO ETHERFILES)
	      (DECLARE: EVAL@COMPILE DONTCOPY (P (CLISPDEC (QUOTE FETCHFIELD))
						 (* Slow, checking version for debugging))))
	(COMS (* Opcodes)
	      (FNS \DEVICE.INPUT \DEVICE.OUTPUT \D0.STARTIO)
	      (DECLARE: DONTCOPY (CONSTANTS * D0DEVICES)
			(EXPORT (PROP DOPVAL \DEVICE.INPUT \DEVICE.OUTPUT \D0.STARTIO))))))



(* Stuff which should be somwhere else!)


(RPAQ? ERRORMESSAGESTREAM T)

(RPAQ? PROMPTWINDOW T)
(DECLARE: DOEVAL@COMPILE DONTCOPY

(GLOBALVARS ERRORMESSAGESTREAM PROMPTWINDOW)
)



(* Queue management for data which can be chain-linked through the first cell)

(DECLARE: DONTCOPY 
(* FOLLOWING DEFINITIONS EXPORTED)


[DECLARE: EVAL@COMPILE 

(DATATYPE SYSQUEUE ((NIL BYTE)
		    (SYSQUEUEHEAD POINTER)
		    (NIL BYTE)
		    (SYSQUEUETAIL POINTER)))

(BLOCKRECORD QABLEITEM ((NIL BYTE)
			(QLINK POINTER)                      (* Link to next thing in queue always in first pointer 
							     of datum, independent of what the datum is)
			)
		       (BLOCKRECORD QABLEITEM ((NIL BYTE)
				     (LINK POINTER)          (* Let's also be able to call it a LINK)
				     )))
]
(/DECLAREDATATYPE (QUOTE SYSQUEUE)
		  (QUOTE (BYTE POINTER BYTE POINTER))
		  (QUOTE ((SYSQUEUE 0 (BITS . 7))
			  (SYSQUEUE 0 POINTER)
			  (SYSQUEUE 2 (BITS . 7))
			  (SYSQUEUE 2 POINTER)))
		  (QUOTE 4))
(DECLARE: EVAL@COMPILE 
(PUTPROPS \QUEUEHEAD MACRO ((Q)
	   (fetch (SYSQUEUE SYSQUEUEHEAD)
		  of Q)))
)


(* END EXPORTED DEFINITIONS)

)
(/DECLAREDATATYPE (QUOTE SYSQUEUE)
		  (QUOTE (BYTE POINTER BYTE POINTER))
		  (QUOTE ((SYSQUEUE 0 (BITS . 7))
			  (SYSQUEUE 0 POINTER)
			  (SYSQUEUE 2 (BITS . 7))
			  (SYSQUEUE 2 POINTER)))
		  (QUOTE 4))
[ADDTOVAR SYSTEMRECLST

(DATATYPE SYSQUEUE ((NIL BYTE)
		    (SYSQUEUEHEAD POINTER)
		    (NIL BYTE)
		    (SYSQUEUETAIL POINTER)))
]
(DEFINEQ

(\ENQUEUE
  [LAMBDA (Q ITEM)                                           (* bvm: "14-Feb-85 21:55")
                                                             (* Adds ITEM to tail of Q, which must be a SYSQUEUE 
							     datatype. ITEM must be describable by QABLEITEM.)
    (SETQ Q (\DTEST Q (QUOTE SYSQUEUE)))                     (* Do this \DTEST first, even though the fetch will 
							     also do it, so that no error occurs underneath the 
							     UNINTERRUPTABLY)
    (PROG (TAILEND JUNK)
          (UNINTERRUPTABLY
              [COND
		((NOT (ffetch SYSQUEUEHEAD of Q))            (* Empty queue)
		  (freplace SYSQUEUEHEAD of Q with ITEM))
		([NULL (fetch QLINK of (SETQ TAILEND (ffetch SYSQUEUETAIL of Q]
                                                             (* Normal case, SYSQUEUETAIL should have nothing after 
							     it)
		  (freplace QLINK of TAILEND with ITEM))
		(T 

          (* SYSQUEUETAIL has non-null link? Shouldn't happen, but folks who are sloppy about there queues can have this 
	  happen. Need to signal an error, but first at least patch the queue up so that while you're sitting in the break you
	  don't have more similar breaks)


		   (SETQ JUNK (LIST* "Tail at:" (LOC TAILEND)
				     "LINK:"
				     (fetch QLINK of TAILEND)
				     "Queue item locations:"
				     (to 100 bind THISITEM (NEXTITEM ←(ffetch SYSQUEUEHEAD
									 of Q))
					while (SETQ NEXTITEM (ffetch QLINK of (SETQ THISITEM NEXTITEM)
								     ))
					collect (LOC THISITEM)
					finally (COND
						  (THISITEM (replace QLINK of THISITEM with ITEM]
	      (freplace QLINK of ITEM with NIL)              (* Just for safety -- who knows what garbage may have 
							     creeped into the LINK slot of ITEM)
	      (freplace SYSQUEUETAIL of Q with ITEM))
          (AND JUNK (ERROR "Tail of queue has non-NIL link ptr" JUNK)))
    ITEM])

(\DEQUEUE
  (LAMBDA (Q)                                                (* bvm: " 4-FEB-83 13:05")
                                                             (* Removes and returns the top item on Q, which should 
							     be a SYSQUEUE datatype. Returns NIL if queue is empty.)
    (SETQ Q (\DTEST Q (QUOTE SYSQUEUE)))                     (* Do this \DTEST first, even though the fetch will 
							     also do it, so that no error occurs underneath the 
							     UNINTERRUPTABLY)
    (UNINTERRUPTABLY
        (PROG ((ITEM (fetch SYSQUEUEHEAD of Q)))
	      (if ITEM
		  then                                       (* First, "cdr" the link in the queue head)
		       (if (NULL (replace SYSQUEUEHEAD of Q with (fetch QLINK of ITEM)))
			   then                              (* Exhausted queue)
				(replace SYSQUEUETAIL of Q with NIL))
		       (replace QLINK of ITEM with NIL)      (* Break the connection that ITEM had with the queue.)
		  )
	      (RETURN ITEM)))))

(\QUEUELENGTH
  (LAMBDA (Q)                                                (* bvm: " 4-FEB-83 13:05")
    (PROG ((X (fetch SYSQUEUEHEAD of Q))
	   (CNT 0))
      LP  (OR X (RETURN CNT))
          (SETQ X (fetch QLINK of X))
          (add CNT 1)
          (GO LP))))

(\ONQUEUE
  (LAMBDA (ITEM Q)                                           (* bvm: " 4-FEB-83 13:04")
    (for (X ←(fetch (SYSQUEUE SYSQUEUEHEAD) of Q)) by (fetch QLINK of X) while X do (RETURN ITEM)
       when (EQ X ITEM))))

(\UNQUEUE
  (LAMBDA (QUEUE ITEM NOERRORFLG)                            (* bvm: " 6-FEB-83 18:27")

          (* * Removes ITEM from QUEUE, wherever it may be. Is error if ITEM not in QUEUE unless NOERRORFLG is true)


    (COND
      ((UNINTERRUPTABLY
           (bind (NEXT ←(fetch SYSQUEUEHEAD of QUEUE))
		 PREV while NEXT do (COND
				      ((EQ NEXT ITEM)
					(COND
					  ((NULL PREV)       (* removing head of queue)
					    (COND
					      ((NULL (replace SYSQUEUEHEAD of QUEUE
							with (fetch QLINK of ITEM)))
                                                             (* Exhausted queue)
						(replace SYSQUEUETAIL of QUEUE with NIL))))
					  ((NULL (replace QLINK of PREV with (fetch QLINK
										of ITEM)))
                                                             (* Removing last item)
					    (replace SYSQUEUETAIL of QUEUE with PREV)))
					(replace QLINK of ITEM with NIL)
					(RETURN ITEM))
				      (T (SETQ NEXT (fetch QLINK of (SETQ PREV NEXT))))))))
      ((NOT NOERRORFLG)
	(ERROR (LIST ITEM (QUOTE not)
		     (QUOTE on)
		     QUEUE))))))
)



(* Queue management constructed by TCONC)

(* FOLLOWING DEFINITIONS EXPORTED)


(DECLARE: EVAL@COMPILE 
(PUTPROPS \DETCONC MACRO (OPENLAMBDA (TQ)
				     (PROG1 (\PEEKTCONC TQ)
					    (if (NULL (CAR (RPLACA TQ (CDAR TQ))))
						then
						(RPLACD TQ)))))
(PUTPROPS \ENTCONC MACRO (= . TCONC))
(PUTPROPS \PEEKTCONC MACRO (= . CAAR))
)


(* END EXPORTED DEFINITIONS)




(* General packet management)

(DECLARE: DONTCOPY 
(* FOLLOWING DEFINITIONS EXPORTED)


[DECLARE: EVAL@COMPILE 

(DATATYPE ETHERPACKET ((NIL BYTE)
		       (EPLINK POINTER)                      (* For queue maintenence)
		       (EPFLAGS BYTE)                        (* optional flags for some applications)
		       (EPUSERFIELD POINTER)                 (* Arbitrary pointer for applications)
		       (NIL BYTE)
		       (EPPLIST POINTER)                     (* Extra field for use as an A-list for properties)
		       (EPTRANSMITTING FLAG)                 (* True while packet is being transmitted and hence 
							     cannot be reused)
		       (NIL BITS 7)
		       (EPREQUEUE POINTER)                   (* Where to requeue this packet after transmission)
		       (NIL BYTE)
		       (EPSOCKET POINTER)
		       (NIL BYTE)
		       (EPNETWORK POINTER)
		       (EPTYPE WORD)                         (* Type of packet to be encapsulated 
							     (PUP or XIP or 10TO3))
		       (NIL WORD)
		       (EPTIMESTAMP FIXP)                    (* Gets RCLK value when transmitted/received)
		       (EPREQUEUEFN POINTER)                 (* FN to perform requeueing)
		       (NIL 4 WORD)                          (* Space for expansion)
                                                             (* Note: This next field wants to be quad+2 aligned so 
							     that the 10mb packet is quad+3 aligned)
		       (EPENCAPSULATION 8 WORD)              (* 10mb encapsulation, or 3mb encapsulation with 
							     padding)
		       (EPBODY 289 WORD)                     (* Body of packet, header up to 16 words plus data up 
							     to 546 bytes)
		       ))

(ACCESSFNS ETHERAUX ((AUXPTR (CDR (ASSOC (QUOTE AUXPTR)
					 (fetch EPPLIST of DATUM)))
			     (\EP.PUT.AUX DATUM (QUOTE AUXPTR)
					  NEWVALUE))
		     (AUXWORD (OR (CDR (ASSOC (QUOTE AUXWORD)
					      (fetch EPPLIST of DATUM)))
				  0)
			      (\EP.PUT.AUX DATUM (QUOTE AUXWORD)
					   NEWVALUE))
		     (AUXBYTE (OR (CDR (ASSOC (QUOTE AUXBYTE)
					      (fetch EPPLIST of DATUM)))
				  0)
			      (\EP.PUT.AUX DATUM (QUOTE AUXBYTE)
					   NEWVALUE))))
]
(/DECLAREDATATYPE (QUOTE ETHERPACKET)
		  (QUOTE (BYTE POINTER BYTE POINTER BYTE POINTER FLAG (BITS 7)
			       POINTER BYTE POINTER BYTE POINTER WORD WORD FIXP POINTER WORD WORD 
			       WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD 
			       WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD 
			       WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD 
			       WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD 
			       WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD 
			       WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD 
			       WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD 
			       WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD 
			       WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD 
			       WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD 
			       WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD 
			       WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD 
			       WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD 
			       WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD 
			       WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD 
			       WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD 
			       WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD 
			       WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD 
			       WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD 
			       WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD 
			       WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD 
			       WORD WORD WORD WORD WORD))
		  (QUOTE ((ETHERPACKET 0 (BITS . 7))
			  (ETHERPACKET 0 POINTER)
			  (ETHERPACKET 2 (BITS . 7))
			  (ETHERPACKET 2 POINTER)
			  (ETHERPACKET 4 (BITS . 7))
			  (ETHERPACKET 4 POINTER)
			  (ETHERPACKET 6 (FLAGBITS . 0))
			  (ETHERPACKET 6 (BITS . 22))
			  (ETHERPACKET 6 POINTER)
			  (ETHERPACKET 8 (BITS . 7))
			  (ETHERPACKET 8 POINTER)
			  (ETHERPACKET 10 (BITS . 7))
			  (ETHERPACKET 10 POINTER)
			  (ETHERPACKET 12 (BITS . 15))
			  (ETHERPACKET 13 (BITS . 15))
			  (ETHERPACKET 14 FIXP)
			  (ETHERPACKET 16 POINTER)
			  (ETHERPACKET 18 (BITS . 15))
			  (ETHERPACKET 19 (BITS . 15))
			  (ETHERPACKET 20 (BITS . 15))
			  (ETHERPACKET 21 (BITS . 15))
			  (ETHERPACKET 22 (BITS . 15))
			  (ETHERPACKET 23 (BITS . 15))
			  (ETHERPACKET 24 (BITS . 15))
			  (ETHERPACKET 25 (BITS . 15))
			  (ETHERPACKET 26 (BITS . 15))
			  (ETHERPACKET 27 (BITS . 15))
			  (ETHERPACKET 28 (BITS . 15))
			  (ETHERPACKET 29 (BITS . 15))
			  (ETHERPACKET 30 (BITS . 15))
			  (ETHERPACKET 31 (BITS . 15))
			  (ETHERPACKET 32 (BITS . 15))
			  (ETHERPACKET 33 (BITS . 15))
			  (ETHERPACKET 34 (BITS . 15))
			  (ETHERPACKET 35 (BITS . 15))
			  (ETHERPACKET 36 (BITS . 15))
			  (ETHERPACKET 37 (BITS . 15))
			  (ETHERPACKET 38 (BITS . 15))
			  (ETHERPACKET 39 (BITS . 15))
			  (ETHERPACKET 40 (BITS . 15))
			  (ETHERPACKET 41 (BITS . 15))
			  (ETHERPACKET 42 (BITS . 15))
			  (ETHERPACKET 43 (BITS . 15))
			  (ETHERPACKET 44 (BITS . 15))
			  (ETHERPACKET 45 (BITS . 15))
			  (ETHERPACKET 46 (BITS . 15))
			  (ETHERPACKET 47 (BITS . 15))
			  (ETHERPACKET 48 (BITS . 15))
			  (ETHERPACKET 49 (BITS . 15))
			  (ETHERPACKET 50 (BITS . 15))
			  (ETHERPACKET 51 (BITS . 15))
			  (ETHERPACKET 52 (BITS . 15))
			  (ETHERPACKET 53 (BITS . 15))
			  (ETHERPACKET 54 (BITS . 15))
			  (ETHERPACKET 55 (BITS . 15))
			  (ETHERPACKET 56 (BITS . 15))
			  (ETHERPACKET 57 (BITS . 15))
			  (ETHERPACKET 58 (BITS . 15))
			  (ETHERPACKET 59 (BITS . 15))
			  (ETHERPACKET 60 (BITS . 15))
			  (ETHERPACKET 61 (BITS . 15))
			  (ETHERPACKET 62 (BITS . 15))
			  (ETHERPACKET 63 (BITS . 15))
			  (ETHERPACKET 64 (BITS . 15))
			  (ETHERPACKET 65 (BITS . 15))
			  (ETHERPACKET 66 (BITS . 15))
			  (ETHERPACKET 67 (BITS . 15))
			  (ETHERPACKET 68 (BITS . 15))
			  (ETHERPACKET 69 (BITS . 15))
			  (ETHERPACKET 70 (BITS . 15))
			  (ETHERPACKET 71 (BITS . 15))
			  (ETHERPACKET 72 (BITS . 15))
			  (ETHERPACKET 73 (BITS . 15))
			  (ETHERPACKET 74 (BITS . 15))
			  (ETHERPACKET 75 (BITS . 15))
			  (ETHERPACKET 76 (BITS . 15))
			  (ETHERPACKET 77 (BITS . 15))
			  (ETHERPACKET 78 (BITS . 15))
			  (ETHERPACKET 79 (BITS . 15))
			  (ETHERPACKET 80 (BITS . 15))
			  (ETHERPACKET 81 (BITS . 15))
			  (ETHERPACKET 82 (BITS . 15))
			  (ETHERPACKET 83 (BITS . 15))
			  (ETHERPACKET 84 (BITS . 15))
			  (ETHERPACKET 85 (BITS . 15))
			  (ETHERPACKET 86 (BITS . 15))
			  (ETHERPACKET 87 (BITS . 15))
			  (ETHERPACKET 88 (BITS . 15))
			  (ETHERPACKET 89 (BITS . 15))
			  (ETHERPACKET 90 (BITS . 15))
			  (ETHERPACKET 91 (BITS . 15))
			  (ETHERPACKET 92 (BITS . 15))
			  (ETHERPACKET 93 (BITS . 15))
			  (ETHERPACKET 94 (BITS . 15))
			  (ETHERPACKET 95 (BITS . 15))
			  (ETHERPACKET 96 (BITS . 15))
			  (ETHERPACKET 97 (BITS . 15))
			  (ETHERPACKET 98 (BITS . 15))
			  (ETHERPACKET 99 (BITS . 15))
			  (ETHERPACKET 100 (BITS . 15))
			  (ETHERPACKET 101 (BITS . 15))
			  (ETHERPACKET 102 (BITS . 15))
			  (ETHERPACKET 103 (BITS . 15))
			  (ETHERPACKET 104 (BITS . 15))
			  (ETHERPACKET 105 (BITS . 15))
			  (ETHERPACKET 106 (BITS . 15))
			  (ETHERPACKET 107 (BITS . 15))
			  (ETHERPACKET 108 (BITS . 15))
			  (ETHERPACKET 109 (BITS . 15))
			  (ETHERPACKET 110 (BITS . 15))
			  (ETHERPACKET 111 (BITS . 15))
			  (ETHERPACKET 112 (BITS . 15))
			  (ETHERPACKET 113 (BITS . 15))
			  (ETHERPACKET 114 (BITS . 15))
			  (ETHERPACKET 115 (BITS . 15))
			  (ETHERPACKET 116 (BITS . 15))
			  (ETHERPACKET 117 (BITS . 15))
			  (ETHERPACKET 118 (BITS . 15))
			  (ETHERPACKET 119 (BITS . 15))
			  (ETHERPACKET 120 (BITS . 15))
			  (ETHERPACKET 121 (BITS . 15))
			  (ETHERPACKET 122 (BITS . 15))
			  (ETHERPACKET 123 (BITS . 15))
			  (ETHERPACKET 124 (BITS . 15))
			  (ETHERPACKET 125 (BITS . 15))
			  (ETHERPACKET 126 (BITS . 15))
			  (ETHERPACKET 127 (BITS . 15))
			  (ETHERPACKET 128 (BITS . 15))
			  (ETHERPACKET 129 (BITS . 15))
			  (ETHERPACKET 130 (BITS . 15))
			  (ETHERPACKET 131 (BITS . 15))
			  (ETHERPACKET 132 (BITS . 15))
			  (ETHERPACKET 133 (BITS . 15))
			  (ETHERPACKET 134 (BITS . 15))
			  (ETHERPACKET 135 (BITS . 15))
			  (ETHERPACKET 136 (BITS . 15))
			  (ETHERPACKET 137 (BITS . 15))
			  (ETHERPACKET 138 (BITS . 15))
			  (ETHERPACKET 139 (BITS . 15))
			  (ETHERPACKET 140 (BITS . 15))
			  (ETHERPACKET 141 (BITS . 15))
			  (ETHERPACKET 142 (BITS . 15))
			  (ETHERPACKET 143 (BITS . 15))
			  (ETHERPACKET 144 (BITS . 15))
			  (ETHERPACKET 145 (BITS . 15))
			  (ETHERPACKET 146 (BITS . 15))
			  (ETHERPACKET 147 (BITS . 15))
			  (ETHERPACKET 148 (BITS . 15))
			  (ETHERPACKET 149 (BITS . 15))
			  (ETHERPACKET 150 (BITS . 15))
			  (ETHERPACKET 151 (BITS . 15))
			  (ETHERPACKET 152 (BITS . 15))
			  (ETHERPACKET 153 (BITS . 15))
			  (ETHERPACKET 154 (BITS . 15))
			  (ETHERPACKET 155 (BITS . 15))
			  (ETHERPACKET 156 (BITS . 15))
			  (ETHERPACKET 157 (BITS . 15))
			  (ETHERPACKET 158 (BITS . 15))
			  (ETHERPACKET 159 (BITS . 15))
			  (ETHERPACKET 160 (BITS . 15))
			  (ETHERPACKET 161 (BITS . 15))
			  (ETHERPACKET 162 (BITS . 15))
			  (ETHERPACKET 163 (BITS . 15))
			  (ETHERPACKET 164 (BITS . 15))
			  (ETHERPACKET 165 (BITS . 15))
			  (ETHERPACKET 166 (BITS . 15))
			  (ETHERPACKET 167 (BITS . 15))
			  (ETHERPACKET 168 (BITS . 15))
			  (ETHERPACKET 169 (BITS . 15))
			  (ETHERPACKET 170 (BITS . 15))
			  (ETHERPACKET 171 (BITS . 15))
			  (ETHERPACKET 172 (BITS . 15))
			  (ETHERPACKET 173 (BITS . 15))
			  (ETHERPACKET 174 (BITS . 15))
			  (ETHERPACKET 175 (BITS . 15))
			  (ETHERPACKET 176 (BITS . 15))
			  (ETHERPACKET 177 (BITS . 15))
			  (ETHERPACKET 178 (BITS . 15))
			  (ETHERPACKET 179 (BITS . 15))
			  (ETHERPACKET 180 (BITS . 15))
			  (ETHERPACKET 181 (BITS . 15))
			  (ETHERPACKET 182 (BITS . 15))
			  (ETHERPACKET 183 (BITS . 15))
			  (ETHERPACKET 184 (BITS . 15))
			  (ETHERPACKET 185 (BITS . 15))
			  (ETHERPACKET 186 (BITS . 15))
			  (ETHERPACKET 187 (BITS . 15))
			  (ETHERPACKET 188 (BITS . 15))
			  (ETHERPACKET 189 (BITS . 15))
			  (ETHERPACKET 190 (BITS . 15))
			  (ETHERPACKET 191 (BITS . 15))
			  (ETHERPACKET 192 (BITS . 15))
			  (ETHERPACKET 193 (BITS . 15))
			  (ETHERPACKET 194 (BITS . 15))
			  (ETHERPACKET 195 (BITS . 15))
			  (ETHERPACKET 196 (BITS . 15))
			  (ETHERPACKET 197 (BITS . 15))
			  (ETHERPACKET 198 (BITS . 15))
			  (ETHERPACKET 199 (BITS . 15))
			  (ETHERPACKET 200 (BITS . 15))
			  (ETHERPACKET 201 (BITS . 15))
			  (ETHERPACKET 202 (BITS . 15))
			  (ETHERPACKET 203 (BITS . 15))
			  (ETHERPACKET 204 (BITS . 15))
			  (ETHERPACKET 205 (BITS . 15))
			  (ETHERPACKET 206 (BITS . 15))
			  (ETHERPACKET 207 (BITS . 15))
			  (ETHERPACKET 208 (BITS . 15))
			  (ETHERPACKET 209 (BITS . 15))
			  (ETHERPACKET 210 (BITS . 15))
			  (ETHERPACKET 211 (BITS . 15))
			  (ETHERPACKET 212 (BITS . 15))
			  (ETHERPACKET 213 (BITS . 15))
			  (ETHERPACKET 214 (BITS . 15))
			  (ETHERPACKET 215 (BITS . 15))
			  (ETHERPACKET 216 (BITS . 15))
			  (ETHERPACKET 217 (BITS . 15))
			  (ETHERPACKET 218 (BITS . 15))
			  (ETHERPACKET 219 (BITS . 15))
			  (ETHERPACKET 220 (BITS . 15))
			  (ETHERPACKET 221 (BITS . 15))
			  (ETHERPACKET 222 (BITS . 15))
			  (ETHERPACKET 223 (BITS . 15))
			  (ETHERPACKET 224 (BITS . 15))
			  (ETHERPACKET 225 (BITS . 15))
			  (ETHERPACKET 226 (BITS . 15))
			  (ETHERPACKET 227 (BITS . 15))
			  (ETHERPACKET 228 (BITS . 15))
			  (ETHERPACKET 229 (BITS . 15))
			  (ETHERPACKET 230 (BITS . 15))
			  (ETHERPACKET 231 (BITS . 15))
			  (ETHERPACKET 232 (BITS . 15))
			  (ETHERPACKET 233 (BITS . 15))
			  (ETHERPACKET 234 (BITS . 15))
			  (ETHERPACKET 235 (BITS . 15))
			  (ETHERPACKET 236 (BITS . 15))
			  (ETHERPACKET 237 (BITS . 15))
			  (ETHERPACKET 238 (BITS . 15))
			  (ETHERPACKET 239 (BITS . 15))
			  (ETHERPACKET 240 (BITS . 15))
			  (ETHERPACKET 241 (BITS . 15))
			  (ETHERPACKET 242 (BITS . 15))
			  (ETHERPACKET 243 (BITS . 15))
			  (ETHERPACKET 244 (BITS . 15))
			  (ETHERPACKET 245 (BITS . 15))
			  (ETHERPACKET 246 (BITS . 15))
			  (ETHERPACKET 247 (BITS . 15))
			  (ETHERPACKET 248 (BITS . 15))
			  (ETHERPACKET 249 (BITS . 15))
			  (ETHERPACKET 250 (BITS . 15))
			  (ETHERPACKET 251 (BITS . 15))
			  (ETHERPACKET 252 (BITS . 15))
			  (ETHERPACKET 253 (BITS . 15))
			  (ETHERPACKET 254 (BITS . 15))
			  (ETHERPACKET 255 (BITS . 15))
			  (ETHERPACKET 256 (BITS . 15))
			  (ETHERPACKET 257 (BITS . 15))
			  (ETHERPACKET 258 (BITS . 15))
			  (ETHERPACKET 259 (BITS . 15))
			  (ETHERPACKET 260 (BITS . 15))
			  (ETHERPACKET 261 (BITS . 15))
			  (ETHERPACKET 262 (BITS . 15))
			  (ETHERPACKET 263 (BITS . 15))
			  (ETHERPACKET 264 (BITS . 15))
			  (ETHERPACKET 265 (BITS . 15))
			  (ETHERPACKET 266 (BITS . 15))
			  (ETHERPACKET 267 (BITS . 15))
			  (ETHERPACKET 268 (BITS . 15))
			  (ETHERPACKET 269 (BITS . 15))
			  (ETHERPACKET 270 (BITS . 15))
			  (ETHERPACKET 271 (BITS . 15))
			  (ETHERPACKET 272 (BITS . 15))
			  (ETHERPACKET 273 (BITS . 15))
			  (ETHERPACKET 274 (BITS . 15))
			  (ETHERPACKET 275 (BITS . 15))
			  (ETHERPACKET 276 (BITS . 15))
			  (ETHERPACKET 277 (BITS . 15))
			  (ETHERPACKET 278 (BITS . 15))
			  (ETHERPACKET 279 (BITS . 15))
			  (ETHERPACKET 280 (BITS . 15))
			  (ETHERPACKET 281 (BITS . 15))
			  (ETHERPACKET 282 (BITS . 15))
			  (ETHERPACKET 283 (BITS . 15))
			  (ETHERPACKET 284 (BITS . 15))
			  (ETHERPACKET 285 (BITS . 15))
			  (ETHERPACKET 286 (BITS . 15))
			  (ETHERPACKET 287 (BITS . 15))
			  (ETHERPACKET 288 (BITS . 15))
			  (ETHERPACKET 289 (BITS . 15))
			  (ETHERPACKET 290 (BITS . 15))
			  (ETHERPACKET 291 (BITS . 15))
			  (ETHERPACKET 292 (BITS . 15))
			  (ETHERPACKET 293 (BITS . 15))
			  (ETHERPACKET 294 (BITS . 15))
			  (ETHERPACKET 295 (BITS . 15))
			  (ETHERPACKET 296 (BITS . 15))
			  (ETHERPACKET 297 (BITS . 15))
			  (ETHERPACKET 298 (BITS . 15))
			  (ETHERPACKET 299 (BITS . 15))
			  (ETHERPACKET 300 (BITS . 15))
			  (ETHERPACKET 301 (BITS . 15))
			  (ETHERPACKET 302 (BITS . 15))
			  (ETHERPACKET 303 (BITS . 15))
			  (ETHERPACKET 304 (BITS . 15))
			  (ETHERPACKET 305 (BITS . 15))
			  (ETHERPACKET 306 (BITS . 15))
			  (ETHERPACKET 307 (BITS . 15))
			  (ETHERPACKET 308 (BITS . 15))
			  (ETHERPACKET 309 (BITS . 15))
			  (ETHERPACKET 310 (BITS . 15))
			  (ETHERPACKET 311 (BITS . 15))
			  (ETHERPACKET 312 (BITS . 15))
			  (ETHERPACKET 313 (BITS . 15))
			  (ETHERPACKET 314 (BITS . 15))
			  (ETHERPACKET 315 (BITS . 15))
			  (ETHERPACKET 316 (BITS . 15))
			  (ETHERPACKET 317 (BITS . 15))
			  (ETHERPACKET 318 (BITS . 15))))
		  (QUOTE 320))
(DECLARE: EVAL@COMPILE 

(RPAQQ \EPT.PUP 512)

(RPAQQ \EPT.XIP 1536)

(RPAQQ \3MBTYPE.XIP 1536)

(RPAQQ \10MBTYPE.XIP 1536)

(RPAQQ \EPT.10TO3 1537)

(RPAQQ \3MBTYPE.10TO3 1537)

(RPAQQ \EPT.UNKNOWN 255)

(CONSTANTS \EPT.PUP \EPT.XIP \3MBTYPE.XIP \10MBTYPE.XIP \EPT.10TO3 \3MBTYPE.10TO3 \EPT.UNKNOWN)
)


(* END EXPORTED DEFINITIONS)


(DECLARE: DOEVAL@COMPILE DONTCOPY

(GLOBALVARS \FREE.PACKET.QUEUE)
)
)
(/DECLAREDATATYPE (QUOTE ETHERPACKET)
		  (QUOTE (BYTE POINTER BYTE POINTER BYTE POINTER FLAG (BITS 7)
			       POINTER BYTE POINTER BYTE POINTER WORD WORD FIXP POINTER WORD WORD 
			       WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD 
			       WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD 
			       WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD 
			       WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD 
			       WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD 
			       WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD 
			       WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD 
			       WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD 
			       WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD 
			       WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD 
			       WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD 
			       WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD 
			       WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD 
			       WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD 
			       WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD 
			       WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD 
			       WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD 
			       WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD 
			       WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD 
			       WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD 
			       WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD WORD 
			       WORD WORD WORD WORD WORD))
		  (QUOTE ((ETHERPACKET 0 (BITS . 7))
			  (ETHERPACKET 0 POINTER)
			  (ETHERPACKET 2 (BITS . 7))
			  (ETHERPACKET 2 POINTER)
			  (ETHERPACKET 4 (BITS . 7))
			  (ETHERPACKET 4 POINTER)
			  (ETHERPACKET 6 (FLAGBITS . 0))
			  (ETHERPACKET 6 (BITS . 22))
			  (ETHERPACKET 6 POINTER)
			  (ETHERPACKET 8 (BITS . 7))
			  (ETHERPACKET 8 POINTER)
			  (ETHERPACKET 10 (BITS . 7))
			  (ETHERPACKET 10 POINTER)
			  (ETHERPACKET 12 (BITS . 15))
			  (ETHERPACKET 13 (BITS . 15))
			  (ETHERPACKET 14 FIXP)
			  (ETHERPACKET 16 POINTER)
			  (ETHERPACKET 18 (BITS . 15))
			  (ETHERPACKET 19 (BITS . 15))
			  (ETHERPACKET 20 (BITS . 15))
			  (ETHERPACKET 21 (BITS . 15))
			  (ETHERPACKET 22 (BITS . 15))
			  (ETHERPACKET 23 (BITS . 15))
			  (ETHERPACKET 24 (BITS . 15))
			  (ETHERPACKET 25 (BITS . 15))
			  (ETHERPACKET 26 (BITS . 15))
			  (ETHERPACKET 27 (BITS . 15))
			  (ETHERPACKET 28 (BITS . 15))
			  (ETHERPACKET 29 (BITS . 15))
			  (ETHERPACKET 30 (BITS . 15))
			  (ETHERPACKET 31 (BITS . 15))
			  (ETHERPACKET 32 (BITS . 15))
			  (ETHERPACKET 33 (BITS . 15))
			  (ETHERPACKET 34 (BITS . 15))
			  (ETHERPACKET 35 (BITS . 15))
			  (ETHERPACKET 36 (BITS . 15))
			  (ETHERPACKET 37 (BITS . 15))
			  (ETHERPACKET 38 (BITS . 15))
			  (ETHERPACKET 39 (BITS . 15))
			  (ETHERPACKET 40 (BITS . 15))
			  (ETHERPACKET 41 (BITS . 15))
			  (ETHERPACKET 42 (BITS . 15))
			  (ETHERPACKET 43 (BITS . 15))
			  (ETHERPACKET 44 (BITS . 15))
			  (ETHERPACKET 45 (BITS . 15))
			  (ETHERPACKET 46 (BITS . 15))
			  (ETHERPACKET 47 (BITS . 15))
			  (ETHERPACKET 48 (BITS . 15))
			  (ETHERPACKET 49 (BITS . 15))
			  (ETHERPACKET 50 (BITS . 15))
			  (ETHERPACKET 51 (BITS . 15))
			  (ETHERPACKET 52 (BITS . 15))
			  (ETHERPACKET 53 (BITS . 15))
			  (ETHERPACKET 54 (BITS . 15))
			  (ETHERPACKET 55 (BITS . 15))
			  (ETHERPACKET 56 (BITS . 15))
			  (ETHERPACKET 57 (BITS . 15))
			  (ETHERPACKET 58 (BITS . 15))
			  (ETHERPACKET 59 (BITS . 15))
			  (ETHERPACKET 60 (BITS . 15))
			  (ETHERPACKET 61 (BITS . 15))
			  (ETHERPACKET 62 (BITS . 15))
			  (ETHERPACKET 63 (BITS . 15))
			  (ETHERPACKET 64 (BITS . 15))
			  (ETHERPACKET 65 (BITS . 15))
			  (ETHERPACKET 66 (BITS . 15))
			  (ETHERPACKET 67 (BITS . 15))
			  (ETHERPACKET 68 (BITS . 15))
			  (ETHERPACKET 69 (BITS . 15))
			  (ETHERPACKET 70 (BITS . 15))
			  (ETHERPACKET 71 (BITS . 15))
			  (ETHERPACKET 72 (BITS . 15))
			  (ETHERPACKET 73 (BITS . 15))
			  (ETHERPACKET 74 (BITS . 15))
			  (ETHERPACKET 75 (BITS . 15))
			  (ETHERPACKET 76 (BITS . 15))
			  (ETHERPACKET 77 (BITS . 15))
			  (ETHERPACKET 78 (BITS . 15))
			  (ETHERPACKET 79 (BITS . 15))
			  (ETHERPACKET 80 (BITS . 15))
			  (ETHERPACKET 81 (BITS . 15))
			  (ETHERPACKET 82 (BITS . 15))
			  (ETHERPACKET 83 (BITS . 15))
			  (ETHERPACKET 84 (BITS . 15))
			  (ETHERPACKET 85 (BITS . 15))
			  (ETHERPACKET 86 (BITS . 15))
			  (ETHERPACKET 87 (BITS . 15))
			  (ETHERPACKET 88 (BITS . 15))
			  (ETHERPACKET 89 (BITS . 15))
			  (ETHERPACKET 90 (BITS . 15))
			  (ETHERPACKET 91 (BITS . 15))
			  (ETHERPACKET 92 (BITS . 15))
			  (ETHERPACKET 93 (BITS . 15))
			  (ETHERPACKET 94 (BITS . 15))
			  (ETHERPACKET 95 (BITS . 15))
			  (ETHERPACKET 96 (BITS . 15))
			  (ETHERPACKET 97 (BITS . 15))
			  (ETHERPACKET 98 (BITS . 15))
			  (ETHERPACKET 99 (BITS . 15))
			  (ETHERPACKET 100 (BITS . 15))
			  (ETHERPACKET 101 (BITS . 15))
			  (ETHERPACKET 102 (BITS . 15))
			  (ETHERPACKET 103 (BITS . 15))
			  (ETHERPACKET 104 (BITS . 15))
			  (ETHERPACKET 105 (BITS . 15))
			  (ETHERPACKET 106 (BITS . 15))
			  (ETHERPACKET 107 (BITS . 15))
			  (ETHERPACKET 108 (BITS . 15))
			  (ETHERPACKET 109 (BITS . 15))
			  (ETHERPACKET 110 (BITS . 15))
			  (ETHERPACKET 111 (BITS . 15))
			  (ETHERPACKET 112 (BITS . 15))
			  (ETHERPACKET 113 (BITS . 15))
			  (ETHERPACKET 114 (BITS . 15))
			  (ETHERPACKET 115 (BITS . 15))
			  (ETHERPACKET 116 (BITS . 15))
			  (ETHERPACKET 117 (BITS . 15))
			  (ETHERPACKET 118 (BITS . 15))
			  (ETHERPACKET 119 (BITS . 15))
			  (ETHERPACKET 120 (BITS . 15))
			  (ETHERPACKET 121 (BITS . 15))
			  (ETHERPACKET 122 (BITS . 15))
			  (ETHERPACKET 123 (BITS . 15))
			  (ETHERPACKET 124 (BITS . 15))
			  (ETHERPACKET 125 (BITS . 15))
			  (ETHERPACKET 126 (BITS . 15))
			  (ETHERPACKET 127 (BITS . 15))
			  (ETHERPACKET 128 (BITS . 15))
			  (ETHERPACKET 129 (BITS . 15))
			  (ETHERPACKET 130 (BITS . 15))
			  (ETHERPACKET 131 (BITS . 15))
			  (ETHERPACKET 132 (BITS . 15))
			  (ETHERPACKET 133 (BITS . 15))
			  (ETHERPACKET 134 (BITS . 15))
			  (ETHERPACKET 135 (BITS . 15))
			  (ETHERPACKET 136 (BITS . 15))
			  (ETHERPACKET 137 (BITS . 15))
			  (ETHERPACKET 138 (BITS . 15))
			  (ETHERPACKET 139 (BITS . 15))
			  (ETHERPACKET 140 (BITS . 15))
			  (ETHERPACKET 141 (BITS . 15))
			  (ETHERPACKET 142 (BITS . 15))
			  (ETHERPACKET 143 (BITS . 15))
			  (ETHERPACKET 144 (BITS . 15))
			  (ETHERPACKET 145 (BITS . 15))
			  (ETHERPACKET 146 (BITS . 15))
			  (ETHERPACKET 147 (BITS . 15))
			  (ETHERPACKET 148 (BITS . 15))
			  (ETHERPACKET 149 (BITS . 15))
			  (ETHERPACKET 150 (BITS . 15))
			  (ETHERPACKET 151 (BITS . 15))
			  (ETHERPACKET 152 (BITS . 15))
			  (ETHERPACKET 153 (BITS . 15))
			  (ETHERPACKET 154 (BITS . 15))
			  (ETHERPACKET 155 (BITS . 15))
			  (ETHERPACKET 156 (BITS . 15))
			  (ETHERPACKET 157 (BITS . 15))
			  (ETHERPACKET 158 (BITS . 15))
			  (ETHERPACKET 159 (BITS . 15))
			  (ETHERPACKET 160 (BITS . 15))
			  (ETHERPACKET 161 (BITS . 15))
			  (ETHERPACKET 162 (BITS . 15))
			  (ETHERPACKET 163 (BITS . 15))
			  (ETHERPACKET 164 (BITS . 15))
			  (ETHERPACKET 165 (BITS . 15))
			  (ETHERPACKET 166 (BITS . 15))
			  (ETHERPACKET 167 (BITS . 15))
			  (ETHERPACKET 168 (BITS . 15))
			  (ETHERPACKET 169 (BITS . 15))
			  (ETHERPACKET 170 (BITS . 15))
			  (ETHERPACKET 171 (BITS . 15))
			  (ETHERPACKET 172 (BITS . 15))
			  (ETHERPACKET 173 (BITS . 15))
			  (ETHERPACKET 174 (BITS . 15))
			  (ETHERPACKET 175 (BITS . 15))
			  (ETHERPACKET 176 (BITS . 15))
			  (ETHERPACKET 177 (BITS . 15))
			  (ETHERPACKET 178 (BITS . 15))
			  (ETHERPACKET 179 (BITS . 15))
			  (ETHERPACKET 180 (BITS . 15))
			  (ETHERPACKET 181 (BITS . 15))
			  (ETHERPACKET 182 (BITS . 15))
			  (ETHERPACKET 183 (BITS . 15))
			  (ETHERPACKET 184 (BITS . 15))
			  (ETHERPACKET 185 (BITS . 15))
			  (ETHERPACKET 186 (BITS . 15))
			  (ETHERPACKET 187 (BITS . 15))
			  (ETHERPACKET 188 (BITS . 15))
			  (ETHERPACKET 189 (BITS . 15))
			  (ETHERPACKET 190 (BITS . 15))
			  (ETHERPACKET 191 (BITS . 15))
			  (ETHERPACKET 192 (BITS . 15))
			  (ETHERPACKET 193 (BITS . 15))
			  (ETHERPACKET 194 (BITS . 15))
			  (ETHERPACKET 195 (BITS . 15))
			  (ETHERPACKET 196 (BITS . 15))
			  (ETHERPACKET 197 (BITS . 15))
			  (ETHERPACKET 198 (BITS . 15))
			  (ETHERPACKET 199 (BITS . 15))
			  (ETHERPACKET 200 (BITS . 15))
			  (ETHERPACKET 201 (BITS . 15))
			  (ETHERPACKET 202 (BITS . 15))
			  (ETHERPACKET 203 (BITS . 15))
			  (ETHERPACKET 204 (BITS . 15))
			  (ETHERPACKET 205 (BITS . 15))
			  (ETHERPACKET 206 (BITS . 15))
			  (ETHERPACKET 207 (BITS . 15))
			  (ETHERPACKET 208 (BITS . 15))
			  (ETHERPACKET 209 (BITS . 15))
			  (ETHERPACKET 210 (BITS . 15))
			  (ETHERPACKET 211 (BITS . 15))
			  (ETHERPACKET 212 (BITS . 15))
			  (ETHERPACKET 213 (BITS . 15))
			  (ETHERPACKET 214 (BITS . 15))
			  (ETHERPACKET 215 (BITS . 15))
			  (ETHERPACKET 216 (BITS . 15))
			  (ETHERPACKET 217 (BITS . 15))
			  (ETHERPACKET 218 (BITS . 15))
			  (ETHERPACKET 219 (BITS . 15))
			  (ETHERPACKET 220 (BITS . 15))
			  (ETHERPACKET 221 (BITS . 15))
			  (ETHERPACKET 222 (BITS . 15))
			  (ETHERPACKET 223 (BITS . 15))
			  (ETHERPACKET 224 (BITS . 15))
			  (ETHERPACKET 225 (BITS . 15))
			  (ETHERPACKET 226 (BITS . 15))
			  (ETHERPACKET 227 (BITS . 15))
			  (ETHERPACKET 228 (BITS . 15))
			  (ETHERPACKET 229 (BITS . 15))
			  (ETHERPACKET 230 (BITS . 15))
			  (ETHERPACKET 231 (BITS . 15))
			  (ETHERPACKET 232 (BITS . 15))
			  (ETHERPACKET 233 (BITS . 15))
			  (ETHERPACKET 234 (BITS . 15))
			  (ETHERPACKET 235 (BITS . 15))
			  (ETHERPACKET 236 (BITS . 15))
			  (ETHERPACKET 237 (BITS . 15))
			  (ETHERPACKET 238 (BITS . 15))
			  (ETHERPACKET 239 (BITS . 15))
			  (ETHERPACKET 240 (BITS . 15))
			  (ETHERPACKET 241 (BITS . 15))
			  (ETHERPACKET 242 (BITS . 15))
			  (ETHERPACKET 243 (BITS . 15))
			  (ETHERPACKET 244 (BITS . 15))
			  (ETHERPACKET 245 (BITS . 15))
			  (ETHERPACKET 246 (BITS . 15))
			  (ETHERPACKET 247 (BITS . 15))
			  (ETHERPACKET 248 (BITS . 15))
			  (ETHERPACKET 249 (BITS . 15))
			  (ETHERPACKET 250 (BITS . 15))
			  (ETHERPACKET 251 (BITS . 15))
			  (ETHERPACKET 252 (BITS . 15))
			  (ETHERPACKET 253 (BITS . 15))
			  (ETHERPACKET 254 (BITS . 15))
			  (ETHERPACKET 255 (BITS . 15))
			  (ETHERPACKET 256 (BITS . 15))
			  (ETHERPACKET 257 (BITS . 15))
			  (ETHERPACKET 258 (BITS . 15))
			  (ETHERPACKET 259 (BITS . 15))
			  (ETHERPACKET 260 (BITS . 15))
			  (ETHERPACKET 261 (BITS . 15))
			  (ETHERPACKET 262 (BITS . 15))
			  (ETHERPACKET 263 (BITS . 15))
			  (ETHERPACKET 264 (BITS . 15))
			  (ETHERPACKET 265 (BITS . 15))
			  (ETHERPACKET 266 (BITS . 15))
			  (ETHERPACKET 267 (BITS . 15))
			  (ETHERPACKET 268 (BITS . 15))
			  (ETHERPACKET 269 (BITS . 15))
			  (ETHERPACKET 270 (BITS . 15))
			  (ETHERPACKET 271 (BITS . 15))
			  (ETHERPACKET 272 (BITS . 15))
			  (ETHERPACKET 273 (BITS . 15))
			  (ETHERPACKET 274 (BITS . 15))
			  (ETHERPACKET 275 (BITS . 15))
			  (ETHERPACKET 276 (BITS . 15))
			  (ETHERPACKET 277 (BITS . 15))
			  (ETHERPACKET 278 (BITS . 15))
			  (ETHERPACKET 279 (BITS . 15))
			  (ETHERPACKET 280 (BITS . 15))
			  (ETHERPACKET 281 (BITS . 15))
			  (ETHERPACKET 282 (BITS . 15))
			  (ETHERPACKET 283 (BITS . 15))
			  (ETHERPACKET 284 (BITS . 15))
			  (ETHERPACKET 285 (BITS . 15))
			  (ETHERPACKET 286 (BITS . 15))
			  (ETHERPACKET 287 (BITS . 15))
			  (ETHERPACKET 288 (BITS . 15))
			  (ETHERPACKET 289 (BITS . 15))
			  (ETHERPACKET 290 (BITS . 15))
			  (ETHERPACKET 291 (BITS . 15))
			  (ETHERPACKET 292 (BITS . 15))
			  (ETHERPACKET 293 (BITS . 15))
			  (ETHERPACKET 294 (BITS . 15))
			  (ETHERPACKET 295 (BITS . 15))
			  (ETHERPACKET 296 (BITS . 15))
			  (ETHERPACKET 297 (BITS . 15))
			  (ETHERPACKET 298 (BITS . 15))
			  (ETHERPACKET 299 (BITS . 15))
			  (ETHERPACKET 300 (BITS . 15))
			  (ETHERPACKET 301 (BITS . 15))
			  (ETHERPACKET 302 (BITS . 15))
			  (ETHERPACKET 303 (BITS . 15))
			  (ETHERPACKET 304 (BITS . 15))
			  (ETHERPACKET 305 (BITS . 15))
			  (ETHERPACKET 306 (BITS . 15))
			  (ETHERPACKET 307 (BITS . 15))
			  (ETHERPACKET 308 (BITS . 15))
			  (ETHERPACKET 309 (BITS . 15))
			  (ETHERPACKET 310 (BITS . 15))
			  (ETHERPACKET 311 (BITS . 15))
			  (ETHERPACKET 312 (BITS . 15))
			  (ETHERPACKET 313 (BITS . 15))
			  (ETHERPACKET 314 (BITS . 15))
			  (ETHERPACKET 315 (BITS . 15))
			  (ETHERPACKET 316 (BITS . 15))
			  (ETHERPACKET 317 (BITS . 15))
			  (ETHERPACKET 318 (BITS . 15))))
		  (QUOTE 320))
[ADDTOVAR SYSTEMRECLST

(DATATYPE ETHERPACKET ((NIL BYTE)
		       (EPLINK POINTER)
		       (EPFLAGS BYTE)
		       (EPUSERFIELD POINTER)
		       (NIL BYTE)
		       (EPPLIST POINTER)
		       (EPTRANSMITTING FLAG)
		       (NIL BITS 7)
		       (EPREQUEUE POINTER)
		       (NIL BYTE)
		       (EPSOCKET POINTER)
		       (NIL BYTE)
		       (EPNETWORK POINTER)
		       (EPTYPE WORD)
		       (NIL WORD)
		       (EPTIMESTAMP FIXP)
		       (EPREQUEUEFN POINTER)
		       (NIL 4 WORD)
		       (EPENCAPSULATION 8 WORD)
		       (EPBODY 289 WORD)))
]
(DEFINEQ

(\ALLOCATE.ETHERPACKET
  [LAMBDA NIL                                                (* bvm: "14-Feb-85 21:58")
    (DECLARE (GLOBALVARS \NEWPACKETCOUNTER))
    (PROG ((PACKET (\DEQUEUE \FREE.PACKET.QUEUE)))
          (RETURN (COND
		    (PACKET (\CLEARWORDS (fetch XIPBASE of PACKET)
					 (FOLDHI \XIPOVLEN BYTESPERWORD))
                                                             (* Clear the header. XIP header is the larger, so this 
							     clears for ether pups or xips)
			    PACKET)
		    (T (COND
			 ((ILESSP (SETQ \NEWPACKETCOUNTER (SUB1 \NEWPACKETCOUNTER))
				  0)                         (* GC doesn't happen often enough, so too many packets 
							     tend to get created)
			   (RECLAIM)
			   (SETQ \NEWPACKETCOUNTER 5)))
		       (create ETHERPACKET])

(\RELEASE.ETHERPACKET
  (LAMBDA (EPKT)                                             (* bvm: " 3-MAR-83 15:14")
                                                             (* Free a ETHERPACKET -- might want to let GC do it, 
							     but GC doesn't happen often enough)
    (\DTEST EPKT (QUOTE ETHERPACKET))
    (COND
      ((NOT (AND (ffetch EPTRANSMITTING of EPKT)
		 (PROGN (freplace EPREQUEUE of EPKT with (QUOTE FREE))
			(ffetch EPTRANSMITTING of EPKT))))   (* Don't free it yet if it's still being transmitted.
							     Test twice in case it finished while we were setting 
							     EPREQUEUE)
	(freplace EPREQUEUE of EPKT with (freplace EPUSERFIELD of EPKT
					    with (freplace EPNETWORK of EPKT
						    with (freplace EPPLIST of EPKT
							    with (freplace EPSOCKET of EPKT
								    with NIL)))))
	(\ENQUEUE \FREE.PACKET.QUEUE EPKT)))
    NIL))

(RELEASE.PUP
  (LAMBDA (PUP)                                              (* bvm: " 3-MAR-83 16:14")
    (\RELEASE.ETHERPACKET PUP)))

(\FLUSH.PACKET.QUEUE
  (LAMBDA (QUEUE)                                            (* bvm: " 4-FEB-83 14:37")

          (* * Releases all packets in QUEUE and returns how many were flushed)


    (bind PACKET (CNT ← 0) while (SETQ PACKET (\DEQUEUE QUEUE))
       do (\RELEASE.ETHERPACKET PACKET)
	  (add CNT 1))))

(\REQUEUE.ETHERPACKET
  (LAMBDA (PACKET)                                           (* bvm: " 3-MAR-83 15:14")
    (PROG ((REQUEUE (fetch EPREQUEUE of PACKET)))
          (SELECTQ REQUEUE
		   ((NIL T))
		   (FREE (\RELEASE.ETHERPACKET PACKET))
		   (UNINTERRUPTABLY
                       (COND
			 ((type? SYSQUEUE REQUEUE)
			   (\ENQUEUE REQUEUE PACKET)))
		       (replace EPREQUEUE of PACKET with NIL))))))

(\EP.PUT.AUX
  (LAMBDA (PKT KEY VAL)                                      (* JonL " 8-JUL-82 21:45")
    (PROG ((PLIST (fetch EPPLIST of PKT))
	   A)
          (COND
	    ((NULL (SETQ A (ASSOC KEY PLIST)))
	      (COND
		((NEQ KEY (QUOTE AUXPTR))
		  ((LAMBDA (CELL)
		      (PutUnboxed CELL VAL)
		      (SETQ VAL CELL))
		    (CREATECELL \FIXP))))
	      (push (fetch EPPLIST of PKT)
		    (CONS KEY VAL)))
	    ((EQ KEY (QUOTE AUXPTR))
	      (RPLACD A VAL))
	    (T (PutUnboxed (CDR A)
			   VAL)
	       (SETQ VAL (CDR A))))
          (RETURN VAL))))
)

(RPAQ? \FREE.PACKET.QUEUE (NCREATE (QUOTE SYSQUEUE)))

(RPAQ? \NEWPACKETCOUNTER 5)
(/DECLAREDATATYPE (QUOTE NSADDRESS)
		  (QUOTE (FIXP WORD WORD WORD WORD))
		  (QUOTE ((NSADDRESS 0 FIXP)
			  (NSADDRESS 2 (BITS . 15))
			  (NSADDRESS 3 (BITS . 15))
			  (NSADDRESS 4 (BITS . 15))
			  (NSADDRESS 5 (BITS . 15))))
		  (QUOTE 6))

(RPAQ? \MY.NSHOSTNUMBER NIL)

(RPAQ? \MY.NSNETNUMBER NIL)

(RPAQ? \MY.NSADDRESS NIL)

(RPAQQ BROADCASTNSHOSTNUMBER (NSHOSTNUMBER 65535 65535 65535))
(DEFINEQ

(\SETLOCALNSNUMBERS
  [LAMBDA (TYPE)                                             (* bvm: "14-Feb-85 00:38")
    [SETQ \MY.NSHOSTNUMBER (COND
	((NEQ (LOGOR (fetch (IFPAGE NSHost0) of \InterfacePage)
		     (fetch (IFPAGE NSHost1) of \InterfacePage)
		     (fetch (IFPAGE NSHost2) of \InterfacePage))
	      0)
	  (create NSHOSTNUMBER
		  NSHOST0 ←(fetch (IFPAGE NSHost0) of \InterfacePage)
		  NSHOST1 ←(fetch (IFPAGE NSHost1) of \InterfacePage)
		  NSHOST2 ←(fetch (IFPAGE NSHost2) of \InterfacePage)))
	(T (create NSHOSTNUMBER
		   NSHOST0 ← 0
		   NSHOST1 ← 5349
		   NSHOST2 ←(\SERIALNUMBER]
    (SETQ \MY.NSNETNUMBER 0)
    (SETQ \MY.NSADDRESS (create NSADDRESS
				NSHNM0 ←(fetch NSHOST0 of \MY.NSHOSTNUMBER)
				NSHNM1 ←(fetch NSHOST1 of \MY.NSHOSTNUMBER)
				NSHNM2 ←(fetch NSHOST2 of \MY.NSHOSTNUMBER])

(\LOADNSADDRESS
  (LAMBDA (BASE A)                                           (* JonL " 2-AUG-82 00:09")
    (PROG ((A (if (type? NSADDRESS A)
		  then A
		else (create NSADDRESS))))
          (\MOVENSADDRESSES BASE A)
          (RETURN A))))

(\STORENSADDRESS
  (LAMBDA (BASE A)                                           (* JonL " 2-AUG-82 00:11")
    (\MOVENSADDRESSES (\DTEST A (QUOTE NSADDRESS))
		      BASE)
    A))

(\PRINTNSADDRESS
  (LAMBDA (BASE FILE)                                        (* bvm: " 1-FEB-83 15:51")
    (if (ILESSP (IDIFFERENCE (LINELENGTH NIL FILE)
			     (POSITION FILE))
		(IPLUS 20 (IQUOTIENT (IPLUS 2 (INTEGERLENGTH (\GETBASE BASE 5)))
				     3)))
	then                                                 (* Find how many octal digits in the socket number.)
	     (TERPRI FILE))
    (printout FILE .I0.-8 (\MAKENUMBER (\GETBASE BASE 0)
				       (\GETBASE BASE 1))
	      "#" .I0.-8 (\GETBASE BASE 2)
	      "." .I0.-8 (\GETBASE BASE 3)
	      "." .I0.-8 (\GETBASE BASE 4)
	      "#" .I0.-8 (\GETBASE BASE 5))
    ""))

(\NSADDRESS.DEFPRINT
  (LAMBDA (BASE)                                             (* bvm: " 1-FEB-83 15:51")
    (LIST (CONCAT (OCTALSTRING (\MAKENUMBER (\GETBASE BASE 0)
					    (\GETBASE BASE 1)))
		  "#"
		  (OCTALSTRING (\GETBASE BASE 2))
		  "."
		  (OCTALSTRING (\GETBASE BASE 3))
		  "."
		  (OCTALSTRING (\GETBASE BASE 4))
		  "#"
		  (OCTALSTRING (\GETBASE BASE 5))))))

(\LOADNSHOSTNUMBER
  (LAMBDA (BASE OLDBOX)                                      (* bvm: "17-FEB-83 17:07")
    (COND
      ((NULL OLDBOX)
	(create NSHOSTNUMBER
		NSHOST0 ←(\GETBASE BASE 0)
		NSHOST1 ←(\GETBASE BASE 1)
		NSHOST2 ←(\GETBASE BASE 2)))
      ((type? NSHOSTNUMBER OLDBOX)
	(replace NSHOST0 of OLDBOX with (\GETBASE BASE 0))
	(replace NSHOST1 of OLDBOX with (\GETBASE BASE 1))
	(replace NSHOST2 of OLDBOX with (\GETBASE BASE 2))
	OLDBOX)
      (T (ERROR "ARG NOT NSHOSTNUMBER" OLDBOX)))))

(\STORENSHOSTNUMBER
  (LAMBDA (BASE NSHNM)                                       (* bvm: "17-FEB-83 17:07")
    (COND
      ((type? NSHOSTNUMBER NSHNM)
	(\PUTBASE BASE 0 (fetch NSHOST0 of NSHNM))
	(\PUTBASE BASE 1 (fetch NSHOST1 of NSHNM))
	(\PUTBASE BASE 2 (fetch NSHOST2 of NSHNM)))
      (T (ERROR "ARG NOT NSHOSTNUMBER" NSHNM)))
    NSHNM))

(PRINTNSHOSTNUMBER
  (LAMBDA (NSHOSTNUMBER FILE)                                (* bvm: " 5-AUG-83 15:12")
    (RESETFORM (RADIX 8)
	       (printout FILE (fetch NSHOST0 of NSHOSTNUMBER)
			 "."
			 (fetch NSHOST1 of NSHOSTNUMBER)
			 "."
			 (fetch NSHOST2 of NSHOSTNUMBER)))))
)
(DECLARE: EVAL@COMPILE DONTCOPY 

(RPAQQ NSADDRESSCOMS ((EXPORT (RECORDS NSADDRESS NSHOSTNUMBER)
			      (MACROS LOADNSHOSTNUMBER STORENSHOSTNUMBER \MOVENSADDRESSES 
				      \SWAPNSADDRESSES)
			      (CONSTANTS (\#WDS.NSADDRESS 6)
					 (\#WDS.NSHOSTNUMBER 3))
			      (MACROS \LOCALNSHOSTNUMBER \LOCALNSNETNUMBER \LOCALNSADDRESS 
				      \BLTLOCALHOSTNUMBER)
			      (GLOBALVARS BROADCASTNSHOSTNUMBER \MY.NSADDRESS \MY.NSHOSTNUMBER 
					  \MY.NSNETNUMBER))
		      (MACROS EQNSHOSTNUMBER EQBROADCASTBASE EQNSHOSTBASE)
		      (FNS TRANSLATE.NSH)
		      (ADDVARS (DONTCOMPILEFNS TRANSLATE.NSH))))
(* FOLLOWING DEFINITIONS EXPORTED)


[DECLARE: EVAL@COMPILE 

(DATATYPE NSADDRESS ((NSNET FIXP)
		     (NSHNM0 WORD)
		     (NSHNM1 WORD)
		     (NSHNM2 WORD)
		     (NSSOCKET WORD))
		    (ACCESSFNS (NSHOSTNUMBER (LOADNSHOSTNUMBER (LOCF (fetch NSHNM0 of DATUM)))
					     (STORENSHOSTNUMBER (LOCF (fetch NSHNM0 of DATUM))
								NEWVALUE)))
		    (BLOCKRECORD NSADDRESS ((NSNETHI WORD)
				  (NSNETLO WORD))))

(TYPERECORD NSHOSTNUMBER (NSHOST0 NSHOST1 NSHOST2))
]
(/DECLAREDATATYPE (QUOTE NSADDRESS)
		  (QUOTE (FIXP WORD WORD WORD WORD))
		  (QUOTE ((NSADDRESS 0 FIXP)
			  (NSADDRESS 2 (BITS . 15))
			  (NSADDRESS 3 (BITS . 15))
			  (NSADDRESS 4 (BITS . 15))
			  (NSADDRESS 5 (BITS . 15))))
		  (QUOTE 6))
(DECLARE: EVAL@COMPILE 
(PUTPROPS LOADNSHOSTNUMBER MACRO (= . \LOADNSHOSTNUMBER))
(PUTPROPS STORENSHOSTNUMBER MACRO (= . \STORENSHOSTNUMBER))
(PUTPROPS \MOVENSADDRESSES MACRO ((BASE1 BASE2)
	   (\BLT BASE2 BASE1 \#WDS.NSADDRESS)))
(PUTPROPS \SWAPNSADDRESSES MACRO (OPENLAMBDA (BASE1 BASE2)
					     (for I from 0 to (SUB1 \#WDS.NSADDRESS)
						  do
						  (\PUTBASE BASE1 I
							    (PROG1 (\GETBASE BASE2 I)
								   (\PUTBASE BASE2 I
									     (PROGN (\GETBASE BASE1 I)
										    )))))))
)
(DECLARE: EVAL@COMPILE 

(RPAQQ \#WDS.NSADDRESS 6)

(RPAQQ \#WDS.NSHOSTNUMBER 3)

(CONSTANTS (\#WDS.NSADDRESS 6)
	   (\#WDS.NSHOSTNUMBER 3))
)
(DECLARE: EVAL@COMPILE 
(PUTPROPS \LOCALNSHOSTNUMBER MACRO (NIL \MY.NSHOSTNUMBER))
(PUTPROPS \LOCALNSNETNUMBER MACRO (NIL \MY.NSNETNUMBER))
(PUTPROPS \LOCALNSADDRESS MACRO (NIL \MY.NSADDRESS))
(PUTPROPS \BLTLOCALHOSTNUMBER MACRO ((BASE)
	   (\BLT BASE (LOCF (fetch (IFPAGE NSHost0)
				   of \InterfacePage))
		 3)))
)
(DECLARE: DOEVAL@COMPILE DONTCOPY

(GLOBALVARS BROADCASTNSHOSTNUMBER \MY.NSADDRESS \MY.NSHOSTNUMBER \MY.NSNETNUMBER)
)


(* END EXPORTED DEFINITIONS)

(DECLARE: EVAL@COMPILE 
(PUTPROPS EQNSHOSTNUMBER MACRO (X (TRANSLATE.NSH X)))
(PUTPROPS EQBROADCASTBASE MACRO (OPENLAMBDA (X)
					    (EQ (LOGAND (\GETBASE X 0)
							(\GETBASE X 1)
							(\GETBASE X 2))
						65535)))
(PUTPROPS EQNSHOSTBASE MACRO (OPENLAMBDA (X Y)
					 (AND (type? NSHOSTNUMBER Y)
					      (EQ (\GETBASE X 2)
						  (fetch (NSHOSTNUMBER NSHOST2)
							 of Y))
					      (EQ (\GETBASE X 1)
						  (fetch (NSHOSTNUMBER NSHOST1)
							 of Y))
					      (EQ (\GETBASE X 0)
						  (fetch (NSHOSTNUMBER NSHOST0)
							 of Y)))))
)
(DEFINEQ

(TRANSLATE.NSH
  (LAMBDA (ARGS)                                             (* bvm: "28-Nov-83 17:32")
    (SETQ ARGS (CDR (DWIMIFY (CONS (QUOTE PROGN)
				   ARGS)
			     T)))
    (PROG ((ARG1 (CAR ARGS))
	   (ARG2 (CADR ARGS)))
          (RETURN (COND
		    ((OR (NLISTP ARG1)
			 (SELECTQ (CAR (SETQ ARG1 (OR (GETHASH ARG1 CLISPARRAY)
						      ARG1)))
				  ((LOADNSHOSTNUMBER \LOADNSHOSTNUMBER)
				    NIL)
				  T))
		      (LIST (QUOTE EQUAL)
			    ARG1 ARG2))
		    ((EQ ARG2 (QUOTE BROADCASTNSHOSTNUMBER))
		      (LIST (QUOTE EQBROADCASTBASE)
			    (CADR ARG1)))
		    (T (LIST (QUOTE EQNSHOSTBASE)
			     (CADR ARG1)
			     ARG2)))))))
)

(ADDTOVAR DONTCOMPILEFNS TRANSLATE.NSH)
)
(DECLARE: DONTEVAL@LOAD DOCOPY 
(DEFPRINT (QUOTE NSADDRESS)
	  (QUOTE \NSADDRESS.DEFPRINT))
)



(* Assorted Level 0)

(DEFINEQ

(\ETHERINIT
  (LAMBDA NIL                                                (* bvm: "14-MAR-83 11:47")

          (* * This gets us EVENT action to take care of pup stuff around LOGOUT, etc.)


    (MOVD (QUOTE \RELEASE.ETHERPACKET)
	  (QUOTE RELEASE.PUP))
    (MOVD (QUOTE \ALLOCATE.ETHERPACKET)
	  (QUOTE ALLOCATE.PUP))
    (\DEFINEDEVICE NIL (create FDEV
			       DEVICENAME ←(QUOTE ETHER)
			       EVENTFN ←(FUNCTION \ETHEREVENTFN)
			       DIRECTORYNAMEP ←(QUOTE NILL)
			       HOSTNAMEP ←(QUOTE NILL)))))

(\ETHEREVENTFN
  [LAMBDA (DEV EVENT)                                        (* edited: "21-Jun-85 18:17")
    (SELECTQ EVENT
	     ((NIL AFTERLOGOUT AFTERSYSOUT AFTERMAKESYS AFTERSAVEVM RESTART)
	       (PROG (NDB TURNOFFNS TIMESET)
		     (SETQ \PUP.READY (SETQ \NS.READY (SETQ \IP.READY)))
		     (\SETETHERFLAGS)
		     (\SETLOCALNSNUMBERS)
		     (\FLUSHNDBS EVENT)
		     [SETQ \3MBLOCALNDB (COND
			 (\3MBFLG (SETQ \LOCALNDBS (\3MB.CREATENDB \3MBFLG]
		     (SETQ \10MBLOCALNDB (COND
			 (\10MBFLG (SETQ NDB (\10MB.CREATENDB \10MBFLG))
				   (COND
				     (\LOCALNDBS (replace NDBNEXT of \LOCALNDBS with NDB))
				     (T (SETQ \LOCALNDBS NDB)))
				   NDB)))
		     [for (DB ← \LOCALNDBS) by (fetch NDBNEXT of DB) while DB
			do (\LOCKWORDS DB (fetch DTDSIZE of (\GETDTD (NTYPX DB]
		     [COND
		       ((OR \NSFLG (SETQ TURNOFFNS \10MBFLG))
                                                             (* Start NS before Pup so that when on 10 we can find 
							     out our pup number, which is done via NS protocol)
			 (\NSINIT EVENT)
			 (SETQ TIMESET (\NS.SETTIME]
		     (\STARTPUP EVENT)
		     (OR TIMESET (AND (EQ \PUP.READY T)
				      (\PUP.SETTIME))
			 [SELECTC \MACHINETYPE
				  (\DANDELION (NEQ 0 (fetch DLTODVALID of \IOPAGE)))
				  (IGREATERP (IDATE)
					     (CONSTANT (IDATE " 1-JAN-84 12:00"]
			 (printout PROMPTWINDOW T "[Time not set]"))
		     (COND
		       (\IPFLG (\IPINIT EVENT)))
		     (COND
		       (TURNOFFNS (STOPNS)))
		     (COND
		       (\GATEWAYFLG (\INIT.GATEWAY)))
		 T))
	     ((BEFOREMAKESYS BEFORELOGOUT BEFORESYSOUT BEFORESAVEVM)
	       (COND
		 ((EQ EVENT (QUOTE BEFORESAVEVM))            (* Save passwords in place outside vmem to avoid having
							     to reenter them later)
		   (\STASH.PASSWORDS))
		 (T                                          (* No need to flush this before SAVEVM)
		    (CLRHASH \ETHERPORTS)))
	       (CLRHASH LOGINPASSWORDS))
	     NIL])

(\SETETHERFLAGS
  (LAMBDA NIL                                                (* ejs: "27-Jul-85 21:56")
    (SELECTC \MACHINETYPE
	     (\DANDELION (SETQ \10MBFLG 0)
			 (SETQ \3MBFLG NIL))
	     (\DOLPHIN (COND
			 ((ILESSP (\SERIALNUMBER)
				  255)
			   (SETQ \3MBFLG T)
			   (SETQ \10MBFLG (COND
			       ((EQ (LRSH (\DEVICE.INPUT (LLSH 5 4))
					  8)
				    \DEVICE.10MBETHER)
				 5))))
			 (T (SETQ \3MBFLG NIL)
			    (SETQ \10MBFLG (COND
				((EQ (LRSH (\DEVICE.INPUT (LLSH 7 4))
					   8)
				     \DEVICE.10MBETHER)
				  7))))))
	     (\DORADO (SETQ \3MBFLG T)
		      (SETQ \10MBFLG NIL))
	     (\DAYBREAK (SETQ \3MBFLG NIL)
			(SETQ \10MBFLG 0))
	     (SHOULDNT))))

(\FLUSHNDBS
  (LAMBDA (EVENT)                                            (* bvm: " 4-AUG-83 22:51")
    (bind NDB QUEUE while (SETQ NDB \LOCALNDBS)
       do (SETQ \LOCALNDBS (fetch NDBNEXT of NDB))
	  (replace NDBNEXT of NDB with NIL)
	  (COND
	    ((EQ EVENT (QUOTE RESTART))
	      (APPLY* (fetch NDBETHERFLUSHER of NDB)
		      NDB)))
	  (DEL.PROCESS (fetch NDBWATCHER of NDB))
	  (replace NDBWATCHER of NDB with (replace NDBTRANSLATIONS of NDB with NIL))
	  (COND
	    ((SETQ QUEUE (fetch NDBTQ of NDB))
	      (\FLUSH.NDB.QUEUE QUEUE EVENT (QUOTE OUTPUT))
                                                             (* Don't do this just yet, because of possible race in 
							     \PUPGATELISTENER -
							     (replace NDBTQ of NDB with NIL))
	      ))
	  (COND
	    ((SETQ QUEUE (fetch NDBIQ of NDB))
	      (\FLUSH.NDB.QUEUE QUEUE EVENT (QUOTE INPUT))
	      (replace NDBIQ of NDB with NIL))))
    (SETQ \PUP.ROUTING.TABLE (CONS))
    (SETQ \NS.ROUTING.TABLE (CONS))))

(\FLUSH.NDB.QUEUE
  (LAMBDA (QUEUE EVENT USE)                                  (* bvm: " 8-JUL-83 18:10")

          (* * Release any packets on this QUEUE, and their IOCB's for USE if EVENT is RESTART)


    (bind PACKET IOCB while (SETQ PACKET (\DEQUEUE QUEUE))
       do (COND
	    ((AND (EQ EVENT (QUOTE RESTART))
		  (SETQ IOCB (fetch EPNETWORK of PACKET)))
	      (\RELEASE.IOCB IOCB USE)))
	  (\RELEASE.ETHERPACKET PACKET))))
)
(DEFINEQ

(\CHECKSUM
  [LAMBDA (BASE NWORDS INITSUM)                              (* bvm: "14-Feb-85 22:20")
    (PROG ((CHECKSUM (COND
		       (INITSUM (LOGAND INITSUM MASKWORD1'S))
		       (T 0)))
	   (ADDR BASE)
	   (CNT NWORDS))
          (while (IGREATERP CNT 0)
	     do 

          (* * Algorithm: Do 1's complement add of next base word, then rotate sum left one. If result is all ones, then make 
	  it zero)


		(COND
		  ([IGREATERP CHECKSUM (SETQ CHECKSUM (IPLUS16 CHECKSUM (\GETBASE ADDR 0]
                                                             (* There was a carry, so add it back in -- 
							     "end around carry")
		    (add CHECKSUM 1)))
		[SETQ CHECKSUM (COND
		    ((IGREATERP CHECKSUM 32767)
		      (LOGOR 1 (LLSH (LOGAND CHECKSUM 32767)
				     1)))
		    (T (LLSH CHECKSUM 1]                     (* ROT)
		(SETQ ADDR (\ADDBASE ADDR 1))
		(SETQ CNT (SUB1 CNT)))
          (RETURN (COND
		    ((EQ CHECKSUM MASKWORD1'S)
		      0)
		    (T CHECKSUM])

(\HANDLE.RAW.OTHER
  (LAMBDA (PACKET RAWTYPE)                                   (* bvm: "15-FEB-83 18:30")
    (COND
      (XIPTRACEFLG (printout XIPTRACEFILE "Dropping packet of unknown encapsulation type: ")
		   (COND
		     (RAWTYPE (printout XIPTRACEFILE "[ = #" .I0.-8 RAWTYPE "]")))))
    (\RELEASE.ETHERPACKET PACKET)))

(\HANDLE.RAW.PACKET
  (LAMBDA (PACKET)                                           (* bvm: " 8-JUN-83 16:56")
    (OR (AND (OR (NOT \ETHERLIGHTNING)
		 (NEQ (RAND 0 \ETHERLIGHTNING)
		      0))
	     (find FILTER in \PACKET.FILTERS bind (TYPE ←(fetch EPTYPE of PACKET))
		suchthat (APPLY* FILTER PACKET TYPE)))
	(\RELEASE.ETHERPACKET PACKET))))

(\ADD.PACKET.FILTER
  (LAMBDA (FILTER)                                           (* bvm: "17-FEB-83 15:17")
    (OR (FMEMB FILTER \PACKET.FILTERS)
	(SETQ \PACKET.FILTERS (NCONC1 \PACKET.FILTERS FILTER)))
    FILTER))

(\DEL.PACKET.FILTER
  (LAMBDA (FILTER)                                           (* bvm: "17-FEB-83 15:18")
    (COND
      ((FMEMB FILTER \PACKET.FILTERS)
	(SETQ \PACKET.FILTERS (DREMOVE FILTER \PACKET.FILTERS))
	T))))
)
(DECLARE: DONTCOPY 
(* FOLLOWING DEFINITIONS EXPORTED)


(DECLARE: EVAL@COMPILE 

(RPAQQ \NULLCHECKSUM 65535)

(CONSTANTS (\NULLCHECKSUM 65535))
)


(* END EXPORTED DEFINITIONS)


(DECLARE: DOEVAL@COMPILE DONTCOPY

(GLOBALVARS \PACKET.FILTERS \ETHERLIGHTNING)
)
)

(RPAQ? \PACKET.FILTERS NIL)

(RPAQ? \ETHERLIGHTNING )
(DECLARE: DONTEVAL@LOAD DOCOPY 
(\ETHERINIT)
(MOVD? (QUOTE NILL)
       (QUOTE BLOCK))
(MOVD? (QUOTE NILL)
       (QUOTE \STASH.PASSWORDS))
)



(* Assorted routing stuff)

(DECLARE: DONTCOPY 
(* FOLLOWING DEFINITIONS EXPORTED)


[DECLARE: EVAL@COMPILE 

(DATATYPE NDB ((NETTYPE BYTE)                                (* 10 or 3 for now)
	       (NDBNEXT POINTER)                             (* Link to next NDB)
	       (NDBPUPNET# BYTE)                             (* Pup number of this net. May be different from NS net
							     number, though not in Xerox world)
	       (NDBNSNET# POINTER)                           (* Can be 32-bits, so might as well leave its box 
							     around)
	       (NDBTASK# BYTE)                               (* Task # of this network)
	       (NDBBROADCASTP POINTER)                       (* Function that returns true if packet is of broadcast
							     type)
	       (NDBPUPHOST# BYTE)                            (* My pup address on this net.
							     NS address is global to all nets, so not needed here)
	       (NDBTRANSMITTER POINTER)                      (* Routine to send a raw packet on this net -
							     args NDB PACKET returns NIL on failure)
	       (NIL BYTE)
	       (NDBENCAPSULATOR POINTER)                     (* Routine to encapsulate and send a higher-level 
							     packet on this net -
							     args NDB PACKET HOST LENGTH TYPE)
	       (NDBCSB POINTER)                              (* Pointer to CSB for this network)
	       (NDBIQLENGTH BYTE)
	       (NDBIQ POINTER)                               (* Queue of empty packets for receiver)
	       (NDBTQ POINTER)                               (* Queue of packets to transmit)
	       (NDBTRANSLATIONS POINTER)                     (* Cache of translations, 3:10 or 10:3 according to 
							     network)
	       (NDBETHERFLUSHER POINTER)                     (* Turns off this ether. Args NDB)
	       (NDBWATCHER POINTER)
	       (NDBCANHEARSELF POINTER)                      (* True if receiver can hear packets sent by 
							     transmitter)
	       (NDBIPNET# POINTER)
	       (NDBIPHOST# POINTER)
	       (NDBPUPTYPE WORD)                             (* The packet encapsulation of PUP on this net)
	       (NIL WORD)
	       (NIL POINTER)                                 (* Spares)
	       ))

(RECORD ROUTING (RTNET# RTHOPCOUNT RTGATEWAY# RTNDB RTTIMER RTRECENT))
]
(/DECLAREDATATYPE (QUOTE NDB)
		  (QUOTE (BYTE POINTER BYTE POINTER BYTE POINTER BYTE POINTER BYTE POINTER POINTER 
			       BYTE POINTER POINTER POINTER POINTER POINTER POINTER POINTER POINTER 
			       WORD WORD POINTER))
		  (QUOTE ((NDB 0 (BITS . 7))
			  (NDB 0 POINTER)
			  (NDB 2 (BITS . 7))
			  (NDB 2 POINTER)
			  (NDB 4 (BITS . 7))
			  (NDB 4 POINTER)
			  (NDB 6 (BITS . 7))
			  (NDB 6 POINTER)
			  (NDB 8 (BITS . 7))
			  (NDB 8 POINTER)
			  (NDB 10 POINTER)
			  (NDB 10 (BITS . 7))
			  (NDB 12 POINTER)
			  (NDB 14 POINTER)
			  (NDB 16 POINTER)
			  (NDB 18 POINTER)
			  (NDB 20 POINTER)
			  (NDB 22 POINTER)
			  (NDB 24 POINTER)
			  (NDB 26 POINTER)
			  (NDB 28 (BITS . 15))
			  (NDB 29 (BITS . 15))
			  (NDB 30 POINTER)))
		  (QUOTE 32))


(* END EXPORTED DEFINITIONS)


(DECLARE: EVAL@COMPILE 

(RPAQQ \RT.INFINITY 16)

(CONSTANTS \RT.INFINITY)
)

(DECLARE: EVAL@COMPILE 
(PUTPROPS ENCAPSULATE.ETHERPACKET MACRO ((NDB PACKET HOST LENGTH TYPE)
	   (SPREADAPPLY* (fetch NDBENCAPSULATOR of NDB)
			 NDB PACKET HOST LENGTH TYPE)))
(PUTPROPS TRANSMIT.ETHERPACKET MACRO ((NDB PACKET)
	   (SPREADAPPLY* (fetch NDBTRANSMITTER of NDB)
			 NDB PACKET)))
(PUTPROPS BROADCASTP MACRO ((PACKET)
	   ((LAMBDA (NDB)
		    (AND NDB (APPLY* (fetch NDBBROADCASTP of NDB)
				     PACKET NDB)))
	    (fetch EPNETWORK of PACKET))))
(PUTPROPS .RTLOOKUP. MACRO ((NET TABLE)
	   (* Net numbers are currently smallp's so this is okay)
	   (ASSOC NET (CDR TABLE))))
)

(DECLARE: DOEVAL@COMPILE DONTCOPY

(GLOBALVARS \RT.TIMEOUTINTERVAL \RT.AGEINTERVAL \RT.PURGEFLG \GATEWAYFLG)
)

(DECLARE: DOEVAL@COMPILE DONTCOPY

(GLOBALVARS \3MBFLG \10MBFLG \3MBLOCALNDB \10MBLOCALNDB \LOCALNDBS \NSFLG \IPFLG \NS.ROUTING.TABLE 
	    \PUP.ROUTING.TABLE \NS.READY \PUP.READY \IP.READY)
)
)
(/DECLAREDATATYPE (QUOTE NDB)
		  (QUOTE (BYTE POINTER BYTE POINTER BYTE POINTER BYTE POINTER BYTE POINTER POINTER 
			       BYTE POINTER POINTER POINTER POINTER POINTER POINTER POINTER POINTER 
			       WORD WORD POINTER))
		  (QUOTE ((NDB 0 (BITS . 7))
			  (NDB 0 POINTER)
			  (NDB 2 (BITS . 7))
			  (NDB 2 POINTER)
			  (NDB 4 (BITS . 7))
			  (NDB 4 POINTER)
			  (NDB 6 (BITS . 7))
			  (NDB 6 POINTER)
			  (NDB 8 (BITS . 7))
			  (NDB 8 POINTER)
			  (NDB 10 POINTER)
			  (NDB 10 (BITS . 7))
			  (NDB 12 POINTER)
			  (NDB 14 POINTER)
			  (NDB 16 POINTER)
			  (NDB 18 POINTER)
			  (NDB 20 POINTER)
			  (NDB 22 POINTER)
			  (NDB 24 POINTER)
			  (NDB 26 POINTER)
			  (NDB 28 (BITS . 15))
			  (NDB 29 (BITS . 15))
			  (NDB 30 POINTER)))
		  (QUOTE 32))
[ADDTOVAR SYSTEMRECLST

(DATATYPE NDB ((NETTYPE BYTE)
	       (NDBNEXT POINTER)
	       (NDBPUPNET# BYTE)
	       (NDBNSNET# POINTER)
	       (NDBTASK# BYTE)
	       (NDBBROADCASTP POINTER)
	       (NDBPUPHOST# BYTE)
	       (NDBTRANSMITTER POINTER)
	       (NIL BYTE)
	       (NDBENCAPSULATOR POINTER)
	       (NDBCSB POINTER)
	       (NDBIQLENGTH BYTE)
	       (NDBIQ POINTER)
	       (NDBTQ POINTER)
	       (NDBTRANSLATIONS POINTER)
	       (NDBETHERFLUSHER POINTER)
	       (NDBWATCHER POINTER)
	       (NDBCANHEARSELF POINTER)
	       (NDBIPNET# POINTER)
	       (NDBIPHOST# POINTER)
	       (NDBPUPTYPE WORD)
	       (NIL WORD)
	       (NIL POINTER)))
]
(DEFINEQ

(\AGE.ROUTING.TABLE
  (LAMBDA (TABLE)                                            (* bvm: "14-FEB-83 14:18")
    (for (TAIL ←(CDR TABLE))
	 (PREV ← TABLE) while TAIL bind ENTRY do (COND
						   ((COND
						       ((AND (NEQ (fetch RTHOPCOUNT
								     of (SETQ ENTRY (CAR TAIL)))
								  0)
							     (TIMEREXPIRED? (fetch RTTIMER
									       of ENTRY)))
                                                             (* Entry has timed out)
							 (COND
							   ((fetch RTRECENT of ENTRY)
                                                             (* New entry, make it old)
							     (replace RTRECENT of ENTRY with NIL)
							     (SETUPTIMER \RT.TIMEOUTINTERVAL
									 (fetch RTTIMER of ENTRY))
							     NIL)
							   (T \RT.PURGEFLG))))
						     (RPLACD PREV (SETQ TAIL (CDR TAIL))))
						   (T (SETQ TAIL (CDR (SETQ PREV TAIL))))))))

(\FLUSH.ROUTING.TABLE
  [LAMBDA (TABLE)                                            (* bvm: "14-Feb-85 00:38")
    (FRPLACD TABLE (for X in (CDR TABLE) collect X when (EQ (fetch RTHOPCOUNT of X)
							    0])

(PRINTROUTINGTABLE
  (LAMBDA (TABLE SORT FILE)                                  (* bvm: " 3-MAR-83 16:19")
    (SELECTQ TABLE
	     (NS (SETQ TABLE \NS.ROUTING.TABLE))
	     ((NIL PUP)
	       (SETQ TABLE \PUP.ROUTING.TABLE))
	     NIL)
    (RESETFORM (RADIX 8)
	       (printout FILE "Net#   Gateway     #Hops   Recent?" T)
	       (for ENTRY in (COND
			       (SORT (SORT (APPEND (CDR TABLE))
					   T))
			       (T (CDR TABLE)))
		  bind GATE
		  do (printout FILE .I4.8 (fetch RTNET# of ENTRY))
		     (COND
		       ((NOT (SETQ GATE (fetch RTGATEWAY# of ENTRY)))
			 (PRIN1 "      ---  " FILE))
		       ((FIXP GATE)
			 (printout FILE .I9.8 GATE))
		       (T (SPACES 2 FILE)
			  (PRINTNSHOSTNUMBER GATE FILE)))
		     (printout FILE 21 .I2 (fetch RTHOPCOUNT of ENTRY)
			       (COND
				 ((fetch RTRECENT of ENTRY)
				   "     Yes")
				 ((TIMEREXPIRED? (fetch RTTIMER of ENTRY))
				   "  timed out")
				 (T "     No"))
			       T))
	       (TERPRI FILE))))

(\MAP.ROUTING.TABLE
  (LAMBDA (TABLE MAPFN)                                      (* bvm: "22-SEP-83 14:21")
    (for ENTRY in (APPEND (CDR (OR TABLE \PUP.ROUTING.TABLE))) do (APPLY* MAPFN ENTRY))))
)
(DEFINEQ

(ENCAPSULATE.ETHERPACKET
  (LAMBDA (NDB PACKET PDH NBYTES ETYPE)                      (* bvm: "10-JUN-83 12:11")
    (APPLY* (ffetch NDBENCAPSULATOR of (\DTEST NDB (QUOTE NDB)))
	    NDB
	    (\DTEST PACKET (QUOTE ETHERPACKET))
	    PDH NBYTES ETYPE)))

(TRANSMIT.ETHERPACKET
  (LAMBDA (NDB PACKET)                                       (* bvm: "10-JUN-83 12:15")
    (APPLY* (ffetch NDBTRANSMITTER of (\DTEST NDB (QUOTE NDB)))
	    NDB
	    (\DTEST PACKET (QUOTE ETHERPACKET)))))
)

(RPAQ? \RT.TIMEOUTINTERVAL 90000)

(RPAQ? \RT.AGEINTERVAL 30000)

(RPAQ? \RT.PURGEFLG T)

(RPAQ? \GATEWAYFLG )

(RPAQ? \3MBFLG T)

(RPAQ? \10MBFLG )

(RPAQ? \3MBLOCALNDB )

(RPAQ? \10MBLOCALNDB )

(RPAQ? \LOCALNDBS )

(RPAQ? \NSFLG )

(RPAQ? \IPFLG )



(* 10 to 3 translation ugliness)

(DEFINEQ

(\TRANSLATE.10TO3
  (LAMBDA (NSHOSTNUMBER NDB)                                 (* bvm: "10-JUN-83 12:29")

          (* Translate from an NSHOSTNUMBER to a PUP host number for the indicated network. If we don't have the translation, 
	  we initiate a probe for it and return NIL)


    (OR (CADR (SASSOC NSHOSTNUMBER (ffetch NDBTRANSLATIONS of (\DTEST NDB (QUOTE NDB)))))
	(PROG ((PACKET (\ALLOCATE.ETHERPACKET)))
	      (replace EPTYPE of PACKET with \EPT.10TO3)
	      (freplace TRANSOPERATION of PACKET with \TRANS.OP.REQUEST)
	      (freplace TRANSNSHOST of PACKET with NSHOSTNUMBER)
	      (freplace TRANSSENDERNSHOST of PACKET with (\LOCALNSHOSTNUMBER))
	      (freplace TRANSSENDERPUPHOST of PACKET with (ffetch NDBPUPHOST# of NDB))
	      (ENCAPSULATE.ETHERPACKET NDB PACKET 0 \TRANS.DATALENGTH \EPT.10TO3)
	      (AND XIPTRACEFLG (\MAYBEPRINTPACKET PACKET (QUOTE PUT)))
	      (freplace EPREQUEUE of PACKET with (QUOTE FREE))
	      (TRANSMIT.ETHERPACKET NDB PACKET)              (* We didn't find out this time, but we will later on)
	      (RETURN)))))

(\NOTE.10TO3
  (LAMBDA (NSHOST PUPADDRESS NDB)                            (* bvm: "26-MAR-83 15:02")
                                                             (* Update cache to include this pairing)
    (PROG ((A (SASSOC NSHOST (ffetch NDBTRANSLATIONS of (\DTEST NDB (QUOTE NDB)))))
	   (HOST (fetch PUPHOST# of PUPADDRESS)))
          (COND
	    (A (RPLACA (CDR A)
		       HOST))
	    (T (push (ffetch NDBTRANSLATIONS of NDB)
		     (LIST NSHOST HOST (CLOCK 0))))))))

(\HANDLE.RAW.10TO3
  (LAMBDA (PACKET TYPE)                                      (* bvm: "10-JUN-83 12:31")

          (* Called when a TRANSLATION packet is received. This is either a packet requesting a 10-to-3 translation, in which 
	  case we respond if it is asking about us; or it is a response to a request of ours, in which case we store the info 
	  in the cache)


    (COND
      ((EQ TYPE \EPT.10TO3)
	(PROG ((NDB (fetch EPNETWORK of PACKET)))
	      (AND XIPTRACEFLG (\MAYBEPRINTPACKET PACKET (QUOTE GET)))
	      (SELECTC (fetch TRANSOPERATION of PACKET)
		       (\TRANS.OP.REQUEST (COND
					    ((EQNSHOSTNUMBER (fetch TRANSNSHOST of PACKET)
							     (\LOCALNSHOSTNUMBER))
                                                             (* It's for us)
					      (COND
						((IGEQ (fetch 3MBLENGTH of PACKET)
						       (IPLUS \3MBENCAPSULATION.WORDS
							      (FOLDHI \TRANS.DATALENGTH BYTESPERWORD))
						       )     (* Add sender's address to cache)
						  (\NOTE.10TO3 (fetch TRANSSENDERNSHOST of PACKET)
							       (fetch TRANSSENDERPUPHOST
								  of PACKET)
							       NDB)))
					      (replace TRANSPUPHOST of PACKET
						 with (fetch NDBPUPHOST# of NDB))
                                                             (* Add in the information he wants)
					      (replace TRANSOPERATION of PACKET with 
									       \TRANS.OP.RESPONSE)
					      (ENCAPSULATE.ETHERPACKET NDB PACKET
								       (fetch TRANSSENDERPUPHOST
									  of PACKET)
								       \TRANS.DATALENGTH \EPT.10TO3)
                                                             (* Send back the response)
					      (AND XIPTRACEFLG (NOT (MEMB (QUOTE TRANS)
									  XIPIGNORETYPES))
						   (PRINT10TO3 PACKET (QUOTE PUT)
							       XIPTRACEFILE))
					      (replace EPREQUEUE of PACKET with (QUOTE FREE))
					      (TRANSMIT.ETHERPACKET NDB PACKET)
					      (RETURN))))
		       (\TRANS.OP.RESPONSE                   (* Add the information to the cache)
					   (\NOTE.10TO3 (fetch TRANSNSHOST of PACKET)
							(fetch TRANSPUPHOST of PACKET)
							NDB))
		       (COND
			 (XIPTRACEFLG (printout XIPTRACEFILE "Bad 10:3 operation: "
						(fetch TRANSOPERATION of PACKET)
						T))))
	      (\RELEASE.ETHERPACKET PACKET))
	T))))
)
(DECLARE: DONTCOPY 
[DECLARE: EVAL@COMPILE 

(ACCESSFNS ETHERTRANS ((TRANSBODY (LOCF (fetch (ETHERPACKET EPBODY) of DATUM))))
		      (BLOCKRECORD TRANSBODY ((TRANSOPERATION WORD)
                                                             (* Request or response)
				    (BASETRANSNSHOST 3 WORD)
                                                             (* Known or desired NS address)
				    (TRANSPUPHOST BYTE)      (* Known or desired PUP address)
				    (NIL BYTE)               (* Padding)
				    (BASETRANSSENDERNSHOST 3 WORD)
                                                             (* Sender's info)
				    (TRANSSENDERPUPHOST BYTE)
				    (NIL BYTE))
				   (ACCESSFNS BASETRANSNSHOST ((TRANSCONTENTS (LOCF DATUM))))
				   (ACCESSFNS BASETRANSNSHOST ((TRANSNSHOST (\LOADNSHOSTNUMBER
									      (LOCF DATUM))
									    (\STORENSHOSTNUMBER
									      (LOCF DATUM)
									      NEWVALUE))))
				   (ACCESSFNS BASETRANSSENDERNSHOST ((TRANSSENDERNSHOST
						 (\LOADNSHOSTNUMBER (LOCF DATUM))
						 (\STORENSHOSTNUMBER (LOCF DATUM)
								     NEWVALUE)))))
		      (TYPE? (type? ETHERPACKET DATUM)))
]

(DECLARE: EVAL@COMPILE 

(RPAQQ \TRANS.OP.REQUEST 4161)

(RPAQQ \TRANS.OP.RESPONSE 3640)

(RPAQQ \TRANS.DATALENGTH 18)

(CONSTANTS \TRANS.OP.REQUEST \TRANS.OP.RESPONSE \TRANS.DATALENGTH)
)
)



(* Printing routines for packets)

(DEFINEQ

(PRINTPACKET
  (LAMBDA (PACKET CALLER FILE PRE.NOTE DOFILTER)             (* bvm: "18-FEB-83 15:25")
    (PROG ((TYPE (fetch EPTYPE of PACKET))
	   FN)
          (COND
	    ((SETQ FN (CDR (FASSOC TYPE \PACKET.PRINTERS)))
	      (RETURN (APPLY* FN PACKET CALLER FILE PRE.NOTE DOFILTER))))
          (OR FILE (SETQ FILE XIPTRACEFILE))
          (AND PRE.NOTE (printout FILE T PRE.NOTE))
          (AND CALLER (printout FILE CALLER ": "))
          (printout FILE "Unknown ether packet type: " TYPE T)
          (RETURN PACKET))))

(\MAYBEPRINTPACKET
  (LAMBDA (PACKET CALLER FILE PRE.NOTE)                      (* bvm: "18-JUN-83 20:57")
    (PROG ((TYPE (fetch EPTYPE of PACKET))
	   NDB)
          (SELECTQ (SELECTC TYPE
			    (\EPT.PUP PUPTRACEFLG)
			    XIPTRACEFLG)
		   (NIL)
		   (PEEK (PRIN1 (SELECTQ CALLER
					 ((GET RAWGET)
					   (COND
					     ((BROADCASTP PACKET)
					       (QUOTE *))
					     (T (QUOTE +))))
					 ((PUT RAWPUT)
					   (COND
					     ((BROADCASTP PACKET)
					       (QUOTE ↑))
					     (T (QUOTE !))))
					 (QUOTE ?))
				(OR FILE (SELECTC TYPE
						  (\EPT.PUP PUPTRACEFILE)
						  XIPTRACEFILE))))
		   (RAW (SELECTQ CALLER
				 ((RAWGET RAWPUT)
				   (PRINTPACKET PACKET CALLER FILE PRE.NOTE T))
				 (PRIN1 (SELECTQ CALLER
						 (GET (QUOTE #))
						 (PUT (QUOTE ↑))
						 (QUOTE ?))
					(OR FILE (SELECTC TYPE
							  (\EPT.PUP PUPTRACEFILE)
							  XIPTRACEFILE)))))
		   (PRINTPACKET PACKET CALLER FILE PRE.NOTE T)))))

(PRINT10TO3
  [LAMBDA (EPKT CALLER FILE PRE.NOTE DOFILTER)               (* bvm: "14-Feb-85 00:38")
    (COND
      ((OR (NOT DOFILTER)
	   (NOT (MEMB (QUOTE TRANS)
		      XIPIGNORETYPES)))
	(OR FILE (SETQ FILE XIPTRACEFILE))
	(FRESHLINE FILE)
	(COND
	  (PRE.NOTE (PRIN1 PRE.NOTE FILE)))
	(SELECTC (fetch TRANSOPERATION of EPKT)
		 (\TRANS.OP.REQUEST (printout FILE CALLER " 10:3 trans request for ")
				    (PRINTNSHOSTNUMBER (fetch TRANSNSHOST of EPKT)
						       FILE)
				    (printout FILE " from ")
				    (PRINTNSHOSTNUMBER (fetch TRANSSENDERNSHOST of EPKT)
						       FILE)
				    (printout FILE " = " (fetch TRANSSENDERPUPHOST of EPKT)
					      T))
		 (\TRANS.OP.RESPONSE (printout FILE CALLER " 10:3 trans response: ")
				     (PRINTNSHOSTNUMBER (fetch TRANSNSHOST of EPKT)
							FILE)
				     (printout FILE " = " (fetch TRANSPUPHOST of EPKT)
					       T))
		 (printout FILE CALLER " unknown 10 to 3 translation operation "
			   (fetch TRANSOPERATION of EPKT)
			   T])

(PRINTPACKETDATA
  (LAMBDA (BASE OFFSET MACRO LENGTH FILE)                    (* bvm: "26-MAY-83 12:27")

          (* * Prints to FILE the data portion of a packet starting at byte OFFSET (default zero) of BASE for LENGTH bytes 
	  according to MACRO. MACRO contains elements describing what format the data is in -
	  WORDS, BYTES, CHARS: print as words, numeric bytes or ascii characters -
	  IFSSTRING: data is a string whose length is in the first two bytes -
	  <positive number>: subsequent commands apply starting at this byte offset -
	  <negative number>: commands apply for the next {magnitude} bytes -
	  ...: print "..." and quit if you still have data at this point -
	  REPEAT: rest of macro should be applied repeatedly until data exhausted -
	  T: end of line -
	  SEPR: separate items (other than CHARS) with next token -
	  FINALLY: print next token when you get to the end)


    (OR OFFSET (SETQ OFFSET 0))
    (bind CHAR TMP FINALPRINT REPEATMACRO (SEPR ← ", ")
	  (TILOFFSET ← 0)
	  (DATATYPE ←(QUOTE WORDS))
	  (STREAM ←(GETSTREAM FILE (QUOTE OUTPUT))) while (ILESSP OFFSET LENGTH)
       do (while (AND (OR MACRO (SETQ MACRO REPEATMACRO))
		      (IGEQ OFFSET TILOFFSET))
	     do (SELECTQ (CAR MACRO)
			 ((WORDS BYTES CHARS INTEGERS)
			   (SETQ DATATYPE (CAR MACRO)))
			 ((WORD BYTE CHAR INTEGER)
			   (SETQ DATATYPE (PACK* (CAR MACRO)
						 (QUOTE S))))
			 (IFSSTRING                          (* Hack. Data is assumed to be a string whose first 
							     word is its length)
				    (SETQ TMP (\GETBASE BASE (FOLDLO OFFSET BYTESPERWORD)))
				    (printout STREAM (QUOTE {)
					      .P2 TMP (QUOTE }))
				    (add OFFSET 2)
				    (SETQ TILOFFSET (CEIL (IPLUS OFFSET TMP)
							  BYTESPERWORD))
				    (COND
				      ((NEQ DATATYPE (QUOTE BYTES))
					(SETQ DATATYPE (QUOTE CHARS)))))
			 (... (PRIN1 (QUOTE ...)
				     STREAM)
			      (SETQ DATATYPE (SETQ MACRO)))
			 (REPEAT (SETQ REPEATMACRO (CDR MACRO)))
			 (SEPR (SETQ SEPR (CADR MACRO))
			       (SETQ MACRO (CDR MACRO)))
			 (FINALLY (SETQ FINALPRINT (CAR (SETQ MACRO (CDR MACRO)))))
			 (T (TERPRI STREAM))
			 (COND
			   ((FIXP (CAR MACRO))
			     (SETQ TILOFFSET (COND
				 ((IGEQ (CAR MACRO)
					0)
				   (CAR MACRO))
				 (T                          (* Relative)
				    (IDIFFERENCE OFFSET (CAR MACRO))))))
			   (T (PRIN1 (CAR MACRO)
				     STREAM))))
		(SETQ MACRO (CDR MACRO)))
	  (SELECTQ DATATYPE
		   (WORDS (PRIN2 (\GETBASE BASE (FOLDLO OFFSET BYTESPERWORD))
				 STREAM)
			  (add OFFSET 2)
			  (COND
			    ((AND SEPR (ILESSP OFFSET LENGTH))
			      (PRIN1 SEPR STREAM))))
		   (INTEGERS (PRIN2 (\MAKENUMBER (\GETBASE BASE (SETQ TMP (FOLDLO OFFSET BYTESPERWORD)
							     ))
						 (\GETBASE BASE (ADD1 TMP)))
				    STREAM)
			     (add OFFSET 4)
			     (COND
			       ((AND SEPR (ILESSP OFFSET LENGTH))
				 (PRIN1 SEPR STREAM))))
		   (CHARS (COND
			    ((AND (IGEQ (SETQ CHAR (\GETBASEBYTE BASE OFFSET))
					(CHARCODE SPACE))
				  (ILESSP CHAR 127))
			      (\OUTCHAR STREAM CHAR))
			    ((AND (EQ CHAR (CHARCODE CR))
				  (IGREATERP LENGTH (ADD1 OFFSET))
				  (EQ (\GETBASEBYTE BASE (ADD1 OFFSET))
				      (CHARCODE LF)))
			      (PRIN1 "[crlf]" STREAM)
			      (add OFFSET 1))
			    (T (printout STREAM (QUOTE %[)
					 CHAR
					 (QUOTE %]))))
			  (add OFFSET 1))
		   (BYTES (printout STREAM (QUOTE %[)
				    (\GETBASEBYTE BASE OFFSET)
				    (QUOTE %]))
			  (add OFFSET 1))
		   (RETURN))
       finally (AND FINALPRINT (PRIN1 FINALPRINT STREAM)))
    (TERPRI FILE)))

(PRINTPACKETQUEUE
  (LAMBDA (QUEUE CALLER FILE)                                (* bvm: "21-APR-83 23:51")
    (for (PACKET ←(COND
		   ((type? SYSQUEUE QUEUE)
		     (fetch SYSQUEUEHEAD of QUEUE))
		   (T (\DTEST QUEUE (QUOTE ETHERPACKET)))))
       by (fetch EPLINK of PACKET) while PACKET do (PRINTPACKET PACKET CALLER FILE))))

(TIME.SINCE.PACKET
  (LAMBDA (PACKET)                                           (* bvm: "26-OCT-83 15:46")
                                                             (* Returns time in milliseconds since PACKET's 
							     EPTIMESTAMP was last set)
    (PROG ((CLK1 (\RCLK (\CREATECELL \FIXP)))
	   (CLK0 (\CREATECELL \FIXP)))
          (\BLT CLK0 (LOCF (fetch EPTIMESTAMP of PACKET))
		WORDSPERCELL)
          (RETURN (IQUOTIENT (\BOXIDIFFERENCE CLK1 CLK0)
			     \RCLKMILLISECOND)))))
)

(RPAQ? \RAWTRACING )

(ADDTOVAR \PACKET.PRINTERS (512 . PRINTPUP)
			   (1537 . PRINT10TO3))
(DECLARE: DOEVAL@COMPILE DONTCOPY

(GLOBALVARS \RAWTRACING \PACKET.PRINTERS PUPTRACEFILE XIPTRACEFILE)
)



(* 3MB stuff, which is not needed in DandeLion)

(DEFINEQ

(\3MBGETPACKET
  (LAMBDA NIL                                                (* bvm: "26-OCT-83 15:16")
    (PROG (PACKET)
          (RETURN (COND
		    ((UNINTERRUPTABLY
                         (PROG ((PBI (\READRAWPBI)))
			       (COND
				 (PBI (SETQ PACKET (\ALLOCATE.ETHERPACKET))
				      (\BLT (fetch 3MBBASE of PACKET)
					    (fetch PBIRAWSTART of PBI)
					    (ADD1 (fetch PBILENGTH of PBI)))
				      (COND
					((NEQ (fetch PBISOCKET of PBI)
					      0)
					  (HELP "PBI has a socket" PBI)))))
			       (RETURN PBI)))
		      (\BOXIPLUS (LOCF (fetch NETIOOPS of \MISCSTATS))
				 1)
		      (\RCLK (LOCF (fetch EPTIMESTAMP of PACKET)))
		      (replace EPNETWORK of PACKET with \3MBLOCALNDB)
		      (replace EPTYPE of PACKET with (fetch 3MBTYPE of PACKET))
		      (COND
			(\RAWTRACING (\MAYBEPRINTPACKET PACKET (QUOTE RAWGET))))
		      PACKET))))))

(\3MB.CREATENDB
  [LAMBDA NIL                                                (* bvm: "15-Feb-85 22:18")
    (create NDB
	    NDBPUPHOST# ←(\SERIALNUMBER)
	    NDBPUPNET# ← 0
	    NDBNSNET# ← 0
	    NETTYPE ← 3
	    NDBPUPTYPE ← \3MBTYPE.PUP
	    NDBTRANSMITTER ←(FUNCTION \3MBSENDPACKET)
	    NDBENCAPSULATOR ←(FUNCTION \3MBENCAPSULATE)
	    NDBBROADCASTP ←(FUNCTION \3MB.BROADCASTP)
	    NDBETHERFLUSHER ←(FUNCTION NILL)
	    NDBWATCHER ←(ADD.PROCESS (QUOTE (\3MBWATCHER))
				     (QUOTE RESTARTABLE)
				     (QUOTE SYSTEM)
				     (QUOTE AFTEREXIT)
				     (QUOTE DELETE])

(\3MBSENDPACKET
  (LAMBDA (NDB PACKET)                                       (* bvm: " 8-JUN-83 16:59")
                                                             (* Sends raw seething etherpacket on the 3mb net 
							     denoted by NDB)
    (SETQ PACKET (\DTEST PACKET (QUOTE ETHERPACKET)))
    (PROG NIL
          (AND \RAWTRACING (\MAYBEPRINTPACKET PACKET (QUOTE RAWPUT)))
          (COND
	    ((OR (NULL \ETHERLIGHTNING)
		 (NEQ (RAND 0 \ETHERLIGHTNING)
		      0))
	      (UNINTERRUPTABLY
                  (PROG ((PBI (\GETPACKETBUFFER)))
		        (OR PBI (RETURN (COND
					  (\RAWTRACING (PRIN1 (QUOTE x)
							      (SELECTC (fetch EPTYPE of PACKET)
								       (\EPT.PUP PUPTRACEFILE)
								       XIPTRACEFILE))))))
		        (\BLT (fetch PBIRAWSTART of PBI)
			      (fetch 3MBBASE of PACKET)
			      (ADD1 (fetch 3MBLENGTH of PACKET)))
		        (\WRITERAWPBI PBI)
		        (\BOXIPLUS (LOCF (fetch NETIOOPS of \MISCSTATS))
				   1)))))
          (\REQUEUE.ETHERPACKET PACKET)
          (RETURN T))))

(\3MBWATCHER
  (LAMBDA NIL                                                (* bvm: "26-OCT-83 15:21")

          (* * Process that watches the 3mb net and pulls packets in, passing them to the raw packet handler)


    (PROG ((CNTR 0)
	   PACKET)
      LP  (COND
	    ((SETQ PACKET (\3MBGETPACKET))                   (* Got something)
	      (\HANDLE.RAW.PACKET PACKET)
	      (COND
		((ILESSP (add CNTR 1)
			 \MAXWATCHERGETS)                    (* Hack to get better ether service in lieu of 
							     preemption)
		  (GO LP)))))
          (BLOCK)
          (SETQ CNTR 0)
          (GO LP))))

(\3MBENCAPSULATE
  (LAMBDA (NDB PACKET PDH LENGTH TYPE)                       (* bvm: " 7-MAR-83 12:44")
                                                             (* Encapsulates packets for 3mb net)
    (replace 3MBDESTHOST of PACKET with PDH)
    (replace 3MBSOURCEHOST of PACKET with (fetch NDBPUPHOST# of NDB))
    (replace 3MBLENGTH of PACKET with (IPLUS (FOLDHI LENGTH BYTESPERWORD)
					     \3MBENCAPSULATION.WORDS))
    (replace 3MBTYPE of PACKET with TYPE)
    PACKET))

(\3MB.BROADCASTP
  [LAMBDA (PACKET)                                           (* bvm: "14-Feb-85 00:38")
    (EQ (fetch 3MBDESTHOST of PACKET)
	0])

(\3MBFLUSH
  (LAMBDA (ASPROC)                                           (* bvm: "18-FEB-83 17:10")
    (PROG NIL
      LP  (RETURN (PROG1 (while (\READRAWPBI) sum 1)
			 (COND
			   (ASPROC (BLOCK 5000)
				   (GO LP))))))))
)

(RPAQ? \MAXWATCHERGETS 5)
(DECLARE: DONTCOPY 
[DECLARE: EVAL@COMPILE 

(ACCESSFNS 3MBENCAPSULATION ((3MBENCAPSTART (LOCF (fetch (ETHERPACKET EPENCAPSULATION) of DATUM))))
			    (BLOCKRECORD 3MBENCAPSTART ((NIL 5 WORD)
                                                             (* waste space)
					  (3MBLENGTH WORD)   (* Length of packet in words, starting at the next 
							     word)
					  (3MBDESTHOST BYTE)
                                                             (* Immediate destination host)
					  (3MBSOURCEHOST BYTE)
                                                             (* Us)
					  (3MBTYPE WORD)     (* Type of packet -- PUP or XIP or 10TO3)
					  )
					 (ACCESSFNS 3MBLENGTH ((3MBBASE (LOCF DATUM))))
                                                             (* What to hand to BCPL)
					 )
			    (TYPE? (type? ETHERPACKET DATUM)))

(BLOCKRECORD PBI ((PBILINK WORD)
		  (PBIQUEUE WORD)
		  (PBISOCKET WORD)
		  (PBINDB WORD)
		  (PBIINPUTP FLAG)
		  (PBIALLNETSP FLAG)
		  (PBINOZEROP FLAG)
		  (NIL BITS 13)
		  (PBITIMER WORD)
		  (PBILENGTH WORD)
		  (PBIENCAPSULATION 2 WORD)
		  (PBIFIRSTPUPWORD 10 WORD)
		  (PBIFIRSTPUPDATAWORD WORD))
		 (ACCESSFNS PBI ((PBIPUPSTART (LOCF (fetch PBIFIRSTPUPWORD of DATUM)))
			     (PBIPUPDATASTART (LOCF (fetch PBIFIRSTPUPDATAWORD of DATUM)))
			     (PBIRAWSTART (LOCF (fetch PBILENGTH of DATUM))))))
]

(* FOLLOWING DEFINITIONS EXPORTED)


(DECLARE: EVAL@COMPILE 
(PUTPROPS \SERIALNUMBER MACRO (NIL (fetch (IFPAGE SerialNumber)
					  of \InterfacePage)))
)


(* END EXPORTED DEFINITIONS)


(DECLARE: EVAL@COMPILE 

(RPAQQ \3MBENCAPSULATION.WORDS 2)

(RPAQQ \3MBTYPE.PUP 512)

(CONSTANTS \3MBENCAPSULATION.WORDS \3MBTYPE.PUP)
)

(DECLARE: DOEVAL@COMPILE DONTCOPY

(GLOBALVARS \MAXWATCHERGETS)
)
)



(* Debugging)

(DEFINEQ

(ASSURE.ETHER.ON
  (LAMBDA (USENS)                                            (* bvm: " 8-JUL-83 18:31")
    (OR (THIS.PROCESS)
	(ERROR "Processes not on!" "" T))
    (COND
      ((NOT \LOCALNDBS)
	(AND USENS (SETQ \NSFLG T))
	(\ETHEREVENTFN))
      ((AND USENS (NOT \NSFLG))
	(\NSINIT)))))

(INITPUPLEVEL1
  (LAMBDA (FLG)                                              (* bvm: " 5-MAY-83 23:49")
    (TURN.OFF.ETHER)
    (DEL.PROCESS (QUOTE \3MBFLUSH))
    (SELECTC \MACHINETYPE
	     (\DANDELION)
	     (\PUPLEVEL1STATE NIL))
    (ASSURE.ETHER.ON)
    (COND
      (FLG                                                   (* This hack used for Bootstrapping: we got called from
							     \PUPINIT in the evaluation of PUP's coms)
	   (HARDRESET)))))

(TURN.ON.ETHER
  (LAMBDA NIL                                                (* bvm: "26-MAR-83 15:55")
    (ASSURE.ETHER.ON \NSFLG)))

(RESTART.ETHER
  (LAMBDA NIL                                                (* bvm: "22-SEP-83 14:20")
    (PROG (PROC)
          (AND (SETQ PROC (FIND.PROCESS (QUOTE \PUPGATELISTENER)))
	       (SUSPEND.PROCESS PROC))
          (AND (SETQ PROC (FIND.PROCESS (QUOTE \NSGATELISTENER)))
	       (SUSPEND.PROCESS PROC)))
    (\ETHEREVENTFN NIL (QUOTE RESTART))))

(TURN.OFF.ETHER
  (LAMBDA NIL                                                (* bvm: "12-JUL-83 14:03")
    (BREAKCONNECTION T)
    (DEL.PROCESS (QUOTE \PUPGATELISTENER))
    (DEL.PROCESS (QUOTE \NSGATELISTENER))
    (CLOSEPUPSOCKET T)
    (AND (GETD (QUOTE CLOSENSOCKET))
	 (CLOSENSOCKET T))
    (\FLUSHNDBS (QUOTE RESTART))))

(PRINTWORDS
  (LAMBDA (BASE NWORDS)                                      (* bvm: "25-MAY-82 21:26")
    (for I from 0 to (SUB1 NWORDS) do (printout NIL .P2 I ": " .P2 (\GETBASE BASE I)
						T))))
)

(RPAQQ ROUTINGINFOMACRO (1 "Operation = " WORDS 2 "Info: " REPEAT "(" SEPR ", " INTEGER -4 WORDS SEPR 
			   ") "
			   -2 FINALLY ")"))

(RPAQQ ETHERFILES (PUP LLETHER 10MBDRIVER))
(DECLARE: EVAL@COMPILE DONTCOPY 
(CLISPDEC (QUOTE FETCHFIELD))
(* Slow, checking version for debugging)
)



(* Opcodes)

(DEFINEQ

(\DEVICE.INPUT
  (LAMBDA (TASKREG)                                          (* bvm: "12-JUL-82 13:29")
    ((OPCODES MISC1 1)
     (\DTEST TASKREG (QUOTE SMALLP)))))

(\DEVICE.OUTPUT
  (LAMBDA (VALUE TASKREG)                                    (* bvm: "12-JUL-82 13:29")
    ((OPCODES MISC2 2)
     (\DTEST VALUE (QUOTE SMALLP))
     (\DTEST TASKREG (QUOTE SMALLP)))))

(\D0.STARTIO
  (LAMBDA (BITS)                                             (* bvm: "12-JUL-82 13:28")
    ((OPCODES MISC1 0)
     (\DTEST BITS (QUOTE SMALLP)))))
)
(DECLARE: DONTCOPY 

(RPAQQ D0DEVICES ((\DEVICE.3MBETHERIN 7)
		  (\DEVICE.3MBETHEROUT 6)
		  (\DEVICE.10MBETHER 21)
		  (\DEVICE.SA4000 3)
		  (\DEVICE.DISPLAY 2)))
(DECLARE: EVAL@COMPILE 

(RPAQQ \DEVICE.3MBETHERIN 7)

(RPAQQ \DEVICE.3MBETHEROUT 6)

(RPAQQ \DEVICE.10MBETHER 21)

(RPAQQ \DEVICE.SA4000 3)

(RPAQQ \DEVICE.DISPLAY 2)

(CONSTANTS (\DEVICE.3MBETHERIN 7)
	   (\DEVICE.3MBETHEROUT 6)
	   (\DEVICE.10MBETHER 21)
	   (\DEVICE.SA4000 3)
	   (\DEVICE.DISPLAY 2))
)

(* FOLLOWING DEFINITIONS EXPORTED)



(PUTPROPS \DEVICE.INPUT DOPVAL (1 MISC1 1))

(PUTPROPS \DEVICE.OUTPUT DOPVAL (2 MISC2 2))

(PUTPROPS \D0.STARTIO DOPVAL (1 MISC1 0))


(* END EXPORTED DEFINITIONS)

)
(PUTPROPS LLETHER COPYRIGHT ("Xerox Corporation" 1982 1983 1984 1985))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (6499 11618 (\ENQUEUE 6509 . 8638) (\DEQUEUE 8640 . 9748) (\QUEUELENGTH 9750 . 10064) (
\ONQUEUE 10066 . 10340) (\UNQUEUE 10342 . 11616)) (41162 44696 (\ALLOCATE.ETHERPACKET 41172 . 42039) (
\RELEASE.ETHERPACKET 42041 . 43062) (RELEASE.PUP 43064 . 43209) (\FLUSH.PACKET.QUEUE 43211 . 43564) (
\REQUEUE.ETHERPACKET 43566 . 44029) (\EP.PUT.AUX 44031 . 44694)) (45202 49102 (\SETLOCALNSNUMBERS 
45212 . 46142) (\LOADNSADDRESS 46144 . 46421) (\STORENSADDRESS 46423 . 46616) (\PRINTNSADDRESS 46618
 . 47340) (\NSADDRESS.DEFPRINT 47342 . 47785) (\LOADNSHOSTNUMBER 47787 . 48374) (\STORENSHOSTNUMBER 
48376 . 48776) (PRINTNSHOSTNUMBER 48778 . 49100)) (52146 52932 (TRANSLATE.NSH 52156 . 52930)) (53103 
58364 (\ETHERINIT 53113 . 53684) (\ETHEREVENTFN 53686 . 55885) (\SETETHERFLAGS 55887 . 56680) (
\FLUSHNDBS 56682 . 57860) (\FLUSH.NDB.QUEUE 57862 . 58362)) (58365 60732 (\CHECKSUM 58375 . 59478) (
\HANDLE.RAW.OTHER 59480 . 59835) (\HANDLE.RAW.PACKET 59837 . 60243) (\ADD.PACKET.FILTER 60245 . 60485)
 (\DEL.PACKET.FILTER 60487 . 60730)) (66813 69460 (\AGE.ROUTING.TABLE 66823 . 67830) (
\FLUSH.ROUTING.TABLE 67832 . 68084) (PRINTROUTINGTABLE 68086 . 69223) (\MAP.ROUTING.TABLE 69225 . 
69458)) (69461 70025 (ENCAPSULATE.ETHERPACKET 69471 . 69759) (TRANSMIT.ETHERPACKET 69761 . 70023)) (
70363 74686 (\TRANSLATE.10TO3 70373 . 71600) (\NOTE.10TO3 71602 . 72151) (\HANDLE.RAW.10TO3 72153 . 
74684)) (76142 83975 (PRINTPACKET 76152 . 76755) (\MAYBEPRINTPACKET 76757 . 77825) (PRINT10TO3 77827
 . 78971) (PRINTPACKETDATA 78973 . 83036) (PRINTPACKETQUEUE 83038 . 83427) (TIME.SINCE.PACKET 83429 . 
83973)) (84239 88778 (\3MBGETPACKET 84249 . 85282) (\3MB.CREATENDB 85284 . 85922) (\3MBSENDPACKET 
85924 . 87111) (\3MBWATCHER 87113 . 87781) (\3MBENCAPSULATE 87783 . 88337) (\3MB.BROADCASTP 88339 . 
88506) (\3MBFLUSH 88508 . 88776)) (90683 92730 (ASSURE.ETHER.ON 90693 . 91035) (INITPUPLEVEL1 91037 . 
91541) (TURN.ON.ETHER 91543 . 91688) (RESTART.ETHER 91690 . 92109) (TURN.OFF.ETHER 92111 . 92494) (
PRINTWORDS 92496 . 92728)) (93048 93646 (\DEVICE.INPUT 93058 . 93239) (\DEVICE.OUTPUT 93241 . 93466) (
\D0.STARTIO 93468 . 93644)))))
STOP