Guided TcpRuleRecvUntil Example

This example shows how to improve recorded scripts for telnet sessions.

Recording a telnet session without recording rules results in scripts that have lots of WebTcpipRecvExact() function calls, as shown below.

Portion of a recorded Telnet script without recording rules

WebTcpipSend(hWeb0, "l");
WebTcpipRecvExact(hWeb0, NULL, 1);
WebTcpipSend(hWeb0, "s\r\n");
WebTcpipRecvExact(hWeb0, NULL, 1);
WebTcpipRecvExact(hWeb0, NULL, 2);
WebTcpipRecvExact(hWeb0, NULL, 1220);

TrueLog Explorer is used to analyze server responses. Each server response ends with a command prompt. The command prompt ends with the three-character sequence blank, hash, blank, which seems a reasonable choice for the terminating data of a server response.

A recording rule can be written for this kind of server response. The rule instructs the Recorder to watch for server responses that end with the special terminating sequence, and to script the function WebTcpipRecvUntil() instead of WebTcpipRecvExact() for those server responses.

TCP/IP recording rule for Telnet

<?xml version="1.0" encoding="UTF-8" ?>
<RecordingRuleSet>
  <TcpRuleRecvUntil>
    <Name>Telnet Command Prompt</Name>
    <Active>true</Active>
    <Identify>
      <TermData> # </TermData>
      <IgnoreWhiteSpaces>false</IgnoreWhiteSpaces>
    </Identify>
    <Conditions>
      <NoBlockSplit>true</NoBlockSplit>
    </Conditions>
  </TcpRuleRecvUntil>
</RecordingRuleSet>

The terminating data is specified in the attribute Identify\TermData. Since the terminating data contains significant white spaces, not to ignore white spaces must be specified in the attribute Identify\IgnoreWhiteSpaces.

The rule should not be applied if a server response coincidentally contains the same terminating sequence elsewhere in the response. Therefore the condition NoBlockSplit should be specified. This means that the end of the terminating data must be aligned with the end of a TCP/IP packet received from the telnet server; otherwise the rule won't be applied.

Portion of a recorded Telnet script using a recording rule

WebTcpipSend(hWeb0, "l");
WebTcpipRecvExact(hWeb0, NULL, 1);
WebTcpipSend(hWeb0, "s");
WebTcpipRecvExact(hWeb0, NULL, 1);
WebTcpipSend(hWeb0, "\r\n");
WebTcpipRecvUntil(hWeb0, NULL, 0, NULL, " # ");

This example shows that the rule works. This script is better equipped to handle varying server responses during replay.

Note that the terminating sequence may be different for other Telnet servers and may depend on operating system and user settings. Therefore the rule shown here is not a general rule that works for all Telnet servers. It can however easily be adapted by changing the terminating character sequence. With the help of TrueLog Explorer, it's easy to determine suitable terminating byte sequences for other Telnet servers.