PcapPlusPlus
Next
|
#include <Layer.h>
Public Member Functions | |
~Layer () override | |
Layer * | getNextLayer () const |
Layer * | getPrevLayer () const |
ProtocolType | getProtocol () const |
bool | isMemberOfProtocolFamily (ProtocolTypeFamily protocolTypeFamily) const |
uint8_t * | getData () const |
size_t | getDataLen () const |
uint8_t * | getLayerPayload () const |
size_t | getLayerPayloadSize () const |
bool | isAllocatedToPacket () const |
void | copyData (uint8_t *toArr) const |
uint8_t * | getDataPtr (size_t offset=0) const override |
virtual void | parseNextLayer ()=0 |
Each layer is responsible for parsing the next layer. | |
virtual size_t | getHeaderLen () const =0 |
virtual void | computeCalculateFields ()=0 |
Each layer can compute field values automatically using this method. This is an abstract method. | |
virtual std::string | toString () const =0 |
virtual OsiModelLayer | getOsiModelLayer () const =0 |
Protected Member Functions | |
template<typename T , typename... Args> | |
Layer * | constructNextLayer (uint8_t *data, size_t dataLen, Packet *packet, Args &&... extraArgs) |
template<typename T , typename TFallback , typename... Args> | |
Layer * | tryConstructNextLayerWithFallback (uint8_t *data, size_t dataLen, Packet *packet, Args &&... extraArgs) |
Static Protected Member Functions | |
template<typename T > | |
static bool | canReinterpretAs (const uint8_t *data, size_t dataLen) |
Check if the data is large enough to reinterpret as a type. More... | |
Layer is the base class for all protocol layers. Each protocol supported in PcapPlusPlus has a class that inherits Layer. The protocol layer class expose all properties and methods relevant for viewing and editing protocol fields. For example: a pointer to a structured header (e.g tcphdr, iphdr, etc.), protocol header size, payload size, compute fields that can be automatically computed, print protocol data to string, etc. Each protocol instance is obviously part of a protocol stack (which construct a packet). This protocol stack is represented in PcapPlusPlus in a linked list, and each layer is an element in this list. That's why each layer has properties to the next and previous layer in the protocol stack. The Layer class, as a base class, is abstract and the user can't create an instance of it (it has a private constructor). Each layer holds a pointer to the relevant place in the packet. The layer sees all the data from this pointer forward until the end of the packet. Here is an example packet showing this concept:
|
override |
A destructor for this class. Frees the data if it was allocated by the layer constructor (see isAllocatedToPacket() for more info)
|
inlinestaticprotected |
Check if the data is large enough to reinterpret as a type.
The data must be non-null and at least as large as the type
T | The type to reinterpret as |
data | The data to check |
dataLen | The length of the data |
|
inlineprotected |
Construct the next layer in the protocol stack. No validation is performed on the data.
T | The type of the layer to construct |
Args | The types of the arguments to pass to the layer constructor |
[in] | data | The data to construct the layer from |
[in] | dataLen | The length of the data |
[in] | packet | The packet the layer belongs to |
[in] | extraArgs | Extra arguments to be forwarded to the layer constructor |
void pcpp::Layer::copyData | ( | uint8_t * | toArr | ) | const |
Copy the raw data of this layer to another array
[out] | toArr | The destination byte array |
|
inline |
|
inline |
|
inlineoverridevirtual |
Get a pointer to the data
[in] | offset | Get a pointer in a certain offset. Default is 0 - get a pointer to start of data |
Implements pcpp::IDataContainer.
|
pure virtual |
Implemented in pcpp::WireGuardLayer, pcpp::WakeOnLanLayer, pcpp::VxlanLayer, pcpp::VrrpLayer, pcpp::VlanLayer, pcpp::UdpLayer, pcpp::TpktLayer, pcpp::TextBasedProtocolMessage, pcpp::TelnetLayer, pcpp::TcpLayer, pcpp::RapidStpLayer, pcpp::StpConfigurationBPDULayer, pcpp::StpTopologyChangeBPDULayer, pcpp::StpLayer, pcpp::SSLLayer, pcpp::SSHEncryptedMessage, pcpp::SSHHandshakeMessage, pcpp::SSHIdentificationMessage, pcpp::SomeIpLayer, pcpp::SmtpLayer, pcpp::SllLayer, pcpp::Sll2Layer, pcpp::S7CommLayer, pcpp::RadiusLayer, pcpp::PPPoEDiscoveryLayer, pcpp::PPPoESessionLayer, pcpp::PayloadLayer, pcpp::PacketTrailerLayer, pcpp::NullLoopbackLayer, pcpp::NtpLayer, pcpp::NflogLayer, pcpp::MplsLayer, pcpp::LLCLayer, pcpp::LdapLayer, pcpp::IPv6Layer, pcpp::IPv4Layer, pcpp::ESPLayer, pcpp::AuthenticationHeaderLayer, pcpp::IgmpV3ReportLayer, pcpp::IgmpV3QueryLayer, pcpp::IgmpLayer, pcpp::IcmpV6Layer, pcpp::IcmpLayer, pcpp::GtpV2Layer, pcpp::GtpV1Layer, pcpp::PPP_PPTPLayer, pcpp::GreLayer, pcpp::FtpLayer, pcpp::EthLayer, pcpp::EthDot3Layer, pcpp::DnsLayer, pcpp::DhcpV6Layer, pcpp::DhcpLayer, pcpp::CotpLayer, pcpp::CiscoHdlcLayer, pcpp::BgpLayer, and pcpp::ArpLayer.
|
inline |
|
inline |
|
inline |
|
pure virtual |
Implemented in pcpp::WireGuardLayer, pcpp::WakeOnLanLayer, pcpp::VxlanLayer, pcpp::VrrpLayer, pcpp::VlanLayer, pcpp::UdpLayer, pcpp::TpktLayer, pcpp::TelnetLayer, pcpp::TcpLayer, pcpp::StpLayer, pcpp::SSLLayer, pcpp::SSHLayer, pcpp::SomeIpLayer, pcpp::SmtpLayer, pcpp::SllLayer, pcpp::Sll2Layer, pcpp::SipLayer, pcpp::SdpLayer, pcpp::S7CommLayer, pcpp::RadiusLayer, pcpp::PPPoELayer, pcpp::PayloadLayer, pcpp::PacketTrailerLayer, pcpp::NullLoopbackLayer, pcpp::NtpLayer, pcpp::NflogLayer, pcpp::MplsLayer, pcpp::LLCLayer, pcpp::LdapLayer, pcpp::IPv6Layer, pcpp::IPv4Layer, pcpp::ESPLayer, pcpp::AuthenticationHeaderLayer, pcpp::IgmpLayer, pcpp::IcmpV6Layer, pcpp::IcmpLayer, pcpp::HttpMessage, pcpp::GtpV2Layer, pcpp::GtpV1Layer, pcpp::PPP_PPTPLayer, pcpp::GreLayer, pcpp::FtpLayer, pcpp::EthLayer, pcpp::EthDot3Layer, pcpp::DnsLayer, pcpp::DhcpV6Layer, pcpp::DhcpLayer, pcpp::CotpLayer, pcpp::CiscoHdlcLayer, pcpp::BgpLayer, and pcpp::ArpLayer.
|
inline |
|
inline |
|
inline |
Raw data in layers can come from one of sources:
bool pcpp::Layer::isMemberOfProtocolFamily | ( | ProtocolTypeFamily | protocolTypeFamily | ) | const |
Check if the layer's protocol matches a protocol family
protocolTypeFamily | The protocol family to check |
|
pure virtual |
Implemented in pcpp::WireGuardLayer, pcpp::WakeOnLanLayer, pcpp::VxlanLayer, pcpp::VrrpLayer, pcpp::VlanLayer, pcpp::UdpLayer, pcpp::TpktLayer, pcpp::TelnetLayer, pcpp::TcpLayer, pcpp::MultipleStpLayer, pcpp::RapidStpLayer, pcpp::StpConfigurationBPDULayer, pcpp::StpTopologyChangeBPDULayer, pcpp::SSLApplicationDataLayer, pcpp::SSLAlertLayer, pcpp::SSLChangeCipherSpecLayer, pcpp::SSLHandshakeLayer, pcpp::SSHEncryptedMessage, pcpp::SSHHandshakeMessage, pcpp::SSHIdentificationMessage, pcpp::SomeIpSdLayer, pcpp::SomeIpTpLayer, pcpp::SomeIpLayer, pcpp::SmtpResponseLayer, pcpp::SmtpRequestLayer, pcpp::SllLayer, pcpp::Sll2Layer, pcpp::SipResponseLayer, pcpp::SipRequestLayer, pcpp::SdpLayer, pcpp::S7CommLayer, pcpp::RadiusLayer, pcpp::PPPoEDiscoveryLayer, pcpp::PPPoESessionLayer, pcpp::PayloadLayer, pcpp::PacketTrailerLayer, pcpp::NullLoopbackLayer, pcpp::NtpLayer, pcpp::NflogLayer, pcpp::NDPNeighborAdvertisementLayer, pcpp::NDPNeighborSolicitationLayer, pcpp::MplsLayer, pcpp::LLCLayer, pcpp::LdapLayer, pcpp::IPv6Layer, pcpp::IPv4Layer, pcpp::ESPLayer, pcpp::AuthenticationHeaderLayer, pcpp::IgmpLayer, pcpp::ICMPv6EchoLayer, pcpp::IcmpV6Layer, pcpp::IcmpLayer, pcpp::HttpResponseLayer, pcpp::HttpRequestLayer, pcpp::GtpV2Layer, pcpp::GtpV1Layer, pcpp::PPP_PPTPLayer, pcpp::GREv1Layer, pcpp::GREv0Layer, pcpp::FtpDataLayer, pcpp::FtpResponseLayer, pcpp::FtpRequestLayer, pcpp::EthLayer, pcpp::EthDot3Layer, pcpp::DnsLayer, pcpp::DhcpV6Layer, pcpp::DhcpLayer, pcpp::CotpLayer, pcpp::CiscoHdlcLayer, pcpp::BgpLayer, and pcpp::ArpLayer.
|
inlineprotected |
Try to construct the next layer in the protocol stack with a fallback option.
The method checks if the data is valid for the layer type T before constructing it by calling T::isDataValid(data, dataLen). If the data is invalid, it constructs the layer of type TFallback.
T | The type of the layer to construct |
TFallback | The fallback layer type to construct if T fails |
Args | The types of the extra arguments to pass to the layer constructor of T |
[in] | data | The data to construct the layer from |
[in] | dataLen | The length of the data |
[in] | packet | The packet the layer belongs to |
[in] | extraArgs | Extra arguments to be forwarded to the layer constructor of T |