PcapPlusPlus  Next
TelnetLayer.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "Layer.h"
4 
6 
9 namespace pcpp
10 {
12  class TelnetLayer : public Layer
13  {
14  private:
15  // Position iterator for next command
16  size_t lastPositionOffset;
17 
18  // Returns distance to next IAC
19  size_t distanceToNextIAC(uint8_t* startPos, size_t maxLength);
20  // Returns length of provided field
21  size_t getFieldLen(uint8_t* startPos, size_t maxLength);
22  // Get position of next data field
23  uint8_t* getNextDataField(uint8_t* pos, size_t len);
24  // Get position of next command field
25  uint8_t* getNextCommandField(uint8_t* pos, size_t len);
26  // Get options of provided field
27  int16_t getSubCommand(uint8_t* pos, size_t len);
28  // Get data of provided field
29  uint8_t* getCommandData(uint8_t* pos, size_t& slen);
30 
31  public:
33  enum class TelnetCommand : int
34  {
37 
39  EndOfFile = 236,
41  Suspend,
43  Abort,
52  DataMark,
54  Break,
68  EraseLine,
70  GoAhead,
82  DoPerform,
89  };
90 
92  enum class TelnetOption : int
93  {
96 
98  TransmitBinary = 0,
100  Echo,
102  Reconnection,
108  Status,
110  TimingMark,
134  Logout,
136  ByteMacro,
140  SUPDUP,
142  SUPDUPOutput,
144  SendLocation,
146  TerminalType,
158  X3Pad,
166  Linemode,
178  TN3270E,
180  XAuth,
182  Charset,
192  Kermit,
194  SendURL,
196  ForwardX,
197 
199  TelOptPragmaLogon = 138,
204 
206  ExtendedOptions = 255
207  };
208 
214  TelnetLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
215  : Layer(data, dataLen, prevLayer, packet, Telnet)
216  {
217  lastPositionOffset = SIZE_MAX;
218  };
219 
223  std::string getDataAsString(bool removeEscapeCharacters = true);
224 
228 
233 
237 
242 
246 
251 
255  uint8_t* getOptionData(size_t& length);
256 
262  uint8_t* getOptionData(TelnetCommand command, size_t& length);
263 
267  static std::string getTelnetCommandAsString(TelnetCommand val);
268 
272  static std::string getTelnetOptionAsString(TelnetOption val);
273 
276  static bool isTelnetPort(uint16_t port)
277  {
278  return port == 23;
279  }
280 
285  static bool isDataValid(const uint8_t* data, size_t dataSize)
286  {
287  return data && dataSize;
288  }
289 
290  // overridden methods
291 
293  void parseNextLayer() override
294  {}
295 
297  size_t getHeaderLen() const override
298  {
299  return m_DataLen;
300  }
301 
303  void computeCalculateFields() override
304  {}
305 
308  {
310  }
311 
313  std::string toString() const override;
314  };
315 
316 } // namespace pcpp
Definition: Layer.h:62
Definition: Packet.h:22
Class for representing the Telnet Layer.
Definition: TelnetLayer.h:13
void computeCalculateFields() override
Does nothing for this layer.
Definition: TelnetLayer.h:303
TelnetOption getOption(TelnetCommand command)
static std::string getTelnetOptionAsString(TelnetOption val)
static bool isDataValid(const uint8_t *data, size_t dataSize)
Definition: TelnetLayer.h:285
uint8_t * getOptionData(size_t &length)
TelnetCommand getNextCommand()
static std::string getTelnetCommandAsString(TelnetCommand val)
std::string toString() const override
OsiModelLayer getOsiModelLayer() const override
Definition: TelnetLayer.h:307
static bool isTelnetPort(uint16_t port)
Definition: TelnetLayer.h:276
size_t getTotalNumberOfCommands()
TelnetLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: TelnetLayer.h:214
TelnetCommand
Telnet Command Indicator.
Definition: TelnetLayer.h:34
@ TelnetCommandEndOfPacket
Indicator to parser reached end of packet.
@ NoOperation
Null command; does nothing.
@ InterruptProcess
Tells the recipient to interrupt, abort, suspend or terminate the process currently in use.
@ DataMark
Used to mark the end of a sequence of data that the recipient should scan for urgent Telnet commands.
@ GoAhead
Used in Telnet half-duplex mode to signal the other device that it may transmit.
@ Suspend
Suspend current process.
@ Break
Represents the pressing of the “break” or “attention” key on the terminal.
uint8_t * getOptionData(TelnetCommand command, size_t &length)
TelnetOption
Telnet Options.
Definition: TelnetLayer.h:93
@ Telnet3270Regime
Telnet 3270 Regime RFC1041 https://www.iana.org/go/rfc1041.
@ ExtendedOptions
Extended option list.
@ SuppressGoAhead
Suppress Go Ahead RFC858 https://www.iana.org/go/rfc858.
@ Logout
Logout RFC727 https://www.iana.org/go/rfc727.
@ NewEnvironmentOption
New Environment Option RFC1572 https://www.iana.org/go/rfc1572.
@ ExtendedASCII
Extended ASCII RFC698 https://www.iana.org/go/rfc698.
@ OutputHorizontalTabDisposition
NAOHTD, Negotiate About Output Horizontal Tab Disposition RFC654 https://www.iana....
@ XDisplayLocation
X Display Location RFC1096 https://www.iana.org/go/rfc1096.
@ OutputMarking
OUTMRK, Output Marking RFC933 https://www.iana.org/go/rfc933.
@ RemoteFlowControl
Remote Flow Control RFC1372 https://www.iana.org/go/rfc1372.
@ TelOptPragmaHeartbeat
Telnet Option Pragma Heartbeat.
@ ByteMacro
BM, Byte Macro RFC735 https://www.iana.org/go/rfc735.
@ Linemode
Line Mode RFC1184 https://www.iana.org/go/rfc1184.
@ TelnetStartTLS
Telnet Start TLS.
@ OutputVerticalTabStops
NAOVTS, Negotiate About Vertical Tabstops RFC656 https://www.iana.org/go/rfc656.
@ TACACSUserIdentification
TUID, TACACS User Identification RFC927 https://www.iana.org/go/rfc927.
@ EncryptionOption
Encryption Option RFC2946 https://www.iana.org/go/rfc2946.
@ EnvironmentOption
Environment Option RFC1408 https://www.iana.org/go/rfc1408.
@ OutputPageSize
Output Page Size.
@ RemoteControlledTransAndEcho
RCTE, Remote Controlled Transmission and Echo RFC726 https://www.iana.org/go/rfc726.
@ TerminalType
Terminal Type RFC1091 https://www.iana.org/go/rfc1091.
@ TelOptSSPILogon
Telnet Option SSPI Logon.
@ OutputVerticalTabDisposition
NAOVTD, Negotiate About Output Vertcial Tab Disposition RFC657 https://www.iana.org/go/rfc657.
@ TerminalLocationNumber
TTYLOC, Terminal Location Number RFC946 https://www.iana.org/go/rfc946.
@ EndOfRecordOption
End of record RFC885 https://www.iana.org/go/rfc885.
@ X3Pad
X.3 PAD RFC1053 https://www.iana.org/go/rfc1053.
@ Kermit
Kermit RFC2840 https://www.iana.org/go/rfc2840.
@ AuthenticationOption
Authentication Option RFC2941 https://www.iana.org/go/rfc2941.
@ TelOptPragmaLogon
Telnet Option Pragma Logon.
@ OutputHorizontalTabStops
NAOHTS, Negotiate About Output Horizontal Tabstops RFC653 https://www.iana.org/go/rfc653.
@ TN3270E
TN3270E RFC2355 https://www.iana.org/go/rfc2355.
@ TelnetRemoteSerialPort
RSP, Telnet Remote Serial Port.
@ TelnetOptionNoOption
Internal return for no option detected.
@ OutputLineWidth
Output Line Width.
@ DataEntryTerminal
Data Entry Terminal RFC1043 - RFC732 https://www.iana.org/go/rfc1043 https://www.iana....
@ SUPDUP
SUPDUP RFC736 - RFC734 https://www.iana.org/go/rfc736 https://www.iana.org/go/rfc734.
@ OutputCarriageReturnDisposition
NAOCRD, Negotiate About Output Carriage-Return Disposition RFC652 https://www.iana....
@ TransmitBinary
Binary Transmission RFC856 https://www.iana.org/go/rfc856.
@ SUPDUPOutput
SUPDUP Output RFC749 https://www.iana.org/go/rfc749.
@ TelnetSuppressLocalEcho
Telnet Suppress Local Echo.
@ Echo
Echo RFC857 https://www.iana.org/go/rfc857.
@ XAuth
X Server Authentication.
@ SendLocation
Send Location RFC779 https://www.iana.org/go/rfc779.
@ OutputFormfeedDisposition
NAOFFD, Negotiate About Output Formfeed Disposition RFC655 https://www.iana.org/go/rfc655.
@ TerminalSpeed
Terminal Speed RFC1079 https://www.iana.org/go/rfc1079.
@ ComPortControlOption
Com Port Control Option RFC2217 https://www.iana.org/go/rfc2217.
@ Status
Status RFC859 https://www.iana.org/go/rfc859.
@ ApproxMsgSizeNegotiation
Negotiate approximate message size.
@ NegotiateAboutWindowSize
NAWS, Negotiate About Window Size RFC1073 https://www.iana.org/go/rfc1073.
@ OutputLinefeedDisposition
NAOLFD, Negotiate About Output Linefeed Disposition RFC658 https://www.iana.org/go/rfc658.
@ Charset
Charset RFC2066 https://www.iana.org/go/rfc2066.
@ TimingMark
Timing Mark RFC860 https://www.iana.org/go/rfc860.
void parseNextLayer() override
Parses the next layer. Telnet is the always last so does nothing for this layer.
Definition: TelnetLayer.h:293
TelnetOption getOption()
TelnetCommand getFirstCommand()
size_t getNumberOfCommands(TelnetCommand command)
std::string getDataAsString(bool removeEscapeCharacters=true)
size_t getHeaderLen() const override
Definition: TelnetLayer.h:297
const ProtocolType Telnet
Telnet Protocol.
Definition: ProtocolType.h:186
The main namespace for the PcapPlusPlus lib.
Definition: AssertionUtils.h:19
OsiModelLayer
An enum representing OSI model layers.
Definition: ProtocolType.h:261
@ OsiModelApplicationLayer
Application layer (layer 7)
Definition: ProtocolType.h:275