PcapPlusPlus  22.11
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);
26  // Checks if position is a command field
27  bool isCommandField(uint8_t *pos);
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:
46  {
49 
51  EndOfFile = 236,
101  };
102 
107  {
110 
211 
218 
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 */
Authentication Option RFC2941 https://www.iana.org/go/rfc2941.
Definition: TelnetLayer.h:186
The main namespace for the PcapPlusPlus lib.
OsiModelLayer
Definition: ProtocolType.h:298
Telnet 3270 Regime RFC1041 https://www.iana.org/go/rfc1041.
Definition: TelnetLayer.h:170
Telnet Option Pragma Heartbeat.
Definition: TelnetLayer.h:217
Echo RFC857 https://www.iana.org/go/rfc857.
Definition: TelnetLayer.h:114
Output Line Width.
Definition: TelnetLayer.h:128
Reconnection.
Definition: TelnetLayer.h:116
TUID, TACACS User Identification RFC927 https://www.iana.org/go/rfc927.
Definition: TelnetLayer.h:164
New Environment Option RFC1572 https://www.iana.org/go/rfc1572.
Definition: TelnetLayer.h:190
Charset RFC2066 https://www.iana.org/go/rfc2066.
Definition: TelnetLayer.h:196
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
Suspend current process.
Definition: TelnetLayer.h:53
Suppress Go Ahead RFC858 https://www.iana.org/go/rfc858.
Definition: TelnetLayer.h:118
Definition: TelnetLayer.h:85
Definition: ProtocolType.h:313
SUPDUP RFC736 - RFC734 https://www.iana.org/go/rfc736 https://www.iana.org/go/rfc734.
Definition: TelnetLayer.h:154
Definition: Layer.h:70
End of Record.
Definition: TelnetLayer.h:57
Data Entry Terminal RFC1043 - RFC732 https://www.iana.org/go/rfc1043 https://www.iana.org/go/rfc732.
Definition: TelnetLayer.h:152
Definition: TelnetLayer.h:60
Logout RFC727 https://www.iana.org/go/rfc727.
Definition: TelnetLayer.h:148
Definition: Packet.h:26
size_t getTotalNumberOfCommands()
TelnetLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: TelnetLayer.h:230
Telnet Option SSPI Logon.
Definition: TelnetLayer.h:215
Timing Mark RFC860 https://www.iana.org/go/rfc860.
Definition: TelnetLayer.h:124
Definition: TelnetLayer.h:18
OsiModelLayer getOsiModelLayer() const
Definition: TelnetLayer.h:341
TelnetCommand
Definition: TelnetLayer.h:45
std::string getDataAsString(bool removeEscapeCharacters=true)
Terminal Type RFC1091 https://www.iana.org/go/rfc1091.
Definition: TelnetLayer.h:160
TN3270E RFC2355 https://www.iana.org/go/rfc2355.
Definition: TelnetLayer.h:192
Send Location RFC779 https://www.iana.org/go/rfc779.
Definition: TelnetLayer.h:158
Extended ASCII RFC698 https://www.iana.org/go/rfc698.
Definition: TelnetLayer.h:146
Used in Telnet half-duplex mode to signal the other device that it may transmit.
Definition: TelnetLayer.h:82
SUPDUP Output RFC749 https://www.iana.org/go/rfc749.
Definition: TelnetLayer.h:156
NAOHTD, Negotiate About Output Horizontal Tab Disposition RFC654 https://www.iana.org/go/rfc654.
Definition: TelnetLayer.h:136
Definition: TelnetLayer.h:91
Null command; does nothing.
Definition: TelnetLayer.h:62
Telnet Option Pragma Logon.
Definition: TelnetLayer.h:213
std::string toString() const
Environment Option RFC1408 https://www.iana.org/go/rfc1408.
Definition: TelnetLayer.h:184
NAWS, Negotiate About Window Size RFC1073 https://www.iana.org/go/rfc1073.
Definition: TelnetLayer.h:174
OUTMRK, Output Marking RFC933 https://www.iana.org/go/rfc933.
Definition: TelnetLayer.h:166
const ProtocolType Telnet
Definition: ProtocolType.h:263
Definition: TelnetLayer.h:97
Line Mode RFC1184 https://www.iana.org/go/rfc1184.
Definition: TelnetLayer.h:180
void computeCalculateFields()
Does nothing for this layer.
Definition: TelnetLayer.h:336
Status RFC859 https://www.iana.org/go/rfc859.
Definition: TelnetLayer.h:122
Extended option list.
Definition: TelnetLayer.h:220
TTYLOC, Terminal Location Number RFC946 https://www.iana.org/go/rfc946.
Definition: TelnetLayer.h:168
Indicator to parser reached end of packet.
Definition: TelnetLayer.h:48
Negotiate approximate message size.
Definition: TelnetLayer.h:120
RCTE, Remote Controlled Transmission and Echo RFC726 https://www.iana.org/go/rfc726.
Definition: TelnetLayer.h:126
Definition: TelnetLayer.h:77
Forward X Server.
Definition: TelnetLayer.h:210
RSP, Telnet Remote Serial Port.
Definition: TelnetLayer.h:198
End of file.
Definition: TelnetLayer.h:51
End of record RFC885 https://www.iana.org/go/rfc885.
Definition: TelnetLayer.h:162
Definition: TelnetLayer.h:74
Definition: TelnetLayer.h:71
BM, Byte Macro RFC735 https://www.iana.org/go/rfc735.
Definition: TelnetLayer.h:150
Com Port Control Option RFC2217 https://www.iana.org/go/rfc2217.
Definition: TelnetLayer.h:200
Output Page Size.
Definition: TelnetLayer.h:130
Tells the recipient to interrupt, abort, suspend or terminate the process currently in use...
Definition: TelnetLayer.h:68
X.3 PAD RFC1053 https://www.iana.org/go/rfc1053.
Definition: TelnetLayer.h:172
static bool isDataValid(const uint8_t *data, size_t dataSize)
Definition: TelnetLayer.h:323
static bool isTelnetPort(uint16_t port)
Definition: TelnetLayer.h:315
Abort Process.
Definition: TelnetLayer.h:55
NAOCRD, Negotiate About Output Carriage-Return Disposition RFC652 https://www.iana.org/go/rfc652.
Definition: TelnetLayer.h:132
Remote Flow Control RFC1372 https://www.iana.org/go/rfc1372.
Definition: TelnetLayer.h:178
Definition: TelnetLayer.h:100
Definition: TelnetLayer.h:80
NAOHTS, Negotiate About Output Horizontal Tabstops RFC653 https://www.iana.org/go/rfc653.
Definition: TelnetLayer.h:134
size_t getNumberOfCommands(TelnetCommand command)
Telnet Suppress Local Echo.
Definition: TelnetLayer.h:202
Send URL.
Definition: TelnetLayer.h:208
Used to mark the end of a sequence of data that the recipient should scan for urgent Telnet commands...
Definition: TelnetLayer.h:64
NAOFFD, Negotiate About Output Formfeed Disposition RFC655 https://www.iana.org/go/rfc655.
Definition: TelnetLayer.h:138
X Server Authentication.
Definition: TelnetLayer.h:194
uint8_t * getOptionData(size_t &length)
size_t getHeaderLen() const
Definition: TelnetLayer.h:333
TelnetCommand getNextCommand()
Represents the pressing of the “break” or “attention” key on the terminal.
Definition: TelnetLayer.h:66
Kermit RFC2840 https://www.iana.org/go/rfc2840.
Definition: TelnetLayer.h:206
Internal return for no option detected.
Definition: TelnetLayer.h:109
TelnetOption getOption()
X Display Location RFC1096 https://www.iana.org/go/rfc1096.
Definition: TelnetLayer.h:182
NAOVTD, Negotiate About Output Vertcial Tab Disposition RFC657 https://www.iana.org/go/rfc657.
Definition: TelnetLayer.h:142
Definition: TelnetLayer.h:88
Telnet Start TLS.
Definition: TelnetLayer.h:204
Terminal Speed RFC1079 https://www.iana.org/go/rfc1079.
Definition: TelnetLayer.h:176
NAOVTS, Negotiate About Vertical Tabstops RFC656 https://www.iana.org/go/rfc656.
Definition: TelnetLayer.h:140
TelnetCommand getFirstCommand()
Encryption Option RFC2946 https://www.iana.org/go/rfc2946.
Definition: TelnetLayer.h:188
static std::string getTelnetCommandAsString(TelnetCommand val)
Binary Transmission RFC856 https://www.iana.org/go/rfc856.
Definition: TelnetLayer.h:112
TelnetOption
Definition: TelnetLayer.h:106
NAOLFD, Negotiate About Output Linefeed Disposition RFC658 https://www.iana.org/go/rfc658.
Definition: TelnetLayer.h:144
Definition: TelnetLayer.h:94