PcapPlusPlus  23.09
pcpp::TelnetLayer Class Reference

#include <TelnetLayer.h>

Inheritance diagram for pcpp::TelnetLayer:
pcpp::Layer pcpp::IDataContainer

Public Types

enum  TelnetCommand : int {
  TelnetCommand::TelnetCommandEndOfPacket = -1, TelnetCommand::EndOfFile = 236, TelnetCommand::Suspend, TelnetCommand::Abort,
  TelnetCommand::EndOfRecordCommand, TelnetCommand::SubnegotiationEnd, TelnetCommand::NoOperation, TelnetCommand::DataMark,
  TelnetCommand::Break, TelnetCommand::InterruptProcess, TelnetCommand::AbortOutput, TelnetCommand::AreYouThere,
  TelnetCommand::EraseCharacter, TelnetCommand::EraseLine, TelnetCommand::GoAhead, TelnetCommand::Subnegotiation,
  TelnetCommand::WillPerform, TelnetCommand::WontPerform, TelnetCommand::DoPerform, TelnetCommand::DontPerform,
  TelnetCommand::InterpretAsCommand
}
 
enum  TelnetOption : int {
  TelnetOption::TelnetOptionNoOption = -1, TelnetOption::TransmitBinary = 0, TelnetOption::Echo, TelnetOption::Reconnection,
  TelnetOption::SuppressGoAhead, TelnetOption::ApproxMsgSizeNegotiation, TelnetOption::Status, TelnetOption::TimingMark,
  TelnetOption::RemoteControlledTransAndEcho, TelnetOption::OutputLineWidth, TelnetOption::OutputPageSize, TelnetOption::OutputCarriageReturnDisposition,
  TelnetOption::OutputHorizontalTabStops, TelnetOption::OutputHorizontalTabDisposition, TelnetOption::OutputFormfeedDisposition, TelnetOption::OutputVerticalTabStops,
  TelnetOption::OutputVerticalTabDisposition, TelnetOption::OutputLinefeedDisposition, TelnetOption::ExtendedASCII, TelnetOption::Logout,
  TelnetOption::ByteMacro, TelnetOption::DataEntryTerminal, TelnetOption::SUPDUP, TelnetOption::SUPDUPOutput,
  TelnetOption::SendLocation, TelnetOption::TerminalType, TelnetOption::EndOfRecordOption, TelnetOption::TACACSUserIdentification,
  TelnetOption::OutputMarking, TelnetOption::TerminalLocationNumber, TelnetOption::Telnet3270Regime, TelnetOption::X3Pad,
  TelnetOption::NegotiateAboutWindowSize, TelnetOption::TerminalSpeed, TelnetOption::RemoteFlowControl, TelnetOption::Linemode,
  TelnetOption::XDisplayLocation, TelnetOption::EnvironmentOption, TelnetOption::AuthenticationOption, TelnetOption::EncryptionOption,
  TelnetOption::NewEnvironmentOption, TelnetOption::TN3270E, TelnetOption::XAuth, TelnetOption::Charset,
  TelnetOption::TelnetRemoteSerialPort, TelnetOption::ComPortControlOption, TelnetOption::TelnetSuppressLocalEcho, TelnetOption::TelnetStartTLS,
  TelnetOption::Kermit, TelnetOption::SendURL, TelnetOption::ForwardX, TelnetOption::TelOptPragmaLogon = 138,
  TelnetOption::TelOptSSPILogon, TelnetOption::TelOptPragmaHeartbeat, TelnetOption::ExtendedOptions = 255
}
 

Public Member Functions

 TelnetLayer (uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
 
std::string getDataAsString (bool removeEscapeCharacters=true)
 
size_t getTotalNumberOfCommands ()
 
size_t getNumberOfCommands (TelnetCommand command)
 
TelnetCommand getFirstCommand ()
 
TelnetCommand getNextCommand ()
 
TelnetOption getOption ()
 
TelnetOption getOption (TelnetCommand command)
 
uint8_t * getOptionData (size_t &length)
 
uint8_t * getOptionData (TelnetCommand command, size_t &length)
 
void parseNextLayer ()
 Parses the next layer. Telnet is the always last so does nothing for this layer.
 
size_t getHeaderLen () const
 
void computeCalculateFields ()
 Does nothing for this layer.
 
OsiModelLayer getOsiModelLayer () const
 
std::string toString () const
 
- Public Member Functions inherited from pcpp::Layer
virtual ~Layer ()
 
LayergetNextLayer () const
 
LayergetPrevLayer () const
 
ProtocolType getProtocol () const
 
uint8_t * getData () const
 
size_t getDataLen () const
 
uint8_t * getLayerPayload () const
 
size_t getLayerPayloadSize () const
 
bool isAllocatedToPacket () const
 
void copyData (uint8_t *toArr) const
 
uint8_t * getDataPtr (size_t offset=0) const
 

Static Public Member Functions

static std::string getTelnetCommandAsString (TelnetCommand val)
 
static std::string getTelnetOptionAsString (TelnetOption val)
 
static bool isTelnetPort (uint16_t port)
 
static bool isDataValid (const uint8_t *data, size_t dataSize)
 

Detailed Description

Class for representing the Telnet Layer

Member Enumeration Documentation

◆ TelnetCommand

Telnet Command Indicator

Enumerator
TelnetCommandEndOfPacket 

Indicator to parser reached end of packet.

EndOfFile 

End of file.

Suspend 

Suspend current process.

Abort 

Abort Process.

EndOfRecordCommand 

End of Record.

SubnegotiationEnd 

Marks the end of a Telnet option subnegotiation, used with the SB code to specify more specific option parameters.

NoOperation 

Null command; does nothing.

DataMark 

Used to mark the end of a sequence of data that the recipient should scan for urgent Telnet commands.

Break 

Represents the pressing of the “break” or “attention” key on the terminal.

InterruptProcess 

Tells the recipient to interrupt, abort, suspend or terminate the process currently in use.

AbortOutput 

Instructs the remote host to continue running the current process, but discard all remaining output from it. This may be needed if a program starts to send unexpectedly large amounts of data to the user.

AreYouThere 

May be used to check that the remote host is still “alive”. When this character is sent the remote host returns some type of output to indicate that it is still functioning.

EraseCharacter 

Instructs the recipient to delete the last undeleted character from the data stream. Used to “undo” the sending of a character.

EraseLine 

Tells the recipient to delete all characters from the data stream back to (but not including) the last end of line (CR+LF) sequence.

GoAhead 

Used in Telnet half-duplex mode to signal the other device that it may transmit.

Subnegotiation 

Marks the beginning of a Telnet option subnegotiation, used when an option requires the client and server to exchange parameters.

WillPerform 

Indicates that the device sending this code is willing to perform or continue performing a particular option.

WontPerform 

Indicates that the device sending this code is either not willing to perform a particular option, or is now refusing to continue to perform it.

DoPerform 

Requests that the other device perform a particular option or confirms the expectation that the other device will perform that option.

DontPerform 

Specifies that the other party not perform an option, or confirms a device’s expectation that the other party not perform an option.

InterpretAsCommand 

Precedes command values 240 through 254 as described above. A pair of IAC bytes in a row represents the data value 255.

◆ TelnetOption

Telnet Options

Enumerator
TelnetOptionNoOption 

Internal return for no option detected.

TransmitBinary 

Binary Transmission RFC856 https://www.iana.org/go/rfc856.

Echo 

Echo RFC857 https://www.iana.org/go/rfc857.

Reconnection 

Reconnection.

SuppressGoAhead 

Suppress Go Ahead RFC858 https://www.iana.org/go/rfc858.

ApproxMsgSizeNegotiation 

Negotiate approximate message size.

Status 

Status RFC859 https://www.iana.org/go/rfc859.

TimingMark 

Timing Mark RFC860 https://www.iana.org/go/rfc860.

RemoteControlledTransAndEcho 

RCTE, Remote Controlled Transmission and Echo RFC726 https://www.iana.org/go/rfc726.

OutputLineWidth 

Output Line Width.

OutputPageSize 

Output Page Size.

OutputCarriageReturnDisposition 

NAOCRD, Negotiate About Output Carriage-Return Disposition RFC652 https://www.iana.org/go/rfc652.

OutputHorizontalTabStops 

NAOHTS, Negotiate About Output Horizontal Tabstops RFC653 https://www.iana.org/go/rfc653.

OutputHorizontalTabDisposition 

NAOHTD, Negotiate About Output Horizontal Tab Disposition RFC654 https://www.iana.org/go/rfc654.

OutputFormfeedDisposition 

NAOFFD, Negotiate About Output Formfeed Disposition RFC655 https://www.iana.org/go/rfc655.

OutputVerticalTabStops 

NAOVTS, Negotiate About Vertical Tabstops RFC656 https://www.iana.org/go/rfc656.

OutputVerticalTabDisposition 

NAOVTD, Negotiate About Output Vertcial Tab Disposition RFC657 https://www.iana.org/go/rfc657.

OutputLinefeedDisposition 

NAOLFD, Negotiate About Output Linefeed Disposition RFC658 https://www.iana.org/go/rfc658.

ExtendedASCII 

Extended ASCII RFC698 https://www.iana.org/go/rfc698.

Logout 

Logout RFC727 https://www.iana.org/go/rfc727.

ByteMacro 

BM, Byte Macro RFC735 https://www.iana.org/go/rfc735.

DataEntryTerminal 

Data Entry Terminal RFC1043 - RFC732 https://www.iana.org/go/rfc1043 https://www.iana.org/go/rfc732.

SUPDUP 

SUPDUP RFC736 - RFC734 https://www.iana.org/go/rfc736 https://www.iana.org/go/rfc734.

SUPDUPOutput 

SUPDUP Output RFC749 https://www.iana.org/go/rfc749.

SendLocation 

Send Location RFC779 https://www.iana.org/go/rfc779.

TerminalType 

Terminal Type RFC1091 https://www.iana.org/go/rfc1091.

EndOfRecordOption 

End of record RFC885 https://www.iana.org/go/rfc885.

TACACSUserIdentification 

TUID, TACACS User Identification RFC927 https://www.iana.org/go/rfc927.

OutputMarking 

OUTMRK, Output Marking RFC933 https://www.iana.org/go/rfc933.

TerminalLocationNumber 

TTYLOC, Terminal Location Number RFC946 https://www.iana.org/go/rfc946.

Telnet3270Regime 

Telnet 3270 Regime RFC1041 https://www.iana.org/go/rfc1041.

X3Pad 

X.3 PAD RFC1053 https://www.iana.org/go/rfc1053.

NegotiateAboutWindowSize 

NAWS, Negotiate About Window Size RFC1073 https://www.iana.org/go/rfc1073.

TerminalSpeed 

Terminal Speed RFC1079 https://www.iana.org/go/rfc1079.

RemoteFlowControl 

Remote Flow Control RFC1372 https://www.iana.org/go/rfc1372.

Linemode 

Line Mode RFC1184 https://www.iana.org/go/rfc1184.

XDisplayLocation 

X Display Location RFC1096 https://www.iana.org/go/rfc1096.

EnvironmentOption 

Environment Option RFC1408 https://www.iana.org/go/rfc1408.

AuthenticationOption 

Authentication Option RFC2941 https://www.iana.org/go/rfc2941.

EncryptionOption 

Encryption Option RFC2946 https://www.iana.org/go/rfc2946.

NewEnvironmentOption 

New Environment Option RFC1572 https://www.iana.org/go/rfc1572.

TN3270E 

TN3270E RFC2355 https://www.iana.org/go/rfc2355.

XAuth 

X Server Authentication.

Charset 

Charset RFC2066 https://www.iana.org/go/rfc2066.

TelnetRemoteSerialPort 

RSP, Telnet Remote Serial Port.

ComPortControlOption 

Com Port Control Option RFC2217 https://www.iana.org/go/rfc2217.

TelnetSuppressLocalEcho 

Telnet Suppress Local Echo.

TelnetStartTLS 

Telnet Start TLS.

Kermit 

Kermit RFC2840 https://www.iana.org/go/rfc2840.

SendURL 

Send URL.

ForwardX 

Forward X Server.

TelOptPragmaLogon 

Telnet Option Pragma Logon.

TelOptSSPILogon 

Telnet Option SSPI Logon.

TelOptPragmaHeartbeat 

Telnet Option Pragma Heartbeat.

ExtendedOptions 

Extended option list.

Constructor & Destructor Documentation

◆ TelnetLayer()

pcpp::TelnetLayer::TelnetLayer ( uint8_t *  data,
size_t  dataLen,
Layer prevLayer,
Packet packet 
)
inline

A constructor that creates the layer from an existing packet raw data

Parameters
[in]dataA pointer to the raw data
[in]dataLenSize of the data in bytes
[in]prevLayerA pointer to the previous layer
[in]packetA pointer to the Packet instance where layer will be stored in

Member Function Documentation

◆ getDataAsString()

std::string pcpp::TelnetLayer::getDataAsString ( bool  removeEscapeCharacters = true)

Get the Telnet data as readable string

Parameters
[in]removeEscapeCharactersWhether non-alphanumerical characters should be removed or not
Returns
Full payload as readable string, empty if Telnet packet contains control commands/options.

◆ getFirstCommand()

TelnetCommand pcpp::TelnetLayer::getFirstCommand ( )

Returns the first command of packet

Returns
TelnetCommand First detected command value, TelnetCommandEndOfPacket if there is no command field

◆ getHeaderLen()

size_t pcpp::TelnetLayer::getHeaderLen ( ) const
inlinevirtual
Returns
Get the size of the layer

Implements pcpp::Layer.

◆ getNextCommand()

TelnetCommand pcpp::TelnetLayer::getNextCommand ( )

Returns the next command of packet. Uses an internal iterator. The iterator resets when reached end of packet.

Returns
TelnetCommand Detected command value, TelnetCommandEndOfPacket if reached the end of packet.

◆ getNumberOfCommands()

size_t pcpp::TelnetLayer::getNumberOfCommands ( TelnetCommand  command)

Returns the number of occurrences of provided command

Parameters
[in]commandTelnet command to count
Returns
size_t Number of occurrences of command

◆ getOption() [1/2]

TelnetOption pcpp::TelnetLayer::getOption ( )

Returns the option of current command. Uses an internal iterator. Iterator can be moved with getNextCommand

Returns
TelnetOption Option of current command

◆ getOption() [2/2]

TelnetOption pcpp::TelnetLayer::getOption ( TelnetCommand  command)

Returns the option of provided command. It will return option of first occurrence of the command

Parameters
[in]commandTelnet command to search
Returns
TelnetOption Option of the command. Returns TelnetOptionNoOption if the provided command not found.

◆ getOptionData() [1/2]

uint8_t* pcpp::TelnetLayer::getOptionData ( size_t &  length)

Returns the data of current command. Uses an internal iterator. Iterator can be moved with getNextCommand

Parameters
[out]lengthLength of the data of current command
Returns
uint8_t* Pointer to the data of current command. NULL if there is no data for this command.

◆ getOptionData() [2/2]

uint8_t* pcpp::TelnetLayer::getOptionData ( TelnetCommand  command,
size_t &  length 
)

Returns the data of provided command. It will return data of first occurrence of the command

Parameters
[in]commandTelnet command to search
[out]lengthLength of the data of current command
Returns
uint8_t* Pointer to the data of current command. NULL if there is no data for this command or if can't find the command.

◆ getOsiModelLayer()

OsiModelLayer pcpp::TelnetLayer::getOsiModelLayer ( ) const
inlinevirtual
Returns
The OSI layer level of Telnet (Application Layer).

Implements pcpp::Layer.

◆ getTelnetCommandAsString()

static std::string pcpp::TelnetLayer::getTelnetCommandAsString ( TelnetCommand  val)
static

Convert the Telnet Command to readable string

Parameters
[in]valValue of the command
Returns
The Telnet Command as readable string

◆ getTelnetOptionAsString()

static std::string pcpp::TelnetLayer::getTelnetOptionAsString ( TelnetOption  val)
static

Convert the Telnet option to readable string

Parameters
[in]valValue of the option
Returns
The Telnet Option as readable string

◆ getTotalNumberOfCommands()

size_t pcpp::TelnetLayer::getTotalNumberOfCommands ( )

Get the total number of detected Telnet commands

Returns
size_t The number of Telnet commands

◆ isDataValid()

static bool pcpp::TelnetLayer::isDataValid ( const uint8_t *  data,
size_t  dataSize 
)
inlinestatic

A static method that takes a byte array and detects whether it is a Telnet message

Parameters
[in]dataA byte array
[in]dataSizeThe byte array size (in bytes)
Returns
True if the data is identified as Telnet message

◆ isTelnetPort()

static bool pcpp::TelnetLayer::isTelnetPort ( uint16_t  port)
inlinestatic

A static method that checks whether the port is considered as Telnet

Parameters
[in]portThe port number to be checked

◆ toString()

std::string pcpp::TelnetLayer::toString ( ) const
virtual
Returns
Returns the protocol info as readable string

Implements pcpp::Layer.