pcapplusplus-sys 0.1.0

Compile PcapPlusPlus and make its library and header files available. See also https://github.com/seladb/PcapPlusPlus
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
#ifndef PACKETPP_FTP_LAYER
#define PACKETPP_FTP_LAYER

#include "SingleCommandTextProtocol.h"
#include "PayloadLayer.h"

/// @file

/**
 * \namespace pcpp
 * \brief The main namespace for the PcapPlusPlus lib
 */
namespace pcpp
{

	/**
	 * Class for general FTP message
	 */
	class FtpLayer : public SingleCommandTextProtocol
	{
	protected:
		FtpLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet) : SingleCommandTextProtocol(data, dataLen, prevLayer, packet) { m_Protocol = FTP; };
		FtpLayer(const std::string &command, const std::string &option) : SingleCommandTextProtocol(command, option) { m_Protocol = FTP; };

	public:

		/**
		 * A static method that checks whether the port is considered as FTP control
		 * @param[in] port The port number to be checked
		 */
		static bool isFtpPort(uint16_t port) { return port == 21; }

		/**
		 * A static method that checks whether the port is considered as FTP data
		 * @param[in] port The port number to be checked
		 */
		static bool isFtpDataPort(uint16_t port) { return port == 20; }

		// overridden methods

		/// FTP is the always last so does nothing for this layer
		void parseNextLayer() {}

		/**
		 * @return Get the size of the layer
		 */
		size_t getHeaderLen() const { return m_DataLen; }

		/// Does nothing for this layer
		void computeCalculateFields() {}

		/**
		 * @return The OSI layer level of FTP (Application Layer).
		 */
		OsiModelLayer getOsiModelLayer() const { return OsiModelApplicationLayer; }

	};

	/**
	 * Class for representing the request messages of FTP Layer
	 */
	class FtpRequestLayer : public FtpLayer
	{
	public:

		/**
		 * Enum for FTP command codes
		 */
		enum class FtpCommand : int
		{
			/// Unknown command
			UNK,
			/// Abort an active file transfer.
			ABOR = ('A') | ('B' << 8) | ('O' << 16) | ('R' << 24),
			/// Account information.
			ACCT = ('A') | ('C' << 8) | ('C' << 16) | ('T' << 24),
			/// Authentication/Security Data
			ADAT = ('A') | ('D' << 8) | ('A' << 16) | ('T' << 24),
			/// Allocate sufficient disk space to receive a file.
			ALLO = ('A') | ('L' << 8) | ('L' << 16) | ('O' << 24),
			/// Append (with create)
			APPE = ('A') | ('P' << 8) | ('P' << 16) | ('E' << 24),
			/// Authentication/Security Mechanism
			AUTH = ('A') | ('U' << 8) | ('T' << 16) | ('H' << 24),
			/// Get the available space
			AVBL = ('A') | ('V' << 8) | ('B' << 16) | ('L' << 24),
			/// Clear Command Channel
			CCC = ('C') | ('C' << 8) | ('C' << 16),
			/// Change to Parent Directory.
			CDUP = ('C') | ('D' << 8) | ('U' << 16) | ('P' << 24),
			/// Confidentiality Protection Command
			CONF = ('C') | ('O' << 8) | ('N' << 16) | ('F' << 24),
			/// Client / Server Identification
			CSID = ('C') | ('S' << 8) | ('I' << 16) | ('D' << 24),
			/// Change working directory.
			CWD  = ('C') | ('W' << 8) | ('D' << 16),
			/// Delete file.
			DELE = ('D') | ('E' << 8) | ('L' << 16) | ('E' << 24),
			/// Get the directory size
			DSIZ = ('D') | ('S' << 8) | ('I' << 16) | ('Z' << 24),
			/// Privacy Protected Channel
			ENC  = ('E') | ('N' << 8) | ('C' << 16),
			/// Specifies an extended address and port to which the server should connect.
			EPRT = ('E') | ('P' << 8) | ('R' << 16) | ('T' << 24),
			/// Enter extended passive mode.
			EPSV = ('E') | ('P' << 8) | ('S' << 16) | ('V' << 24),
			/// Get the feature list implemented by the server.
			FEAT = ('F') | ('E' << 8) | ('A' << 16) | ('T' << 24),
			/// Returns usage documentation on a command if specified, else a general help document is returned.
			HELP = ('H') | ('E' << 8) | ('L' << 16) | ('P' << 24),
			/// Identify desired virtual host on server, by name.
			HOST = ('H') | ('O' << 8) | ('S' << 16) | ('T' << 24),
			/// Language Negotiation
			LANG = ('L') | ('A' << 8) | ('N' << 16) | ('G' << 24),
			/// Returns information of a file or directory if specified, else information of the current working directory is returned.
			LIST = ('L') | ('I' << 8) | ('S' << 16) | ('T' << 24),
			/// Specifies a long address and port to which the server should connect.
			LPRT = ('L') | ('P' << 8) | ('R' << 16) | ('T' << 24),
			/// Enter long passive mode.
			LPSV = ('L') | ('P' << 8) | ('S' << 16) | ('V' << 24),
			/// Return the last-modified time of a specified file.
			MDTM = ('M') | ('D' << 8) | ('T' << 16) | ('M' << 24),
			/// Modify the creation time of a file.
			MFCT = ('M') | ('F' << 8) | ('C' << 16) | ('T' << 24),
			/// Modify fact (the last modification time, creation time, UNIX group/owner/mode of a file).
			MFF  = ('M') | ('F' << 8) | ('F' << 16),
			/// Modify the last modification time of a file.
			MFMT = ('M') | ('F' << 8) | ('M' << 16) | ('T' << 24),
			/// Integrity Protected Command
			MIC  = ('M') | ('I' << 8) | ('C' << 16),
			/// Make directory.
			MKD  = ('M') | ('K' << 8) | ('D' << 16),
			/// Lists the contents of a directory in a standardized machine-readable format.
			MLSD = ('M') | ('L' << 8) | ('S' << 16) | ('D' << 24),
			/// Provides data about exactly the object named on its command line in a standardized machine-readable format.
			MLST = ('M') | ('L' << 8) | ('S' << 16) | ('T' << 24),
			/// Sets the transfer mode (Stream, Block, or Compressed).
			MODE = ('M') | ('O' << 8) | ('D' << 16) | ('E' << 24),
			/// Returns a list of file names in a specified directory.
			NLST = ('N') | ('L' << 8) | ('S' << 16) | ('T' << 24),
			/// No operation (dummy packet; used mostly on keepalives).
			NOOP = ('N') | ('O' << 8) | ('O' << 16) | ('P' << 24),
			/// Select options for a feature (for example OPTS UTF8 ON).
			OPTS = ('O') | ('P' << 8) | ('T' << 16) | ('S' << 24),
			/// Authentication password.
			PASS = ('P') | ('A' << 8) | ('S' << 16) | ('S' << 24),
			/// Enter passive mode.
			PASV = ('P') | ('A' << 8) | ('S' << 16) | ('V' << 24),
			/// Protection Buffer Size
			PBSZ = ('P') | ('B' << 8) | ('S' << 16) | ('Z' << 24),
			/// Specifies an address and port to which the server should connect.
			PORT = ('P') | ('O' << 8) | ('R' << 16) | ('T' << 24),
			/// Data Channel Protection Level.
			PROT = ('P') | ('R' << 8) | ('O' << 16) | ('T' << 24),
			/// Print working directory. Returns the current directory of the host.
			PWD  = ('P') | ('W' << 8) | ('D' << 16),
			/// Disconnect.
			QUIT = ('Q') | ('U' << 8) | ('I' << 16) | ('T' << 24),
			/// Re initializes the connection.
			REIN = ('R') | ('E' << 8) | ('I' << 16) | ('N' << 24),
			/// Restart transfer from the specified point.
			REST = ('R') | ('E' << 8) | ('S' << 16) | ('T' << 24),
			/// Retrieve a copy of the file
			RETR = ('R') | ('E' << 8) | ('T' << 16) | ('R' << 24),
			/// Remove a directory.
			RMD  = ('R') | ('M' << 8) | ('D' << 16),
			/// Remove a directory tree
			RMDA = ('R') | ('M' << 8) | ('D' << 16) | ('A' << 24),
			/// Rename from.
			RNFR = ('R') | ('N' << 8) | ('F' << 16) | ('R' << 24),
			/// Rename to.
			RNTO = ('R') | ('N' << 8) | ('T' << 16) | ('O' << 24),
			/// Sends site specific commands to remote server (like SITE IDLE 60 or SITE UMASK 002). Inspect SITE HELP output for complete list of supported commands.
			SITE = ('S') | ('I' << 8) | ('T' << 16) | ('E' << 24),
			/// Return the size of a file.
			SIZE = ('S') | ('I' << 8) | ('Z' << 16) | ('E' << 24),
			/// Mount file structure.
			SMNT = ('S') | ('M' << 8) | ('N' << 16) | ('T' << 24),
			/// Use single port passive mode (only one TCP port number for both control connections and passive-mode data connections)
			SPSV = ('S') | ('P' << 8) | ('S' << 16) | ('V' << 24),
			/// Returns information on the server status, including the status of the current connection
			STAT = ('S') | ('T' << 8) | ('A' << 16) | ('T' << 24),
			/// Accept the data and to store the data as a file at the server site
			STOR = ('S') | ('T' << 8) | ('O' << 16) | ('R' << 24),
			/// Store file uniquely.
			STOU = ('S') | ('T' << 8) | ('O' << 16) | ('U' << 24),
			/// Set file transfer structure.
			STRU = ('S') | ('T' << 8) | ('R' << 16) | ('U' << 24),
			/// Return system type.
			SYST = ('S') | ('Y' << 8) | ('S' << 16) | ('T' << 24),
			/// Get a thumbnail of a remote image file
			THMB = ('T') | ('H' << 8) | ('M' << 16) | ('B' << 24),
			/// Sets the transfer mode (ASCII/Binary).
			TYPE = ('T') | ('Y' << 8) | ('P' << 16) | ('E' << 24),
			/// Authentication username.
			USER = ('U') | ('S' << 8) | ('E' << 16) | ('R' << 24),
			/// Change to the parent of the current working directory
			XCUP = ('X') | ('C' << 8) | ('U' << 16) | ('P' << 24),
			/// Make a directory
			XMKD = ('X') | ('M' << 8) | ('K' << 16) | ('D' << 24),
			/// Print the current working directory
			XPWD = ('X') | ('P' << 8) | ('W' << 16) | ('D' << 24),
			///
			XRCP = ('X') | ('R' << 8) | ('C' << 16) | ('P' << 24),
			/// Remove the directory
			XRMD = ('X') | ('R' << 8) | ('M' << 16) | ('D' << 24),
			///
			XRSQ = ('X') | ('R' << 8) | ('S' << 16) | ('Q' << 24),
			/// Send, mail if cannot
			XSEM = ('X') | ('S' << 8) | ('E' << 16) | ('M' << 24),
			/// Send to terminal
			XSEN = ('X') | ('S' << 8) | ('E' << 16) | ('N' << 24)
		};

		/** A constructor that creates the layer from an existing packet raw data
		 * @param[in] data A pointer to the raw data
		 * @param[in] dataLen Size of the data in bytes
		 * @param[in] prevLayer A pointer to the previous layer
		 * @param[in] packet A pointer to the Packet instance where layer will be stored in
		 */
		FtpRequestLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet) : FtpLayer(data, dataLen, prevLayer, packet) {};

		/**
		 * A constructor that creates layer with provided input values
		 * @param[in] command FTP command
		 * @param[in] option Argument of the command
		 */
		explicit FtpRequestLayer(const FtpCommand &command, const std::string &option = "") : FtpLayer(getCommandAsString(command), option) {};

		/**
		 * Set the command of request message
		 * @param[in] code Value to set command
		 * @return True if the operation is successful, false otherwise
		 */
		bool setCommand(FtpCommand code);

		/**
		 * Get the command of request message
		 * @return FtpCommand Value of the command
		 */
		FtpCommand getCommand() const;

		/**
		 * Get the command of request message as string
		 * @return std::string Value of the command as string
		 */
		std::string getCommandString() const;

		/**
		 * Set the command argument of request message
		 * @param[in] value Value to set command argument
		 * @return True if the operation is successful, false otherwise
		 */
		bool setCommandOption(const std::string &value);

		/**
		 * Get the command argument of request message
		 * @param[in] removeEscapeCharacters Whether non-alphanumerical characters should be removed or not
		 * @return std::string Value of command argument
		 */
		std::string getCommandOption(bool removeEscapeCharacters = true) const;

		/**
		 * Convert the command info to readable string
		 * @param[in] code Command code to convert
		 * @return std::string Returns the command info as readable string
		 */
		static std::string getCommandInfo(FtpCommand code);

		/**
		 * Convert the command to readable string
		 * @param[in] code Command code to convert
		 * @return std::string Returns the command as readable string
		 */
		static std::string getCommandAsString(FtpCommand code);

		// overridden methods

		/**
		 * @return Returns the protocol info as readable string
		 */
		std::string toString() const;
	};

	/**
	 * Class for representing the response messages of FTP Layer
	 */
	class FtpResponseLayer : public FtpLayer
	{
	public:

		/**
		 * Enum for FTP response codes
		 */
		enum class FtpStatusCode : int
		{
			/// Unknown status code
			UNKNOWN,
			/// Restart marker reply
			RESTART_MARKER = 110,
			/// Service ready in nnn minutes
			SERVICE_READY_IN_MIN = 120,
			/// Data connection already open; transfer starting
			DATA_ALREADY_OPEN_START_TRANSFER = 125,
			/// File status okay; about to open data connection
			FILE_OK = 150,
			/// Command okay
			COMMAND_OK = 200,
			/// Command not implemented, superfluous at this site
			COMMAND_NOT_IMPLEMENTED_SUPERFLUOUS = 202,
			/// System status, or system help reply
			SYSTEM_STATUS = 211,
			/// Directory status
			DIR_STATUS = 212,
			/// File status
			FILE_STATUS = 213,
			/// Help message
			HELP_MESSAGE = 214,
			/// NAME system type
			NAME_SYSTEM_TYPE = 215,
			/// Service ready for new user
			SERVICE_READY_FOR_USER = 220,
			/// Service closing control connection
			SERVICE_CLOSING_CONTROL = 221,
			/// Data connection open; no transfer in progress
			DATA_OPEN_NO_TRANSFER = 225,
			/// Closing data connection
			CLOSING_DATA = 226,
			/// Entering Passive Mode
			ENTERING_PASSIVE = 227,
			/// Entering Extended Passive Mode
			ENTERING_EXTENDED_PASSIVE = 229,
			/// User logged in, proceed
			USER_LOG_IN_PROCEED = 230,
			/// User logged in, authorized by security data exchange
			USER_LOG_IN_AUTHORIZED = 232,
			/// Security data exchange complete
			SEC_DATA_EXCHANGE_COMPLETE = 234,
			/// Security data exchange completed successfully
			SEC_DATA_EXCHANGE_COMPLETE_SUCCESS = 235,
			/// Requested file action okay, completed
			REQ_FILE_OK_COMPLETE = 250,
			/// PATHNAME created
			PATHNAME_CREATED = 257,
			/// User name okay, need password
			USER_OK_NEED_PASSWORD = 331,
			/// Need account for login
			NEED_ACCOUNT = 332,
			/// Requested security mechanism is ok
			REQ_SEC_MECHANISM_OK = 334,
			/// Security data is acceptable, more is required
			SEC_IS_ACCEPTABLE = 335,
			/// Username okay, need password. Challenge is ...
			USER_OK_NEED_PASS_CHALLENGE = 336,
			/// Requested file action pending further information
			FILE_PENDING_ACTION = 350,
			/// Service not available, closing control connection
			SERVICE_NOT_AVAILABLE = 421,
			/// Can't open data connection
			CANT_OPEN_DATA_CONNECTION = 425,
			/// Connection closed; transfer aborted
			CONNECTION_CLOSED = 426,
			/// Need some unavailable resource to process security
			NEED_UNAVAILABLE_RESOURCE_TO_SEC = 431,
			/// Requested file action not taken
			REQ_FILE_ACTION_NOT_TAKEN = 450,
			/// Requested action aborted: local error in processing
			REQ_ACTION_ABORTED = 451,
			/// Requested action not taken. Insufficient storage space in system
			REQ_ACTION_NOT_TAKEN = 452,
			/// Syntax error, command unrecognized
			SYNTAX_ERROR_COMMAND_UNRECOGNIZED = 500,
			/// Syntax error in parameters or arguments
			SYNTAX_ERROR_PARAMETER_OR_ARGUMENT = 501,
			/// Command not implemented
			COMMAND_NOT_IMPLEMENTED = 502,
			/// Bad sequence of commands
			BAD_SEQUENCE_COMMANDS = 503,
			/// Command not implemented for that parameter
			COMMAND_NOT_IMPLEMENTED_FOR_PARAMETER = 504,
			/// Network protocol not supported
			NETWORK_PROTOCOL_NOT_SUPPORTED = 522,
			/// Not logged in
			NOT_LOGGED_IN = 530,
			/// Need account for storing files
			NEED_ACCOUNT_FOR_STORE_FILE = 532,
			/// Command protection level denied for policy reasons
			COMMAND_PROTECTION_DENIED = 533,
			/// Request denied for policy reasons
			REQUEST_DENIED = 534,
			/// Failed security check (hash, sequence, etc)
			FAILED_SEC_CHECK = 535,
			/// Requested PROT level not supported by mechanism
			REQ_PROT_LEVEL_NOT_SUPPORTED = 536,
			/// Command protection level not supported by security mechanism
			COMMAND_PROTECTION_LEVEL_NOT_SUPPORTED = 537,
			/// Requested action not taken: File unavailable
			FILE_UNAVAILABLE = 550,
			/// Requested action aborted: page type unknown
			PAGE_TYPE_UNKNOWN = 551,
			/// Requested file action aborted: Exceeded storage allocation
			EXCEED_STORAGE_ALLOCATION = 552,
			/// Requested action not taken: File name not allowed
			FILENAME_NOT_ALLOWED = 553,
			/// Integrity protected reply
			INTEGRITY_PROTECTED = 631,
			/// Confidentiality and integrity protected reply
			CONFIDENTIALITY_AND_INTEGRITY_PROTECTED = 632,
			/// Confidentiality protected reply
			CONFIDENTIALITY_PROTECTED = 633
		};

		/** A constructor that creates the layer from an existing packet raw data
		 * @param[in] data A pointer to the raw data
		 * @param[in] dataLen Size of the data in bytes
		 * @param[in] prevLayer A pointer to the previous layer
		 * @param[in] packet A pointer to the Packet instance where layer will be stored in
		 */
		FtpResponseLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet) : FtpLayer(data, dataLen, prevLayer, packet) {};

		/**
		 * A constructor that creates layer with provided input values
		 * @param[in] code Status code
		 * @param[in] option Argument of the status code
		 */
		explicit FtpResponseLayer(const FtpStatusCode &code, const std::string &option = "") : FtpLayer(std::to_string(int(code)), option) {};

		/**
		 * Set the status code of response message
		 * @param[in] code Value to set status code
		 * @return True if the operation is successful, false otherwise
		 */
		bool setStatusCode(FtpStatusCode code);

		/**
		 * Get the status code of response message
		 * @return FtpStatusCode Value of the status code
		 */
		FtpStatusCode getStatusCode() const;

		/**
		 * Get the status code of response message as string
		 * @return std::string Value of the status code as string
		 */
		std::string getStatusCodeString() const;

		/**
		 * Set the argument of response message
		 * @param[in] value Value to set argument
		 * @return True if the operation is successful, false otherwise
		 */
		bool setStatusOption(const std::string &value);

		/**
		 * Get the argument of response message
		 * @param[in] removeEscapeCharacters Whether non-alphanumerical characters should be removed or not
		 * @return std::string Value of argument
		 */
		std::string getStatusOption(bool removeEscapeCharacters = true) const;

		/**
		 * Convert the status code to readable string
		 * @param[in] code Status code to convert
		 * @return std::string Returns the status info as readable string
		 */
		static std::string getStatusCodeAsString(FtpStatusCode code);

		// overridden methods

		/**
		 * @return Returns the protocol info as readable string
		 */
		std::string toString() const;
	};

	/**
	 * Class for representing the data of FTP Layer
	 */
	class FtpDataLayer : public PayloadLayer
	{
	public:

		/** A constructor that creates the layer from an existing packet raw data
		 * @param[in] data A pointer to the raw data
		 * @param[in] dataLen Size of the data in bytes
		 * @param[in] prevLayer A pointer to the previous layer
		 * @param[in] packet A pointer to the Packet instance where layer will be stored in
		 */
		FtpDataLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet) : PayloadLayer(data, dataLen, prevLayer, packet) { m_Protocol = FTP; };

		/**
		 * @return Returns the protocol info as readable string
		 */
		std::string toString() const;
	};
} // namespace pcpp

#endif /* PACKETPP_FTP_LAYER */