PcapPlusPlus  23.09
TelnetLayer.h
Go to the documentation of this file.
1 #ifndef PACKETPP_TELNET_LAYER
2 #define PACKETPP_TELNET_LAYER
3 
4 #include "Layer.h"
5 
7 
12 namespace pcpp
13 {
14 
18 class TelnetLayer : public Layer
19 {
20  private:
21  // Position iterator for next command
22  size_t lastPositionOffset;
23 
24  // Checks if position is a data field
25  bool isDataField(uint8_t *pos) const;
26  // Checks if position is a command field
27  bool isCommandField(uint8_t *pos) const;
28  // Returns distance to next IAC
29  size_t distanceToNextIAC(uint8_t *startPos, size_t maxLength);
30  // Returns length of provided field
31  size_t getFieldLen(uint8_t *startPos, size_t maxLength);
32  // Get position of next data field
33  uint8_t *getNextDataField(uint8_t *pos, size_t len);
34  // Get position of next command field
35  uint8_t *getNextCommandField(uint8_t *pos, size_t len);
36  // Get options of provided field
37  int16_t getSubCommand(uint8_t *pos, size_t len);
38  // Get data of provided field
39  uint8_t *getCommandData(uint8_t *pos, size_t &slen);
40 
41  public:
45  enum class TelnetCommand : int
46  {
49 
51  EndOfFile = 236,
53  Suspend,
55  Abort,
64  DataMark,
66  Break,
80  EraseLine,
82  GoAhead,
94  DoPerform,
101  };
102 
106  enum class TelnetOption : int
107  {
109  TelnetOptionNoOption = -1,
110 
112  TransmitBinary = 0,
114  Echo,
116  Reconnection,
118  SuppressGoAhead,
120  ApproxMsgSizeNegotiation,
122  Status,
124  TimingMark,
126  RemoteControlledTransAndEcho,
128  OutputLineWidth,
130  OutputPageSize,
132  OutputCarriageReturnDisposition,
134  OutputHorizontalTabStops,
136  OutputHorizontalTabDisposition,
138  OutputFormfeedDisposition,
140  OutputVerticalTabStops,
142  OutputVerticalTabDisposition,
144  OutputLinefeedDisposition,
146  ExtendedASCII,
148  Logout,
150  ByteMacro,
152  DataEntryTerminal,
154  SUPDUP,
156  SUPDUPOutput,
158  SendLocation,
160  TerminalType,
162  EndOfRecordOption,
164  TACACSUserIdentification,
166  OutputMarking,
168  TerminalLocationNumber,
170  Telnet3270Regime,
172  X3Pad,
174  NegotiateAboutWindowSize,
176  TerminalSpeed,
178  RemoteFlowControl,
180  Linemode,
182  XDisplayLocation,
184  EnvironmentOption,
186  AuthenticationOption,
188  EncryptionOption,
190  NewEnvironmentOption,
192  TN3270E,
194  XAuth,
196  Charset,
198  TelnetRemoteSerialPort,
200  ComPortControlOption,
202  TelnetSuppressLocalEcho,
204  TelnetStartTLS,
206  Kermit,
208  SendURL,
210  ForwardX,
211 
213  TelOptPragmaLogon = 138,
215  TelOptSSPILogon,
217  TelOptPragmaHeartbeat,
218 
220  ExtendedOptions = 255
221  };
222 
230  TelnetLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet) : Layer(data, dataLen, prevLayer, packet)
231  {
232  m_Protocol = Telnet;
233  lastPositionOffset = SIZE_MAX;
234  };
235 
241  std::string getDataAsString(bool removeEscapeCharacters = true);
242 
247  size_t getTotalNumberOfCommands();
248 
254  size_t getNumberOfCommands(TelnetCommand command);
255 
261 
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) { return port == 23; }
316 
323  static bool isDataValid(const uint8_t *data, size_t dataSize) { return data && dataSize; }
324 
325  // overridden methods
326 
328  void parseNextLayer() {}
329 
333  size_t getHeaderLen() const { return m_DataLen; }
334 
337 
342 
346  std::string toString() const;
347 };
348 
349 } // namespace pcpp
350 
351 #endif /* PACKETPP_TELNET_LAYER */
The main namespace for the PcapPlusPlus lib.
OsiModelLayer
Definition: ProtocolType.h:333
Tells the recipient to interrupt, abort, suspend or terminate the process currently in use...
static std::string getTelnetOptionAsString(TelnetOption val)
void parseNextLayer()
Parses the next layer. Telnet is the always last so does nothing for this layer.
Definition: TelnetLayer.h:328
Definition: ProtocolType.h:348
Definition: Layer.h:70
Definition: Packet.h:26
size_t getTotalNumberOfCommands()
TelnetLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: TelnetLayer.h:230
Definition: TelnetLayer.h:18
OsiModelLayer getOsiModelLayer() const
Definition: TelnetLayer.h:341
std::string getDataAsString(bool removeEscapeCharacters=true)
Used to mark the end of a sequence of data that the recipient should scan for urgent Telnet commands...
std::string toString() const
const ProtocolType Telnet
Definition: ProtocolType.h:263
void computeCalculateFields()
Does nothing for this layer.
Definition: TelnetLayer.h:336
Represents the pressing of the “break” or “attention” key on the terminal.
Indicator to parser reached end of packet.
TelnetOption
Definition: TelnetLayer.h:106
static bool isDataValid(const uint8_t *data, size_t dataSize)
Definition: TelnetLayer.h:323
static bool isTelnetPort(uint16_t port)
Definition: TelnetLayer.h:315
size_t getNumberOfCommands(TelnetCommand command)
Used in Telnet half-duplex mode to signal the other device that it may transmit.
uint8_t * getOptionData(size_t &length)
size_t getHeaderLen() const
Definition: TelnetLayer.h:333
TelnetCommand getNextCommand()
TelnetOption getOption()
TelnetCommand
Definition: TelnetLayer.h:45
TelnetCommand getFirstCommand()
static std::string getTelnetCommandAsString(TelnetCommand val)