PcapPlusPlus  24.09
TelnetLayer.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "Layer.h"
4 
6 
11 namespace pcpp
12 {
13 
17  class TelnetLayer : public Layer
18  {
19  private:
20  // Position iterator for next command
21  size_t lastPositionOffset;
22 
23  // Checks if position is a data field
24  bool isDataField(uint8_t* pos) const;
25  // Checks if position is a command field
26  bool isCommandField(uint8_t* pos) const;
27  // Returns distance to next IAC
28  size_t distanceToNextIAC(uint8_t* startPos, size_t maxLength);
29  // Returns length of provided field
30  size_t getFieldLen(uint8_t* startPos, size_t maxLength);
31  // Get position of next data field
32  uint8_t* getNextDataField(uint8_t* pos, size_t len);
33  // Get position of next command field
34  uint8_t* getNextCommandField(uint8_t* pos, size_t len);
35  // Get options of provided field
36  int16_t getSubCommand(uint8_t* pos, size_t len);
37  // Get data of provided field
38  uint8_t* getCommandData(uint8_t* pos, size_t& slen);
39 
40  public:
44  enum class TelnetCommand : int
45  {
48 
50  EndOfFile = 236,
52  Suspend,
54  Abort,
63  DataMark,
65  Break,
79  EraseLine,
81  GoAhead,
93  DoPerform,
100  };
101 
105  enum class TelnetOption : int
106  {
109 
111  TransmitBinary = 0,
113  Echo,
115  Reconnection,
121  Status,
123  TimingMark,
147  Logout,
149  ByteMacro,
153  SUPDUP,
155  SUPDUPOutput,
157  SendLocation,
159  TerminalType,
171  X3Pad,
179  Linemode,
191  TN3270E,
193  XAuth,
195  Charset,
205  Kermit,
207  SendURL,
209  ForwardX,
210 
212  TelOptPragmaLogon = 138,
217 
219  ExtendedOptions = 255
220  };
221 
229  TelnetLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
230  : Layer(data, dataLen, prevLayer, packet, Telnet)
231  {
232  lastPositionOffset = SIZE_MAX;
233  };
234 
240  std::string getDataAsString(bool removeEscapeCharacters = true);
241 
247 
254 
260 
267 
273 
280 
286  uint8_t* getOptionData(size_t& length);
287 
295  uint8_t* getOptionData(TelnetCommand command, size_t& length);
296 
302  static std::string getTelnetCommandAsString(TelnetCommand val);
303 
309  static std::string getTelnetOptionAsString(TelnetOption val);
310 
315  static bool isTelnetPort(uint16_t port)
316  {
317  return port == 23;
318  }
319 
326  static bool isDataValid(const uint8_t* data, size_t dataSize)
327  {
328  return data && dataSize;
329  }
330 
331  // overridden methods
332 
335  {}
336 
340  size_t getHeaderLen() const
341  {
342  return m_DataLen;
343  }
344 
347  {}
348 
353  {
355  }
356 
360  std::string toString() const;
361  };
362 
363 } // namespace pcpp
Definition: Layer.h:70
Definition: Packet.h:27
Definition: TelnetLayer.h:18
void computeCalculateFields()
Does nothing for this layer.
Definition: TelnetLayer.h:346
TelnetOption getOption(TelnetCommand command)
static std::string getTelnetOptionAsString(TelnetOption val)
static bool isDataValid(const uint8_t *data, size_t dataSize)
Definition: TelnetLayer.h:326
uint8_t * getOptionData(size_t &length)
TelnetCommand getNextCommand()
static std::string getTelnetCommandAsString(TelnetCommand val)
std::string toString() const
void parseNextLayer()
Parses the next layer. Telnet is the always last so does nothing for this layer.
Definition: TelnetLayer.h:334
static bool isTelnetPort(uint16_t port)
Definition: TelnetLayer.h:315
size_t getTotalNumberOfCommands()
TelnetLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: TelnetLayer.h:229
TelnetCommand
Definition: TelnetLayer.h:45
@ 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
Definition: TelnetLayer.h:106
@ 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.
size_t getHeaderLen() const
Definition: TelnetLayer.h:340
TelnetOption getOption()
TelnetCommand getFirstCommand()
OsiModelLayer getOsiModelLayer() const
Definition: TelnetLayer.h:352
size_t getNumberOfCommands(TelnetCommand command)
std::string getDataAsString(bool removeEscapeCharacters=true)
The main namespace for the PcapPlusPlus lib.
OsiModelLayer
Definition: ProtocolType.h:354
@ OsiModelApplicationLayer
Definition: ProtocolType.h:368
const ProtocolType Telnet
Definition: ProtocolType.h:268