The TCP/IP Guide - Version 3.0 (Contents) ` 1618 _ © 2001-2005 Charles M. Kozierok. All Rights Reserved.
that represent these commands are translated to the standard Telnet codes for trans-
mission, and then translated to the specific needs of the host computer. So to take our
example again, if a user presses “<Ctrl>+C” on a UNIX terminal where this is defined as the
interrupt function, then instead of sending that exact keystroke, the Telnet client sends the
special Telnet Interrupt Process command, which is translated by the Telnet server to the
command code appropriate for the connected host.
The Telnet standard includes a number of these special codes to allow a user to control the
operation of the remote computer. It also defines a set of commands that are specific to the
Telnet protocol itself; these let the Telnet client and Telnet server software communicate.
Collectively, these are called Telnet protocol commands.
Escaping Commands and the Interpret As Command (IAC) Character
All Telnet commands are sent in the same communication stream as regular data; they are
represented using special byte values in the range from 240 to 254. To differentiate
between data bytes of these values and Telnet commands, every command is preceded by
a special escape character, given the name Interpret As Command (IAC). IAC has a value
of 255; when the recipient sees this character, it knows the next byte is a command and not
data. So, since the Telnet Interrupt Process command has the value 244, to send this
command the Telnet client would transmit the byte 255 and then 244. If the actual data byte
value 255 needs to be sent, it is transmitted as two 255 bytes. Some Telnet commands also
include additional bytes data, which are sent after the command code itself; a good
example is the use of parameters in Telnet option negotiation.
You may be wondering at this point why the IAC character is needed at all. After all, Telnet
uses US ASCII, which is 7-bit data in the byte range of 0 to 127, and the Telnet commands
have values higher than 127. One general rationale for using the IAC escape is to be
explicit that a command is being sent. A more specific reason is to accommodate the
optional sending of 8-bit binary data over Telnet, which the client and server can negotiate.
If this mode were enabled and commands were not preceded by the IAC character, this
would require all data bytes with values from 240 to 255 to be somehow marked so they
would be interpreted as data and not commands. It is more efficient to include an extra byte
for commands than data, since they are sent less frequently. By escaping commands, only
data byte value 255 requires two bytes to be sent.
Key Concept: The Telnet protocol defines a set of protocol commands that are used
for two purposes: first, to represent standard control functions that need to be sent
between a terminal and host, such as the command to interrupt a process; and
second, to enable protocol communication between the Telnet client and server software.
Protocol commands are sent in the normal data communication stream over the Telnet
session’s TCP connection. Each is represented by a byte value from 240 to 254, and is
preceded by the Interpret As Command (IAC) command, byte value 255, which tells the
recipient that the next byte in the stream is a command.