telnet
Posted by vincekool
Last Updated: April 13, 2012
  1403

Telnet is best understood in the context of a user with a simple terminal using the local Telnet program (known as the client program) to run a logon session on a remote computer where the user's communications needs are handled by a Telnet server program.

It should be emphasized that the Telnet server can pass on the data it has received from the client to many other types of processes including a remote logon server. This is described in RFC854 and was first published in 1983.

The Network Virtual Terminal

Communication is established using TCP/IP and is based on a Network Virtual Terminal (NVT). On the client, the Telnet program is responsible for translating incoming NVT codes to codes understood by the client's display device as well as for translating client-generated keyboard codes into outgoing NVT codes.

The NVT uses 7-bit codes for characters. The display device, referred to as a printer in the RFC, is only required to display the standard printing ASCII characters represented by 7-bit codes and to recognize and process certain control codes. The 7-bit characters are transmitted as 8-bit bytes with the most significant bit set to zero. An end-of-line is transmitted as a carriage return (CR) followed by a line feed (LF). If you want to transmit an actual carriage return, this is transmitted as a carriage return followed by a NUL (all bits zero) character.

NVT ASCII is used by many other Internet protocols like SMTP and FTP.

The following control codes are required to be understood by the NVT.

Name Code Decimal Value Function
NULL NUL 0 No operation
Line Feed LF 10 Moves the printer to the next print line, keeping the same horizontal position.
Carriage Return CR 13 Moves the printer to the left margin of the current line.


The following further control codes are optional but should have the indicated defined effect on the display.

Name Code Decimal Value Function
BELL BEL 7 Produces an audible or visible signal (which does NOT move the print head.
Back Space BS 8 Moves the print head one character position towards the left margin. (On a printing device, this mechanism was commonly used to form composite characters by printing two basic characters on top of each other.)
Horizontal Tab HT 9 Moves the printer to the next horizontal tab stop. It remains unspecified how either party determines or establishes where such tab stops are located.
Vertical Tab VT 11 Moves the printer to the next vertical tab stop. It remains unspecified how either party determines or establishes where such tab stops are located.
Form Feed FF 12 Moves the printer to the top of the next page, keeping the same horizontal position. (On visual displays, this commonly clears the screen and moves the cursor to the top left corner.)
The NVT keyboard is specified as being capable of generating all 128 ASCII codes by using keys, key combinations, or key sequences.

Commands

The Telnet protocol uses various commands to control the client-server connection. These commands are transmitted within the data stream. The commands are distinguished from the data by setting the most significant bit to 1. (Remember that data is transmitted as 7-bits with the eighth bit set to 0) Commands are always introduced by the Interpret as command (IAC) character.

Here is the complete set of commands:

Name Decimal Code Meaning Comment
SE 240 End of subnegotiation parameters
NOP 241 No operation
DM 242 Data mark Indicates the position of a Synch event within the data stream. This should always be accompanied by a TCP urgent notification.
BRK 243 Break Indicates that the "break" or "attention" key was hi.
IP 244 Suspend Interrupt or abort the process to which the NVT is connected.
AO 245 Abort output Allows the current process to run to completion but does not send its output to the user.
AYT 246 Are you there Send back to the NVT some visible evidence that the AYT was received.
EC 247 Erase character The receiver should delete the last preceding undeleted character from the data stream.
EL 248 Erase line Delete characters from the data stream back to but not including the previous CRLF.
GA 249 Go ahead Under certain circumstances used to tell the other end that it can transmit.
SB 250 Subnegotiation Subnegotiation of the indicated option follows.
WILL 251 will Indicates the desire to begin performing, or confirmation that you are now performing, the indicated option.
WONT 252 wont Indicates the refusal to perform, or continue performing, the indicated option.
DO 253 do Indicates the request that the other party perform, or confirmation that you are expecting the other party to perform, the indicated option.
DONT 254 dont Indicates the demand that the other party stop performing, or confirmation that you are no longer expecting the other party to perform, the indicated option.
IAC 255 Interpret as command Interpret as a command

Telnet Options

Options give the client and server a common view of the connection. They can be negotiated at any time during the connection by the use of commands. They are described in separate RFCs.

The following are examples of common options:

Decimal code Name RFC
3 suppress go ahead 858
5 status 859
1 echo 857
6 timing mark 860
24 terminal type 1091
31 window size 1073
32 terminal speed 1079
33 remote flow control 1372
34 linemode 1184
36 environment variables 1408

Either end of a Telnet conversation can locally or remotely enable or disable an option. The initiator sends a 3-byte command of the form:
IAC Type of Operation Option

The response is of the same form. Operation is one of:

Description Decimal Code Action
WILL 251 Sender wants to do something.
WONT 252 Sender doesn't want to do something.
DO 253 Sender wants the other end to do something.
DONT 254 Sender wants the other not to do something.


Associated with each of the these commands are various possible responses:

Sender Sent Receiver Responds Implication
WILL DO The sender would like to use a certain facility if the receiver can handle it. Option is now in effect.
WILL DONT Receiver says it cannot support the option. Option is not in effect.
DO WILL The sender says it can handle traffic from the sender if the sender wishes to use a certain option. Option is now in effect.
DO WONT Receiver says it cannot support the option. Option is not in effect.
WONT DONT Option disabled. DONT is only valid response.
DONT WONT Option disabled. WONT is only valid response.


For example, if the sender wants the other end to suppress go-ahead, it would send the byte sequence:

IAC WILL Suppress Go Ahead

The final byte of the 3-byte sequence identifies the required action.

Some option's values need to be communicated after support of the option has been agreed. This is done using sub-option negotiation. Values are negotiated using value query commands and responses in the following form:

IAC SB option code 1 IAC SE
and
IAC SB option code 0 IAC SE


For example, if the client wants to identify the terminal type to the server, the following exchange might take place:

CLIENT IAC WILL Terminal Type
SERVER IAC DO Terminal Type
CLIENT IAC SB Terminal Type 1 IAC SE
SERVER IAC SB Terminal Type 0 V T 2 2 0 IAC SE

The first exchange establishes that terminal type (option number 24) is handled, the server then enquires of the client what value it wishes to associate with the terminal type.

The sequence SB,24,1 implies sub-option negotiation for option type 24, value required (1). The IAC,SE sequence indicates the end of this request.

The response IAC,SB,24,0,'V'... implies sub-option negotiation for option type 24, value supplied (0), the IAC,SE sequence indicates the end of the response (and the supplied value).

The encoding of the value is specific to the option but a sequence of characters, as shown above, is common.

ref.......................http://support.microsoft.com/kb/231866
   
  
 
 
   

 
 
Cool!