Copyright (C) 1983, 1984 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.
TCPTest.mesa
Last Edited by: Nichols, September 1, 1983 4:43 pm
Last Edited by: Taft, January 22, 1984 11:28:59 am PST
Last Edited by: HGM, October 6, 1984 10:51:08 pm PDT
Hal Murray May 16, 1985 3:16:56 am PDT
John Larson, April 14, 1986 11:34:42 pm PST
DIRECTORY
Commander USING [CommandProc, Register],
CommandTool USING [ArgumentVector, Failed, Parse],
IO USING [Close, EndOf, EndOfStream, Error, Flush, GetChar, int, PutChar, PutF, PutRope, STREAM],
Rope USING [Cat, Find, FromChar, ROPE],
UserCredentials USING [Get],
IPDefs USING [Address],
IPName USING [NameToAddress],
TCP USING [AbortTCPStream, CreateTCPStream, Error, ErrorFromStream, neverTimeout, Reason, Timeout, WaitForListenerOpen];
TCPTest: CEDAR PROGRAM
IMPORTS Commander, CommandTool, IO, Rope, UserCredentials, IPName, TCP =
BEGIN
fingerSocket: INT = 79;
remoteAddress: IPDefs.Address;
remoteSocket: INT ← fingerSocket;
running: BOOLTRUE;
server: PROCESS;
SetAddress: Commander.CommandProc = {
out: IO.STREAM ← cmd.out;
argv: CommandTool.ArgumentVector = CommandTool.Parse[cmd !
CommandTool.Failed => {out.PutRope[errorMsg]; GO TO GiveUp}];
remoteAddresses: LIST OF IPDefs.Address ← IPName.NameToAddress[argv[1]];
IF remoteAddresses=NIL THEN {out.PutRope["Name not found"]; GOTO GiveUp};
remoteAddress ← remoteAddresses.first;
out.PutF["[%g.%g.%g.%g]\n", IO.int[remoteAddress[0]], IO.int[remoteAddress[1]], IO.int[remoteAddress[2]], IO.int[remoteAddress[3]]];
EXITS
GiveUp => NULL;
};
Finger: Commander.CommandProc = {
out: IO.STREAMcmd.out;
fingerStream: IO.STREAM;
c: CHAR;
cr: TCP.Reason ← neverOpen;
{
ENABLE {
TCP.Timeout => {
out.PutRope["[No response.]\n"];
GO TO GiveUp;
};
TCP.Error => {
cr ← reason;
GO TO GiveUp;
};
IO.Error => {
cr ← TCP.ErrorFromStream[fingerStream];
GOTO GiveUp;
};
};
fingerStream ← TCP.CreateTCPStream[[matchLocalPort~FALSE, localPort~0, matchForeignAddr~TRUE, foreignAddress~remoteAddress, matchForeignPort~TRUE, foreignPort~remoteSocket, active~TRUE, timeout~120000]];
TCP.WaitForListenerOpen[fingerStream, TCP.neverTimeout];
fingerStream.PutRope[cmd.commandLine];
fingerStream.PutChar['\l]; -- send the LF as well
fingerStream.Flush[];
WHILE NOT fingerStream.EndOf[] DO
c ← fingerStream.GetChar[ ! IO.EndOfStream => EXIT];
IF c # '\l THEN out.PutChar[c];
ENDLOOP;
fingerStream.Close[];
EXITS
GiveUp =>
SELECT cr FROM
remoteAbort => out.PutRope["[Remote host refused to point the finger at its users.]\n"];
ENDCASE => TCP.AbortTCPStream[fingerStream];
};
};
FingerServer: PROC = {
ENABLE TCP.Timeout => RESUME;
fingerStream: IO.STREAM;
WHILE running DO
ENABLE BEGIN
IO.Error => RETRY;
TCP.Timeout => RETRY;
TCP.Error => RETRY;
END;
char: CHAR;
rope: Rope.ROPENIL;
fingerStream ← TCP.CreateTCPStream[[matchLocalPort: TRUE, localPort: fingerSocket, matchForeignAddr: FALSE, matchForeignPort: FALSE, active: FALSE]];
DO
char ← fingerStream.GetChar[];
IF char = '\l THEN EXIT;
rope ← Rope.Cat[rope, Rope.FromChar[char]];
ENDLOOP;
fingerStream.PutF["User %g logged in on a Dorado.\n\l", [rope[UserCredentials.Get[].name]]];
IF Rope.Find[rope, "Verbose"] # -1 THEN
Hack for resting reassembly via echoing to GOONHILLY-ECHO. Send big packets.
THROUGH [0..20) DO
fingerStream.PutF[" 123456789 123456789 123456789 123456789 123456789\n\l"];
ENDLOOP;
IF Rope.Find[rope, "Super"] # -1 THEN
THROUGH [0..200) DO
fingerStream.PutF[" 123456789 123456789 123456789 123456789 123456789\n\l"];
ENDLOOP;
fingerStream.Flush[];
fingerStream.Close[];
ENDLOOP;
};
Commander.Register["SetTCPAddress", SetAddress, "Tell which remote host to use."];
Commander.Register["Finger", Finger, "Who is on host."];
server ← FORK FingerServer[];
END.