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  // Checks if position is a data field
19  bool isDataField(uint8_t* pos) const;
20  // Checks if position is a command field
21  bool isCommandField(uint8_t* pos) const;
22  // Returns distance to next IAC
23  size_t distanceToNextIAC(uint8_t* startPos, size_t maxLength);
24  // Returns length of provided field
25  size_t getFieldLen(uint8_t* startPos, size_t maxLength);
26  // Get position of next data field
27  uint8_t* getNextDataField(uint8_t* pos, size_t len);
28  // Get position of next command field
29  uint8_t* getNextCommandField(uint8_t* pos, size_t len);
30  // Get options of provided field
31  int16_t getSubCommand(uint8_t* pos, size_t len);
32  // Get data of provided field
33  uint8_t* getCommandData(uint8_t* pos, size_t& slen);
34 
35  public:
37  enum class TelnetCommand : int
38  {
41 
43  EndOfFile = 236,
45  Suspend,
47  Abort,
56  DataMark,
58  Break,
72  EraseLine,
74  GoAhead,
86  DoPerform,
93  };
94 
96  enum class TelnetOption : int
97  {
100 
102  TransmitBinary = 0,
104  Echo,
106  Reconnection,
112  Status,
114  TimingMark,
138  Logout,
140  ByteMacro,
144  SUPDUP,
146  SUPDUPOutput,
148  SendLocation,
150  TerminalType,
162  X3Pad,
170  Linemode,
182  TN3270E,
184  XAuth,
186  Charset,
196  Kermit,
198  SendURL,
200  ForwardX,
201 
203  TelOptPragmaLogon = 138,
208 
210  ExtendedOptions = 255
211  };
212 
218  TelnetLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
219  : Layer(data, dataLen, prevLayer, packet, Telnet)
220  {
221  lastPositionOffset = SIZE_MAX;
222  };
223 
227  std::string getDataAsString(bool removeEscapeCharacters = true);
228 
232 
237 
241 
246 
250 
255 
259  uint8_t* getOptionData(size_t& length);
260 
266  uint8_t* getOptionData(TelnetCommand command, size_t& length);
267 
271  static std::string getTelnetCommandAsString(TelnetCommand val);
272 
276  static std::string getTelnetOptionAsString(TelnetOption val);
277 
280  static bool isTelnetPort(uint16_t port)
281  {
282  return port == 23;
283  }
284 
289  static bool isDataValid(const uint8_t* data, size_t dataSize)
290  {
291  return data && dataSize;
292  }
293 
294  // overridden methods
295 
297  void parseNextLayer() override
298  {}
299 
301  size_t getHeaderLen() const override
302  {
303  return m_DataLen;
304  }
305 
307  void computeCalculateFields() override
308  {}
309 
312  {
314  }
315 
317  std::string toString() const override;
318  };
319 
320 } // namespace pcpp
Definition: Layer.h:60
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:307
TelnetOption getOption(TelnetCommand command)
static std::string getTelnetOptionAsString(TelnetOption val)
static bool isDataValid(const uint8_t *data, size_t dataSize)
Definition: TelnetLayer.h:289
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:311
static bool isTelnetPort(uint16_t port)
Definition: TelnetLayer.h:280
size_t getTotalNumberOfCommands()
TelnetLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: TelnetLayer.h:218
TelnetCommand
Telnet Command Indicator.
Definition: TelnetLayer.h:38
@ 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:97
@ 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:297
TelnetOption getOption()
TelnetCommand getFirstCommand()
size_t getNumberOfCommands(TelnetCommand command)
std::string getDataAsString(bool removeEscapeCharacters=true)
size_t getHeaderLen() const override
Definition: TelnetLayer.h:301
The main namespace for the PcapPlusPlus lib.
OsiModelLayer
An enum representing OSI model layers.
Definition: ProtocolType.h:225
@ OsiModelApplicationLayer
Application layer (layer 7)
Definition: ProtocolType.h:239
const ProtocolType Telnet
Telnet Protocol.
Definition: ProtocolType.h:164