ArpaICMP.mesa
Demers, August 27, 1987 6:21:26 pm PDT
DIRECTORY
Arpa USING [Address],
ArpaICMPBuf USING [Buffer]
;
ArpaICMP: CEDAR DEFINITIONS
~ {
Introduction
This interface can be used to send arbitrary ICMP datagrams (with IP options) and to receive replies of types echoReply, timestampReply, infoReply.
ArpaICMPImpl is a server for echo, timestamp, inforequest and redirect requests.
ICMP destUnreachable, sourceQuench, timeExceeded and parameterProblem messages are passed to the protocol module that generated the original datagram.
Types
Address: TYPE ~ Arpa.Address;
Buffer: TYPE ~ ArpaICMPBuf.Buffer;
Handle: TYPE ~ REF Object;
Object: TYPE;
Handle Create / Destroy
nullID: CARD16 ~ CARD16.LAST;
CreateHandle: PROC [id: CARD16 ← nullID] RETURNS [h: Handle];
Create a handle that can be used to send / receive ICMP messages with a given ID to / from a given address.
Kick: PROC [h: Handle];
Wake up processes waiting in Receive[h].
DestroyHandle: PROC [h: Handle];
Destroy a handle.
Don't drop it on the floor.
Sending
AllocBuffer: PROC [h: Handle] RETURNS [b: Buffer];
Allocate a buffer associated with this handle.
The Handle may be NIL, in which case we use a default handle that allows sending but not receiving.
SetBodyBytes: PROC [b: Buffer, bodyBytes: CARDINAL, optionsBytes: CARDINAL ← 0];
Set number of bytes in body and options of ICMP message in buffer.
Example: for a TimeStamp message, call SetBodyBytes[b, BYTES[ArpaICMPBuf.Body.timestamp]].
Send: PROC [h: Handle, b: Buffer, address: Address];
Send an ICMP message to the specified address.
The Handle may be NIL, as in AllocBuffer.
The (ICMP and IP) Hdr of b will be "fixed" for sending, but the data will not be changed.
Call FreeBuffer after Send if you don't want to keep the buffer around (e.g. for retransmission).
Receiving
waitForever: CARD ~ CARD.LAST;
dontWait: CARD ~ 0;
Receive: PROC [h: Handle, timeoutMsec: CARD ← waitForever] RETURNS [b: Buffer];
Receive and ICMP message. The ICMP type is echoReply, timestampReply or infoReply; ID is the one specified when the handle was created.
GetBodyBytes: PROC [b: Buffer] RETURNS [bodyBytes: CARDINAL, optionsBytes: CARDINAL];
Return number of bytes in body of ICMP message in buffer.
Example: if b contains a well-formed TimestampReply message, then GetBodyBytes[b] = BYTES[ArpaICMPBuf.Body.timestampReply].
GetSource: PROC [b: Buffer] RETURNS [Address];
Return source address of datagram in buffer.
FreeBuffer: PROC [h: Handle, b: Buffer];
Release a buffer obtained by Receive or AllocBuffer.
The Handle may be NIL, as in AllocBuffer / Send.
Errors
Error: ERROR [code: ATOM];
Error Codes:
$HandleDestroyed : can't send or receive after destroy
others as necessary ...
}...