(DEFINE-FILE-INFO READTABLE "INTERLISP" PACKAGE "INTERLISP")
(FILECREATED "15-Oct-87 18:56:42" {SAFE}</B/JFINGER/RPC/X>RPCLOWLEVEL.LSP;10 4831   

      changes to%:  (VARS RPCLOWLEVELCOMS)

      previous date%: "15-Oct-87 09:49:11" 
{SAFE}</B/JFINGER/RPC/X>RPCLOWLEVEL.LSP;8)


(PRETTYCOMPRINT RPCLOWLEVELCOMS)

(RPAQQ RPCLOWLEVELCOMS 
       ((* "Copyright (c) 1987 by the Leland Stanford Junior University. All rights reserved."
           )
        (* "Written by Jeff Finger at the SUMEX-AIM Computing Resource at Stanford University" 
     "under support from National Institutes of Health Grant NIH 5P41 RR00785."
           )
        (* "Compiling this file requires several definitions from EXPORTS.ALL."
           )
        (CONSTANTS (BYTESPERCELL 4))
        (FNS TCP.STREAM.SOCKET TCP.SOCKET.EVENT STRING.ZEROBYTES STRING.BOUTS 
             STRING.BINS \IP.APPEND.BYTES UDP.APPEND.BYTES UDP.GET.BYTES 
             UDP.MYGET.STRING \UDP.SET.CHECKSUM.ZERO)
        (P (CHANGENAME 'UDP.SEND '\UDP.SET.CHECKSUM '\UDP.SET.CHECKSUM.ZERO))))



(* 
"Copyright (c) 1987 by the Leland Stanford Junior University. All rights reserved."
)




(* 
"Written by Jeff Finger at the SUMEX-AIM Computing Resource at Stanford University"
 "under support from National Institutes of Health Grant NIH 5P41 RR00785.")




(* "Compiling this file requires several definitions from EXPORTS.ALL.")

(DECLARE%: EVAL@COMPILE 

(RPAQQ BYTESPERCELL 4)

(CONSTANTS (BYTESPERCELL 4))
)
(DEFINEQ

(TCP.STREAM.SOCKET
  (LAMBDA (STREAM)                       (* ; "Edited  8-Oct-87 16:08 by jjf")
        
        (* * "Return IPSOCKET of a TCP Stream")

    (fetch TCB.IPSOCKET of (fetch F1 of STREAM))))

(TCP.SOCKET.EVENT
  (LAMBDA (IPSOCKET)                     (* ; "Edited  8-Oct-87 16:14 by jjf")
        
        (* * "For some reason Eric did not include this function, but it is identical to UDP.SOCKET.NUMBER, anyway.")

    (fetch (IPSOCKET IPSEVENT) of IPSOCKET)))

(STRING.ZEROBYTES
  (LAMBDA (STRING FIRST NBYTES)          (* ; "Edited 11-Oct-87 09:49 by jjf")
        
        (* * "Zero bytes of a string")

    (\ZEROBYTES (fetch (STRINGP BASE) of STRING)
           FIRST
           (SUB1 (IPLUS FIRST NBYTES)))))

(STRING.BOUTS
  (LAMBDA (STREAM STRING FIRST NBYTES)   (* ; "Edited 11-Oct-87 10:22 by jjf")
        
        (* * "Write substring to stream")

    (\BOUTS STREAM (fetch (STRINGP BASE) of STRING)
           FIRST NBYTES)))

(STRING.BINS
  (LAMBDA (STREAM STRING FIRST NBYTES)   (* ; "Edited 11-Oct-87 13:58 by jjf")
        
        (* * "Read substring from stream")

    (\BINS STREAM (fetch (STRINGP BASE) of STRING)
           FIRST NBYTES)))

(\IP.APPEND.BYTES
  (LAMBDA (IP ADDR OFFSET LENGTH)        (* ; "Edited 30-Jul-87 17:13 by jjf")
        
        (* * "Append bytes (not necessarily a string) to IPPACKET. ")

    (\MOVEBYTES ADDR OFFSET (fetch (IP IPBASE) of IP)
           (fetch (IP IPTOTALLENGTH) of IP)
           LENGTH)
    (add (ffetch (IP IPTOTALLENGTH) of IP)
         LENGTH)))

(UDP.APPEND.BYTES
  (LAMBDA (UDP ADDR OFFSET NBYTES)       (* ; "Edited 30-Jul-87 17:14 by jjf")
        
        (* * "Append bytes (not necessarily a string) to UDP Packet")

    (\IP.APPEND.BYTES UDP ADDR OFFSET NBYTES)
    (add (fetch (UDP UDPLENGTH) of UDP)
         NBYTES)))

(UDP.GET.BYTES
  (LAMBDA (UDP SOFFSET DEST DOFFSET NBYTES)
                                         (* ; "Edited 30-Jul-87 17:14 by jjf")
        
        (* * 
       "Move bytes out of UDP Packet to another buffer without string creation")

    (\MOVEBYTES (fetch (UDP UDPCONTENTS) of UDP)
           SOFFSET DEST DOFFSET NBYTES)
    DEST))

(UDP.MYGET.STRING
  (LAMBDA (UDP OFFSET LENGTH)            (* ; "Edited 30-Jul-87 17:17 by jjf")
        
        (* * "Fetch string from packet. String does not go to end of packet as in UDP.GET.STRING.")

    (OR (SMALLP OFFSET)
        (SETQ OFFSET 0))
    (LET* ((STRING (ALLOCSTRING LENGTH)))
          (\MOVEBYTES (fetch (UDP UDPCONTENTS) of UDP)
                 OFFSET
                 (fetch (STRINGP BASE) of STRING)
                 (fetch (STRINGP OFFST) of STRING)
                 LENGTH)
          STRING)))

(\UDP.SET.CHECKSUM.ZERO
  (LAMBDA (UDP)                          (* ; "Edited 30-Jul-87 17:18 by jjf")
        
        (* * "Avoid doing a UDP checksum. Packet already gets IP Checksum.")

    (replace (UDP UDPCHECKSUM) of UDP with 0)))
)
(CHANGENAME 'UDP.SEND '\UDP.SET.CHECKSUM '\UDP.SET.CHECKSUM.ZERO)
(DECLARE%: DONTCOPY
  (FILEMAP (NIL (1501 4742 (TCP.STREAM.SOCKET 1511 . 1749) (TCP.SOCKET.EVENT 1751
 . 2045) (STRING.ZEROBYTES 2047 . 2324) (STRING.BOUTS 2326 . 2573) (STRING.BINS 
2575 . 2821) (\IP.APPEND.BYTES 2823 . 3222) (UDP.APPEND.BYTES 3224 . 3537) (
UDP.GET.BYTES 3539 . 3909) (UDP.MYGET.STRING 3911 . 4473) (
\UDP.SET.CHECKSUM.ZERO 4475 . 4740)))))
STOP