Copyright (C) 1983, 1985 by Xerox Corporation. All rights reserved. The following program was created in 1983 but has not been published within the meaning of the copyright law, is furnished under license, and may not be used, copied and/or disclosed except in accordance with the terms of said license.
IP.mesa
Hal Murray May 16, 1985 2:35:05 am PDT
Last Edited by: Nichols, August 10, 1983 9:14 pm
Last Edited by: Taft, January 5, 1984 5:05 pm
DIRECTORY
IO USING [STREAM];
IP: CEDAR DEFINITIONS
~ BEGIN
Packet format
maxOptionLength: INT ~ 40; -- Maximum length of internet options.
maxDataLength: INT ~ 556; -- In bytes, excluding headers.
maxIHL: INT ~ 15; -- Maximum internet header length.
minIHL: INT ~ 5;
neverTimeout: INT ~ -1; -- timeout value to prevent timing out.
Byte: TYPE ~ INT [0..255]; -- One byte field.
DByte: TYPE ~ INT [0..65535]; -- Two byte field.
Address: TYPE = PACKED ARRAY INT [0..4) OF Byte; -- Internet address format.
AddressList: TYPE = LIST OF Address;
nullAddress: Address ~ ALL[0];
OptionsArray: TYPE ~ PACKED ARRAY INT [1..maxOptionLength] OF Byte;
InternetHeader: TYPE ~ MACHINE DEPENDENT RECORD [ -- Format of internet header.
version (0: 0..3): INT [0..15] ← 4,
IHL (0: 4..7): INT [0..15],
precedence (0: 8..10): INT [0..7] ← 0,
delay (0: 11..11): INT [0..1] ← 0,
throughput (0: 12..12): INT [0..1] ← 0,
reliability (0: 13..13): INT [0..1] ← 0,
filler1 (0: 14..15): INT [0..3] ← 0,
packetLength (1): DByte,
fragmentId (2): DByte ← 0,
filler2 (3: 0..0): INT [0..1] ← 0,
dontFragment (3: 1..1): BOOLFALSE,
moreFragments (3: 2..2): BOOLFALSE,
fragmentOffset (3: 3..15): INT [0..17777B],
timeToLive (4: 0..7): Byte,
protocol (4: 8..15): Byte,
checksum (5): DByte,
source (6): Address,
destination (8): Address,
options (10): OptionsArray];
Protocol field values.
ICMPProtocol: Byte = 1;
TCPProtocol: Byte = 6;
UDPProtocol: Byte = 17;
DataBuffer: TYPE = PACKED ARRAY INT [0..maxDataLength) OF Byte; -- Internet data buffer.
Datagram: TYPE = REF DatagramRec;
DatagramRec: TYPE = RECORD [ -- Format of internet datagram
dataLength: INT, -- data length in bytes
optionLength: INT [0..maxOptionLength) ← 0, -- number of bytes of options.
inHdr: InternetHeader, -- internet header
data: DataBuffer]; -- data buffer
DatagramQueue: TYPE ~ LIST OF Datagram; -- ???
type of argument to CreateIPHandle
RequestData: TYPE ~ RECORD [ -- Specify internet packets to receive/send
matchProtocol: BOOL, -- true if match internet protocol on packets
protocol: Byte, -- protocol value to match
matchAddr: BOOL, -- true if match internet address on packets
address: Address, -- internet address to match
matchLocalAddr: BOOL, -- true if specifying particular local address
localAddress: Address, -- local address to match, if matchLocalAddr is false, address in configuration file is used
printPkts: BOOLFALSE, -- true if print packets for this request
logPkts: BOOLFALSE]; -- true if log packets for this request
InternetHandle: TYPE ~ REF InternetHandleRec; -- "handle" on request, returned by IPRequest for internet process use only.
InternetHandleRec: TYPE ~ RECORD [ -- Specify internet packets to receive/send
matchProtocol: BOOL, -- true if match internet protocol on packets
protocol: Byte, -- protocol value to match
matchAddr: BOOL, -- true if match internet address on packets
address: Address, -- internet address to match
matchLocalAddr: BOOL, -- true if specifying a particular local address
localAddress: Address, -- local address to match
printPkts: BOOL, -- true if print packets for this request
logPkts: BOOL, -- true if log packets for this request
waitingDatagrams: DatagramQueue ← NIL, -- unread datagrams
lastWaitingElement: DatagramQueue ← NIL, -- points to last CONS cell to make appending fast
newDatagram: CONDITION, -- how to wait on new ones
handleDestroyed: BOOLFALSE]; -- set to tell waiters to give up
CreateIPHandle: PROC [requestData: RequestData] RETURNS [handle: InternetHandle];
Add a new request for incoming packets. Returns a handle on the Internet. If the reqest conflicts with an existing one, then CreateIPHandle returns NIL.
DestroyIPHandle: PROC [handle: InternetHandle];
Removes the request and flushes all waiting datagrams.
Send: PROC [handle: InternetHandle, data: Datagram];
Fills in header of datagram from the handle and sends it.
SendSpecific: PROC [data: Datagram];
Sends a datagram whose header has already been filled in.
Receive: PROC [handle: InternetHandle, timeout: INT ← neverTimeout] RETURNS [data: Datagram];
Waits for a datagram that matches the request that was used to create the handle. Returns the datagram or NIL if timeout milliseconds (?) pass with no packet arriving. A value of neverTimeout for timeout will cause Receive to wait forever.
PrintDatagram: PROC [s: IO.STREAM, data: IP.Datagram];
Print a representation of the datagram on the stream.
Errorcode: TYPE ~ {handleDestroyed, unknown};
Error: ERROR [type: Errorcode];
END.