Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Packet++/header/FtpLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ namespace pcpp
{
protected:
FtpLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
: SingleCommandTextProtocol(data, dataLen, prevLayer, packet, FTP) {};
: SingleCommandTextProtocol(data, dataLen, prevLayer, packet, FTPControl) {};
FtpLayer(const std::string& command, const std::string& option)
: SingleCommandTextProtocol(command, option, FTP) {};
: SingleCommandTextProtocol(command, option, FTPControl) {};

public:
/// A static method that checks whether the port is considered as FTP control
Expand Down Expand Up @@ -447,7 +447,7 @@ namespace pcpp
FtpDataLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
: PayloadLayer(data, dataLen, prevLayer, packet)
{
m_Protocol = FTP;
m_Protocol = FTPData;
};

/// @return Returns the protocol info as readable string
Expand Down
10 changes: 8 additions & 2 deletions Packet++/header/ProtocolType.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ namespace pcpp
/// Telnet Protocol
const ProtocolType Telnet = 40;

/// File Transfer (FTP) Protocol
const ProtocolType FTP = 41;
/// File Transfer (FTP) Protocol - Control channel
const ProtocolType FTPControl = 41;

/// ICMPv6 protocol
const ProtocolType ICMPv6 = 42;
Expand Down Expand Up @@ -223,6 +223,12 @@ namespace pcpp
/// Diagnostic over IP protocol (DOIP)
const ProtocolType DOIP = 59;

/// File Transfer Protocol (FTP) Data channel
const ProtocolType FTPData = 60;

/// FTP protocol family (FTPControl and FtpData protocols)
const ProtocolTypeFamily FTP = 0x3c29;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why FTP value is 0x3c29?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It follows the convention for other protocol family packs.

Hex 3c = Dec 60 = FTPData
Hex 29 = Dec 41 = FTPControl

A single protocol value is 8 bits, while a family is 32 bits packed 4x 8 bit protocol type values. Essentially being (protocol1, protocol2, protocol3, protocol4).

The public API takes 32-bit family packs, so if a single protocol is passed, the value gets zero extended to (unknown protocol, unknown protocol, unknown protocol, protocol value).

Ideally, I would have this done with structs and constepxr construction, but we need cpp17 for that to work alongside the current usages inside switch cases. Until then, hard coded magic values it is.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow... TBH it's a little hard to get the idea just from the source code. Could you add the comment in the code, thanks!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Sure I can try to add documentation on how it works. Will be in a different PR tho.


/// An enum representing OSI model layers
enum OsiModelLayer
{
Expand Down
Loading