/src/PcapPlusPlus/Packet++/header/Layer.h
Line | Count | Source |
1 | | #pragma once |
2 | | |
3 | | #include <stdint.h> |
4 | | #include <stdio.h> |
5 | | #include "ProtocolType.h" |
6 | | #include <string> |
7 | | #include <stdexcept> |
8 | | #include <utility> |
9 | | |
10 | | /// @file |
11 | | |
12 | | /// @namespace pcpp |
13 | | /// @brief The main namespace for the PcapPlusPlus lib |
14 | | namespace pcpp |
15 | | { |
16 | | |
17 | | /// @class IDataContainer |
18 | | /// An interface (virtual abstract class) that indicates an object that holds a pointer to a buffer data. The Layer |
19 | | /// class is an example of such object, hence it inherits this interface |
20 | | class IDataContainer |
21 | | { |
22 | | public: |
23 | | /// Get a pointer to the data |
24 | | /// @param[in] offset Get a pointer in a certain offset. Default is 0 - get a pointer to start of data |
25 | | /// @return A pointer to the data |
26 | | virtual uint8_t* getDataPtr(size_t offset = 0) const = 0; |
27 | | |
28 | 5.00M | virtual ~IDataContainer() = default; |
29 | | }; |
30 | | |
31 | | class Packet; |
32 | | |
33 | | namespace internal |
34 | | { |
35 | | /// @brief Holds information about a Layer's data and object ownership. |
36 | | struct LayerAllocationInfo |
37 | | { |
38 | | /// @brief Pointer to the Packet this layer is attached to (if any). |
39 | | /// |
40 | | /// If the layer is attached to a Packet, the layer's memory span (data) is considered managed by the |
41 | | /// Packet. The Packet is responsible for keeping the layer's memory span valid and updating it should it |
42 | | /// become necessary as long as the layer is attached to it. |
43 | | /// |
44 | | /// In an event the Packet is destroyed, all of its attached layers's memory views are considered invalid. |
45 | | /// Accessing layer data after the Packet is destroyed results in undefined behavior. |
46 | | /// |
47 | | /// If nullptr, the layer is not attached to any Packet and is considered unmanaged. |
48 | | /// It also means the layer's memory span is considered owned by the layer itself and will be freed when |
49 | | /// the layer is destroyed. |
50 | | Packet* attachedPacket = nullptr; |
51 | | |
52 | | /// @brief Controls if the layer object is considered owned by the attached Packet |
53 | | /// |
54 | | /// If 'true', the Layer object is considered owned by the attached Packet and will be freed by it on Packet |
55 | | /// destruction. |
56 | | /// |
57 | | /// If 'false', the Layer object is considered unmanaged and the user is responsible for freeing it. |
58 | | /// This is commonly the case for layers created on the stack and attached to a Packet. |
59 | | bool ownedByPacket = false; |
60 | | |
61 | | /// @brief Sets the state of attachment to a specified Packet |
62 | | /// @param packet Pointer to the Packet this layer is attached to (or nullptr if not attached to any Packet) |
63 | | /// @param managed True if the layer object's lifetime is to be managed by the Packet, false otherwise |
64 | | /// @param force If true, bypasses the check for existing attachment. Default is false. |
65 | | /// @throws std::runtime_error if the layer is already attached to a Packet and 'force' is false |
66 | | void attachPacket(Packet* packet, bool managed, bool force = false) |
67 | 0 | { |
68 | 0 | if (!force && attachedPacket != nullptr) |
69 | 0 | { |
70 | 0 | throw std::runtime_error("Layer is already attached to a Packet"); |
71 | 0 | } |
72 | 0 |
|
73 | 0 | attachedPacket = packet; |
74 | 0 | ownedByPacket = managed; |
75 | 0 | } |
76 | | |
77 | | /// @brief Clears the attachment to any Packet, resetting to unmanaged state. |
78 | | void detach() |
79 | 0 | { |
80 | 0 | attachedPacket = nullptr; |
81 | 0 | ownedByPacket = false; |
82 | 0 | } |
83 | | }; |
84 | | } // namespace internal |
85 | | |
86 | | /// @class Layer |
87 | | /// Layer is the base class for all protocol layers. Each protocol supported in PcapPlusPlus has a class that |
88 | | /// inherits Layer. |
89 | | /// The protocol layer class expose all properties and methods relevant for viewing and editing protocol fields. |
90 | | /// For example: a pointer to a structured header (e.g tcphdr, iphdr, etc.), protocol header size, payload size, |
91 | | /// compute fields that can be automatically computed, print protocol data to string, etc. |
92 | | /// Each protocol instance is obviously part of a protocol stack (which construct a packet). This protocol stack is |
93 | | /// represented in PcapPlusPlus in a linked list, and each layer is an element in this list. That's why each layer |
94 | | /// has properties to the next and previous layer in the protocol stack. The Layer class, as a base class, is |
95 | | /// abstract and the user can't create an instance of it (it has a private constructor). Each layer holds a pointer |
96 | | /// to the relevant place in the packet. The layer sees all the data from this pointer forward until the end of the |
97 | | /// packet. Here is an example packet showing this concept: |
98 | | /// |
99 | | /// @code{.unparsed} |
100 | | /// ==================================================== |
101 | | /// |Eth |IPv4 |TCP |Packet | |
102 | | /// |Header |Header |Header |Payload | |
103 | | /// ==================================================== |
104 | | /// |
105 | | /// |--------------------------------------------------| |
106 | | /// EthLayer data |
107 | | /// |---------------------------------------| |
108 | | /// IPv4Layer data |
109 | | /// |---------------------------| |
110 | | /// TcpLayer data |
111 | | /// |----------------| |
112 | | /// PayloadLayer data |
113 | | /// @endcode |
114 | | class Layer : public IDataContainer |
115 | | { |
116 | | friend class Packet; |
117 | | |
118 | | public: |
119 | | /// A destructor for this class. Frees the data if it was allocated by the layer constructor (see |
120 | | /// isAllocatedToPacket() for more info) |
121 | | ~Layer() override; |
122 | | |
123 | | /// @return A pointer to the next layer in the protocol stack or nullptr if the layer is the last one |
124 | | Layer* getNextLayer() const |
125 | 94.8M | { |
126 | 94.8M | return m_NextLayer; |
127 | 94.8M | } |
128 | | |
129 | | /// @return A pointer to the previous layer in the protocol stack or nullptr if the layer is the first one |
130 | | Layer* getPrevLayer() const |
131 | 2.16M | { |
132 | 2.16M | return m_PrevLayer; |
133 | 2.16M | } |
134 | | |
135 | | /// @return The protocol enum |
136 | | ProtocolType getProtocol() const |
137 | 67.8M | { |
138 | 67.8M | return m_Protocol; |
139 | 67.8M | } |
140 | | |
141 | | /// Check if the layer's protocol matches a protocol family |
142 | | /// @param protocolTypeFamily The protocol family to check |
143 | | /// @return True if the layer's protocol matches the protocol family, false otherwise |
144 | | bool isMemberOfProtocolFamily(ProtocolTypeFamily protocolTypeFamily) const; |
145 | | |
146 | | /// @return A pointer to the layer raw data. In most cases it'll be a pointer to the first byte of the header |
147 | | uint8_t* getData() const |
148 | 317k | { |
149 | 317k | return m_Data; |
150 | 317k | } |
151 | | |
152 | | /// @return The length in bytes of the data from the first byte of the header until the end of the packet |
153 | | size_t getDataLen() const |
154 | 3.32M | { |
155 | 3.32M | return m_DataLen; |
156 | 3.32M | } |
157 | | |
158 | | /// @return A pointer for the layer payload, meaning the first byte after the header |
159 | | uint8_t* getLayerPayload() const |
160 | 0 | { |
161 | 0 | return m_Data + getHeaderLen(); |
162 | 0 | } |
163 | | |
164 | | /// @return The size in bytes of the payload |
165 | | size_t getLayerPayloadSize() const |
166 | 65.8k | { |
167 | 65.8k | return m_DataLen - getHeaderLen(); |
168 | 65.8k | } |
169 | | |
170 | | /// Raw data in layers can come from one of sources: |
171 | | /// 1. from an existing packet - this is the case when parsing packets received from files or the network. In |
172 | | /// this case the data was already allocated by someone else, and layer only holds the pointer to the relevant |
173 | | /// place inside this data |
174 | | /// 2. when creating packets, data is allocated when layer is created. In this case the layer is responsible for |
175 | | /// freeing it as well |
176 | | /// |
177 | | /// @return Returns true if the data was allocated by an external source (a packet) or false if it was allocated |
178 | | /// by the layer itself |
179 | | bool isAllocatedToPacket() const |
180 | 5.00M | { |
181 | 5.00M | return m_AllocationInfo.attachedPacket != nullptr; |
182 | 5.00M | } |
183 | | |
184 | | /// Copy the raw data of this layer to another array |
185 | | /// @param[out] toArr The destination byte array |
186 | | void copyData(uint8_t* toArr) const; |
187 | | |
188 | | // implement abstract methods |
189 | | |
190 | | uint8_t* getDataPtr(size_t offset = 0) const override |
191 | 118k | { |
192 | 118k | return static_cast<uint8_t*>(m_Data + offset); |
193 | 118k | } |
194 | | |
195 | | // abstract methods |
196 | | |
197 | | /// Each layer is responsible for parsing the next layer |
198 | | virtual void parseNextLayer() = 0; |
199 | | |
200 | | /// @return The header length in bytes |
201 | | virtual size_t getHeaderLen() const = 0; |
202 | | |
203 | | /// Each layer can compute field values automatically using this method. This is an abstract method |
204 | | virtual void computeCalculateFields() = 0; |
205 | | |
206 | | /// @return A string representation of the layer most important data (should look like the layer description in |
207 | | /// Wireshark) |
208 | | virtual std::string toString() const = 0; |
209 | | |
210 | | /// @return The OSI Model layer this protocol belongs to |
211 | | virtual OsiModelLayer getOsiModelLayer() const = 0; |
212 | | |
213 | | protected: |
214 | | uint8_t* m_Data; |
215 | | size_t m_DataLen; |
216 | | ProtocolType m_Protocol; |
217 | | Layer* m_NextLayer; |
218 | | Layer* m_PrevLayer; |
219 | | |
220 | | private: |
221 | | internal::LayerAllocationInfo m_AllocationInfo; |
222 | | |
223 | | protected: |
224 | | Layer() : m_Data(nullptr), m_DataLen(0), m_Protocol(UnknownProtocol), m_NextLayer(nullptr), m_PrevLayer(nullptr) |
225 | 0 | {} |
226 | | |
227 | | Layer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet, ProtocolType protocol = UnknownProtocol) |
228 | 4.87M | : m_Data(data), m_DataLen(dataLen), m_Protocol(protocol), m_NextLayer(nullptr), m_PrevLayer(prevLayer), |
229 | 4.87M | m_AllocationInfo{ packet, false } |
230 | 4.87M | {} |
231 | | |
232 | | // Copy c'tor |
233 | | Layer(const Layer& other); |
234 | | Layer& operator=(const Layer& other); |
235 | | |
236 | | /// @brief Get a pointer to the Packet this layer is attached to (if any). |
237 | | /// @return A pointer to the Packet this layer is attached to, or nullptr if the layer is not attached. |
238 | | Packet* getAttachedPacket() |
239 | 4.84M | { |
240 | 4.84M | return m_AllocationInfo.attachedPacket; |
241 | 4.84M | } |
242 | | |
243 | | /// @brief Get a pointer to the Packet this layer is attached to (if any). |
244 | | /// @return A const pointer to the Packet this layer is attached to, or nullptr if the layer is not attached. |
245 | | Packet const* getAttachedPacket() const |
246 | 3.10k | { |
247 | 3.10k | return m_AllocationInfo.attachedPacket; |
248 | 3.10k | } |
249 | | |
250 | | void setNextLayer(Layer* nextLayer) |
251 | 3.92M | { |
252 | 3.92M | m_NextLayer = nextLayer; |
253 | 3.92M | } |
254 | | void setPrevLayer(Layer* prevLayer) |
255 | 0 | { |
256 | 0 | m_PrevLayer = prevLayer; |
257 | 0 | } |
258 | | |
259 | | virtual bool extendLayer(int offsetInLayer, size_t numOfBytesToExtend); |
260 | | virtual bool shortenLayer(int offsetInLayer, size_t numOfBytesToShorten); |
261 | | |
262 | | bool hasNextLayer() const |
263 | 6.89M | { |
264 | 6.89M | return m_NextLayer != nullptr; |
265 | 6.89M | } |
266 | | |
267 | | /// @brief Construct the next layer in the protocol stack. No validation is performed on the data. |
268 | | /// |
269 | | /// This overload infers the Packet from the current layer. |
270 | | /// |
271 | | /// @tparam T The type of the layer to construct |
272 | | /// @tparam Args The types of the arguments to pass to the layer constructor |
273 | | /// @param data The data to construct the layer from |
274 | | /// @param dataLen The length of the data |
275 | | /// @param extraArgs Extra arguments to be forwarded to the layer constructor |
276 | | /// @return The constructed layer |
277 | | template <typename T, typename... Args> |
278 | | Layer* constructNextLayer(uint8_t* data, size_t dataLen, Args&&... extraArgs) |
279 | 345k | { |
280 | 345k | return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...); |
281 | 345k | } pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::VlanLayer>(unsigned char*, unsigned long) Line | Count | Source | 279 | 53.5k | { | 280 | 53.5k | return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...); | 281 | 53.5k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::MplsLayer>(unsigned char*, unsigned long) Line | Count | Source | 279 | 3.99k | { | 280 | 3.99k | return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...); | 281 | 3.99k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::PayloadLayer>(unsigned char*, unsigned long) Line | Count | Source | 279 | 103k | { | 280 | 103k | return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...); | 281 | 103k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::VrrpV3Layer, pcpp::IPAddress::AddressType>(unsigned char*, unsigned long, pcpp::IPAddress::AddressType&&) Line | Count | Source | 279 | 4.27k | { | 280 | 4.27k | return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...); | 281 | 4.27k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::ArpLayer>(unsigned char*, unsigned long) Line | Count | Source | 279 | 1.87k | { | 280 | 1.87k | return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...); | 281 | 1.87k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::DnsLayer>(unsigned char*, unsigned long) Line | Count | Source | 279 | 58.3k | { | 280 | 58.3k | return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...); | 281 | 58.3k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::RadiusLayer>(unsigned char*, unsigned long) Line | Count | Source | 279 | 12.6k | { | 280 | 12.6k | return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...); | 281 | 12.6k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::GtpV1Layer>(unsigned char*, unsigned long) Line | Count | Source | 279 | 32.0k | { | 280 | 32.0k | return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...); | 281 | 32.0k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::GtpV2Layer>(unsigned char*, unsigned long) Line | Count | Source | 279 | 6 | { | 280 | 6 | return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...); | 281 | 6 | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::DhcpV6Layer>(unsigned char*, unsigned long) Line | Count | Source | 279 | 19.7k | { | 280 | 19.7k | return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...); | 281 | 19.7k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::NtpLayer>(unsigned char*, unsigned long) Line | Count | Source | 279 | 16.7k | { | 280 | 16.7k | return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...); | 281 | 16.7k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::WakeOnLanLayer>(unsigned char*, unsigned long) Line | Count | Source | 279 | 500 | { | 280 | 500 | return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...); | 281 | 500 | } |
Unexecuted instantiation: pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::EthLayer>(unsigned char*, unsigned long) pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::SdpLayer>(unsigned char*, unsigned long) Line | Count | Source | 279 | 38.4k | { | 280 | 38.4k | return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...); | 281 | 38.4k | } |
|
282 | | |
283 | | /// Construct the next layer in the protocol stack. No validation is performed on the data. |
284 | | /// @tparam T The type of the layer to construct |
285 | | /// @tparam Args The types of the arguments to pass to the layer constructor |
286 | | /// @param[in] data The data to construct the layer from |
287 | | /// @param[in] dataLen The length of the data |
288 | | /// @param[in] packet The packet the layer belongs to |
289 | | /// @param[in] extraArgs Extra arguments to be forwarded to the layer constructor |
290 | | /// @return The constructed layer |
291 | | template <typename T, typename... Args> |
292 | | Layer* constructNextLayer(uint8_t* data, size_t dataLen, Packet* packet, Args&&... extraArgs) |
293 | 3.12M | { |
294 | 3.12M | if (hasNextLayer()) |
295 | 0 | { |
296 | 0 | throw std::runtime_error("Next layer already exists"); |
297 | 0 | } |
298 | | |
299 | 3.12M | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); |
300 | 3.12M | setNextLayer(newLayer); |
301 | 3.12M | return newLayer; |
302 | 3.12M | } pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::IPv4Layer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 293 | 929k | { | 294 | 929k | if (hasNextLayer()) | 295 | 0 | { | 296 | 0 | throw std::runtime_error("Next layer already exists"); | 297 | 0 | } | 298 | | | 299 | 929k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 300 | 929k | setNextLayer(newLayer); | 301 | 929k | return newLayer; | 302 | 929k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 293 | 302k | { | 294 | 302k | if (hasNextLayer()) | 295 | 0 | { | 296 | 0 | throw std::runtime_error("Next layer already exists"); | 297 | 0 | } | 298 | | | 299 | 302k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 300 | 302k | setNextLayer(newLayer); | 301 | 302k | return newLayer; | 302 | 302k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::IPv6Layer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 293 | 164k | { | 294 | 164k | if (hasNextLayer()) | 295 | 0 | { | 296 | 0 | throw std::runtime_error("Next layer already exists"); | 297 | 0 | } | 298 | | | 299 | 164k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 300 | 164k | setNextLayer(newLayer); | 301 | 164k | return newLayer; | 302 | 164k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::VlanLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 293 | 208k | { | 294 | 208k | if (hasNextLayer()) | 295 | 0 | { | 296 | 0 | throw std::runtime_error("Next layer already exists"); | 297 | 0 | } | 298 | | | 299 | 208k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 300 | 208k | setNextLayer(newLayer); | 301 | 208k | return newLayer; | 302 | 208k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::MplsLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 293 | 3.99k | { | 294 | 3.99k | if (hasNextLayer()) | 295 | 0 | { | 296 | 0 | throw std::runtime_error("Next layer already exists"); | 297 | 0 | } | 298 | | | 299 | 3.99k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 300 | 3.99k | setNextLayer(newLayer); | 301 | 3.99k | return newLayer; | 302 | 3.99k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::PPP_PPTPLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 293 | 67.4k | { | 294 | 67.4k | if (hasNextLayer()) | 295 | 0 | { | 296 | 0 | throw std::runtime_error("Next layer already exists"); | 297 | 0 | } | 298 | | | 299 | 67.4k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 300 | 67.4k | setNextLayer(newLayer); | 301 | 67.4k | return newLayer; | 302 | 67.4k | } |
Unexecuted instantiation: pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::EthLayer>(unsigned char*, unsigned long, pcpp::Packet*) Unexecuted instantiation: pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::EthDot3Layer>(unsigned char*, unsigned long, pcpp::Packet*) pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::GtpV2Layer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 293 | 6 | { | 294 | 6 | if (hasNextLayer()) | 295 | 0 | { | 296 | 0 | throw std::runtime_error("Next layer already exists"); | 297 | 0 | } | 298 | | | 299 | 6 | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 300 | 6 | setNextLayer(newLayer); | 301 | 6 | return newLayer; | 302 | 6 | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::UdpLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 293 | 363k | { | 294 | 363k | if (hasNextLayer()) | 295 | 0 | { | 296 | 0 | throw std::runtime_error("Next layer already exists"); | 297 | 0 | } | 298 | | | 299 | 363k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 300 | 363k | setNextLayer(newLayer); | 301 | 363k | return newLayer; | 302 | 363k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::TcpLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 293 | 525k | { | 294 | 525k | if (hasNextLayer()) | 295 | 0 | { | 296 | 0 | throw std::runtime_error("Next layer already exists"); | 297 | 0 | } | 298 | | | 299 | 525k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 300 | 525k | setNextLayer(newLayer); | 301 | 525k | return newLayer; | 302 | 525k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::IcmpLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 293 | 41.6k | { | 294 | 41.6k | if (hasNextLayer()) | 295 | 0 | { | 296 | 0 | throw std::runtime_error("Next layer already exists"); | 297 | 0 | } | 298 | | | 299 | 41.6k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 300 | 41.6k | setNextLayer(newLayer); | 301 | 41.6k | return newLayer; | 302 | 41.6k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::GREv0Layer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 293 | 10.0k | { | 294 | 10.0k | if (hasNextLayer()) | 295 | 0 | { | 296 | 0 | throw std::runtime_error("Next layer already exists"); | 297 | 0 | } | 298 | | | 299 | 10.0k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 300 | 10.0k | setNextLayer(newLayer); | 301 | 10.0k | return newLayer; | 302 | 10.0k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::GREv1Layer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 293 | 75.1k | { | 294 | 75.1k | if (hasNextLayer()) | 295 | 0 | { | 296 | 0 | throw std::runtime_error("Next layer already exists"); | 297 | 0 | } | 298 | | | 299 | 75.1k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 300 | 75.1k | setNextLayer(newLayer); | 301 | 75.1k | return newLayer; | 302 | 75.1k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::IgmpV1Layer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 293 | 3.13k | { | 294 | 3.13k | if (hasNextLayer()) | 295 | 0 | { | 296 | 0 | throw std::runtime_error("Next layer already exists"); | 297 | 0 | } | 298 | | | 299 | 3.13k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 300 | 3.13k | setNextLayer(newLayer); | 301 | 3.13k | return newLayer; | 302 | 3.13k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::IgmpV2Layer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 293 | 7.73k | { | 294 | 7.73k | if (hasNextLayer()) | 295 | 0 | { | 296 | 0 | throw std::runtime_error("Next layer already exists"); | 297 | 0 | } | 298 | | | 299 | 7.73k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 300 | 7.73k | setNextLayer(newLayer); | 301 | 7.73k | return newLayer; | 302 | 7.73k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::IgmpV3QueryLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 293 | 1.71k | { | 294 | 1.71k | if (hasNextLayer()) | 295 | 0 | { | 296 | 0 | throw std::runtime_error("Next layer already exists"); | 297 | 0 | } | 298 | | | 299 | 1.71k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 300 | 1.71k | setNextLayer(newLayer); | 301 | 1.71k | return newLayer; | 302 | 1.71k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::IgmpV3ReportLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 293 | 2.23k | { | 294 | 2.23k | if (hasNextLayer()) | 295 | 0 | { | 296 | 0 | throw std::runtime_error("Next layer already exists"); | 297 | 0 | } | 298 | | | 299 | 2.23k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 300 | 2.23k | setNextLayer(newLayer); | 301 | 2.23k | return newLayer; | 302 | 2.23k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::AuthenticationHeaderLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 293 | 5.19k | { | 294 | 5.19k | if (hasNextLayer()) | 295 | 0 | { | 296 | 0 | throw std::runtime_error("Next layer already exists"); | 297 | 0 | } | 298 | | | 299 | 5.19k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 300 | 5.19k | setNextLayer(newLayer); | 301 | 5.19k | return newLayer; | 302 | 5.19k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::ESPLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 293 | 6.70k | { | 294 | 6.70k | if (hasNextLayer()) | 295 | 0 | { | 296 | 0 | throw std::runtime_error("Next layer already exists"); | 297 | 0 | } | 298 | | | 299 | 6.70k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 300 | 6.70k | setNextLayer(newLayer); | 301 | 6.70k | return newLayer; | 302 | 6.70k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::VrrpV2Layer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 293 | 3.98k | { | 294 | 3.98k | if (hasNextLayer()) | 295 | 0 | { | 296 | 0 | throw std::runtime_error("Next layer already exists"); | 297 | 0 | } | 298 | | | 299 | 3.98k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 300 | 3.98k | setNextLayer(newLayer); | 301 | 3.98k | return newLayer; | 302 | 3.98k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::VrrpV3Layer, pcpp::IPAddress::AddressType>(unsigned char*, unsigned long, pcpp::Packet*, pcpp::IPAddress::AddressType&&) Line | Count | Source | 293 | 7.51k | { | 294 | 7.51k | if (hasNextLayer()) | 295 | 0 | { | 296 | 0 | throw std::runtime_error("Next layer already exists"); | 297 | 0 | } | 298 | | | 299 | 7.51k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 300 | 7.51k | setNextLayer(newLayer); | 301 | 7.51k | return newLayer; | 302 | 7.51k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::ArpLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 293 | 5.26k | { | 294 | 5.26k | if (hasNextLayer()) | 295 | 0 | { | 296 | 0 | throw std::runtime_error("Next layer already exists"); | 297 | 0 | } | 298 | | | 299 | 5.26k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 300 | 5.26k | setNextLayer(newLayer); | 301 | 5.26k | return newLayer; | 302 | 5.26k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::PPPoESessionLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 293 | 42.1k | { | 294 | 42.1k | if (hasNextLayer()) | 295 | 0 | { | 296 | 0 | throw std::runtime_error("Next layer already exists"); | 297 | 0 | } | 298 | | | 299 | 42.1k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 300 | 42.1k | setNextLayer(newLayer); | 301 | 42.1k | return newLayer; | 302 | 42.1k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::PPPoEDiscoveryLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 293 | 227 | { | 294 | 227 | if (hasNextLayer()) | 295 | 0 | { | 296 | 0 | throw std::runtime_error("Next layer already exists"); | 297 | 0 | } | 298 | | | 299 | 227 | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 300 | 227 | setNextLayer(newLayer); | 301 | 227 | return newLayer; | 302 | 227 | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::HttpRequestLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 293 | 6.18k | { | 294 | 6.18k | if (hasNextLayer()) | 295 | 0 | { | 296 | 0 | throw std::runtime_error("Next layer already exists"); | 297 | 0 | } | 298 | | | 299 | 6.18k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 300 | 6.18k | setNextLayer(newLayer); | 301 | 6.18k | return newLayer; | 302 | 6.18k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::HttpResponseLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 293 | 13.9k | { | 294 | 13.9k | if (hasNextLayer()) | 295 | 0 | { | 296 | 0 | throw std::runtime_error("Next layer already exists"); | 297 | 0 | } | 298 | | | 299 | 13.9k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 300 | 13.9k | setNextLayer(newLayer); | 301 | 13.9k | return newLayer; | 302 | 13.9k | } |
Unexecuted instantiation: pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::SipRequestLayer>(unsigned char*, unsigned long, pcpp::Packet*) Unexecuted instantiation: pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::SipResponseLayer>(unsigned char*, unsigned long, pcpp::Packet*) pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::DnsOverTcpLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 293 | 21.9k | { | 294 | 21.9k | if (hasNextLayer()) | 295 | 0 | { | 296 | 0 | throw std::runtime_error("Next layer already exists"); | 297 | 0 | } | 298 | | | 299 | 21.9k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 300 | 21.9k | setNextLayer(newLayer); | 301 | 21.9k | return newLayer; | 302 | 21.9k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::TelnetLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 293 | 49.4k | { | 294 | 49.4k | if (hasNextLayer()) | 295 | 0 | { | 296 | 0 | throw std::runtime_error("Next layer already exists"); | 297 | 0 | } | 298 | | | 299 | 49.4k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 300 | 49.4k | setNextLayer(newLayer); | 301 | 49.4k | return newLayer; | 302 | 49.4k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::FtpResponseLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 293 | 8.69k | { | 294 | 8.69k | if (hasNextLayer()) | 295 | 0 | { | 296 | 0 | throw std::runtime_error("Next layer already exists"); | 297 | 0 | } | 298 | | | 299 | 8.69k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 300 | 8.69k | setNextLayer(newLayer); | 301 | 8.69k | return newLayer; | 302 | 8.69k | } |
Unexecuted instantiation: pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::FtpRequestLayer>(unsigned char*, unsigned long, pcpp::Packet*) pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::FtpDataLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 293 | 2.95k | { | 294 | 2.95k | if (hasNextLayer()) | 295 | 0 | { | 296 | 0 | throw std::runtime_error("Next layer already exists"); | 297 | 0 | } | 298 | | | 299 | 2.95k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 300 | 2.95k | setNextLayer(newLayer); | 301 | 2.95k | return newLayer; | 302 | 2.95k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::TpktLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 293 | 17.1k | { | 294 | 17.1k | if (hasNextLayer()) | 295 | 0 | { | 296 | 0 | throw std::runtime_error("Next layer already exists"); | 297 | 0 | } | 298 | | | 299 | 17.1k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 300 | 17.1k | setNextLayer(newLayer); | 301 | 17.1k | return newLayer; | 302 | 17.1k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::SmtpResponseLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 293 | 76 | { | 294 | 76 | if (hasNextLayer()) | 295 | 0 | { | 296 | 0 | throw std::runtime_error("Next layer already exists"); | 297 | 0 | } | 298 | | | 299 | 76 | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 300 | 76 | setNextLayer(newLayer); | 301 | 76 | return newLayer; | 302 | 76 | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::SmtpRequestLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 293 | 190 | { | 294 | 190 | if (hasNextLayer()) | 295 | 0 | { | 296 | 0 | throw std::runtime_error("Next layer already exists"); | 297 | 0 | } | 298 | | | 299 | 190 | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 300 | 190 | setNextLayer(newLayer); | 301 | 190 | return newLayer; | 302 | 190 | } |
Unexecuted instantiation: pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::ModbusLayer>(unsigned char*, unsigned long, pcpp::Packet*) pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::CotpLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 293 | 13.2k | { | 294 | 13.2k | if (hasNextLayer()) | 295 | 0 | { | 296 | 0 | throw std::runtime_error("Next layer already exists"); | 297 | 0 | } | 298 | | | 299 | 13.2k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 300 | 13.2k | setNextLayer(newLayer); | 301 | 13.2k | return newLayer; | 302 | 13.2k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::DhcpLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 293 | 15.1k | { | 294 | 15.1k | if (hasNextLayer()) | 295 | 0 | { | 296 | 0 | throw std::runtime_error("Next layer already exists"); | 297 | 0 | } | 298 | | | 299 | 15.1k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 300 | 15.1k | setNextLayer(newLayer); | 301 | 15.1k | return newLayer; | 302 | 15.1k | } |
Unexecuted instantiation: pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::VxlanLayer>(unsigned char*, unsigned long, pcpp::Packet*) pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::DnsLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 293 | 58.3k | { | 294 | 58.3k | if (hasNextLayer()) | 295 | 0 | { | 296 | 0 | throw std::runtime_error("Next layer already exists"); | 297 | 0 | } | 298 | | | 299 | 58.3k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 300 | 58.3k | setNextLayer(newLayer); | 301 | 58.3k | return newLayer; | 302 | 58.3k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::RadiusLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 293 | 12.6k | { | 294 | 12.6k | if (hasNextLayer()) | 295 | 0 | { | 296 | 0 | throw std::runtime_error("Next layer already exists"); | 297 | 0 | } | 298 | | | 299 | 12.6k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 300 | 12.6k | setNextLayer(newLayer); | 301 | 12.6k | return newLayer; | 302 | 12.6k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::GtpV1Layer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 293 | 32.0k | { | 294 | 32.0k | if (hasNextLayer()) | 295 | 0 | { | 296 | 0 | throw std::runtime_error("Next layer already exists"); | 297 | 0 | } | 298 | | | 299 | 32.0k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 300 | 32.0k | setNextLayer(newLayer); | 301 | 32.0k | return newLayer; | 302 | 32.0k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::DhcpV6Layer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 293 | 19.7k | { | 294 | 19.7k | if (hasNextLayer()) | 295 | 0 | { | 296 | 0 | throw std::runtime_error("Next layer already exists"); | 297 | 0 | } | 298 | | | 299 | 19.7k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 300 | 19.7k | setNextLayer(newLayer); | 301 | 19.7k | return newLayer; | 302 | 19.7k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::NtpLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 293 | 16.7k | { | 294 | 16.7k | if (hasNextLayer()) | 295 | 0 | { | 296 | 0 | throw std::runtime_error("Next layer already exists"); | 297 | 0 | } | 298 | | | 299 | 16.7k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 300 | 16.7k | setNextLayer(newLayer); | 301 | 16.7k | return newLayer; | 302 | 16.7k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::WakeOnLanLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 293 | 500 | { | 294 | 500 | if (hasNextLayer()) | 295 | 0 | { | 296 | 0 | throw std::runtime_error("Next layer already exists"); | 297 | 0 | } | 298 | | | 299 | 500 | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 300 | 500 | setNextLayer(newLayer); | 301 | 500 | return newLayer; | 302 | 500 | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::LLCLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 293 | 6.43k | { | 294 | 6.43k | if (hasNextLayer()) | 295 | 0 | { | 296 | 0 | throw std::runtime_error("Next layer already exists"); | 297 | 0 | } | 298 | | | 299 | 6.43k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 300 | 6.43k | setNextLayer(newLayer); | 301 | 6.43k | return newLayer; | 302 | 6.43k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::S7CommLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 293 | 9.87k | { | 294 | 9.87k | if (hasNextLayer()) | 295 | 0 | { | 296 | 0 | throw std::runtime_error("Next layer already exists"); | 297 | 0 | } | 298 | | | 299 | 9.87k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 300 | 9.87k | setNextLayer(newLayer); | 301 | 9.87k | return newLayer; | 302 | 9.87k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::SdpLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 293 | 38.4k | { | 294 | 38.4k | if (hasNextLayer()) | 295 | 0 | { | 296 | 0 | throw std::runtime_error("Next layer already exists"); | 297 | 0 | } | 298 | | | 299 | 38.4k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 300 | 38.4k | setNextLayer(newLayer); | 301 | 38.4k | return newLayer; | 302 | 38.4k | } |
|
303 | | |
304 | | /// @brief Construct the next layer in the protocol stack using a factory functor. |
305 | | /// |
306 | | /// No validation is performed on the data, outside of what the factory functor may perform. |
307 | | /// If the factory returns a nullptr, no next layer is set. |
308 | | /// |
309 | | /// The factory functor is expected to have the following signature: |
310 | | /// Layer* factoryFn(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet, ...); |
311 | | /// |
312 | | /// This overload infers the Packet from the current layer. |
313 | | /// |
314 | | /// @tparam TFactory The factory functor type. |
315 | | /// @tparam ...Args Parameter pack for extra arguments to pass to the factory functor. |
316 | | /// @param[in] factoryFn The factory functor to create the layer. |
317 | | /// @param[in] data The data to construct the layer from |
318 | | /// @param[in] dataLen The length of the data |
319 | | /// @param[in] extraArgs Extra arguments to be forwarded to the factory. |
320 | | /// @return The return value of the factory functor. |
321 | | template <typename TFactory, typename... Args> |
322 | | Layer* constructNextLayerFromFactory(TFactory factoryFn, uint8_t* data, size_t dataLen, Args&&... extraArgs) |
323 | 471k | { |
324 | 471k | return constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, getAttachedPacket(), |
325 | 471k | std::forward<Args>(extraArgs)...); |
326 | 471k | } pcpp::Layer* pcpp::Layer::constructNextLayerFromFactory<pcpp::BgpLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*)>(pcpp::BgpLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*), unsigned char*, unsigned long) Line | Count | Source | 323 | 148k | { | 324 | 148k | return constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, getAttachedPacket(), | 325 | 148k | std::forward<Args>(extraArgs)...); | 326 | 148k | } |
pcpp::Layer* pcpp::Layer::constructNextLayerFromFactory<pcpp::Layer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*)>(pcpp::Layer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*), unsigned char*, unsigned long) Line | Count | Source | 323 | 60.0k | { | 324 | 60.0k | return constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, getAttachedPacket(), | 325 | 60.0k | std::forward<Args>(extraArgs)...); | 326 | 60.0k | } |
pcpp::Layer* pcpp::Layer::constructNextLayerFromFactory<pcpp::SSLLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*)>(pcpp::SSLLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*), unsigned char*, unsigned long) Line | Count | Source | 323 | 220k | { | 324 | 220k | return constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, getAttachedPacket(), | 325 | 220k | std::forward<Args>(extraArgs)...); | 326 | 220k | } |
pcpp::Layer* pcpp::Layer::constructNextLayerFromFactory<pcpp::SSHLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*)>(pcpp::SSHLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*), unsigned char*, unsigned long) Line | Count | Source | 323 | 16.8k | { | 324 | 16.8k | return constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, getAttachedPacket(), | 325 | 16.8k | std::forward<Args>(extraArgs)...); | 326 | 16.8k | } |
pcpp::Layer* pcpp::Layer::constructNextLayerFromFactory<pcpp::LdapLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*)>(pcpp::LdapLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*), unsigned char*, unsigned long) Line | Count | Source | 323 | 25.7k | { | 324 | 25.7k | return constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, getAttachedPacket(), | 325 | 25.7k | std::forward<Args>(extraArgs)...); | 326 | 25.7k | } |
Unexecuted instantiation: pcpp::Layer* pcpp::Layer::constructNextLayerFromFactory<pcpp::StpLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*)>(pcpp::StpLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*), unsigned char*, unsigned long) |
327 | | |
328 | | /// @brief Construct the next layer in the protocol stack using a factory functor. |
329 | | /// |
330 | | /// No validation is performed on the data, outside of what the factory functor may perform. |
331 | | /// If the factory returns a nullptr, no next layer is set. |
332 | | /// |
333 | | /// The factory functor is expected to have the following signature: |
334 | | /// Layer* factoryFn(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet, ...); |
335 | | /// |
336 | | /// @tparam TFactory The factory functor type. |
337 | | /// @tparam ...Args Parameter pack for extra arguments to pass to the factory functor. |
338 | | /// @param[in] factoryFn The factory functor to create the layer. |
339 | | /// @param[in] data The data to construct the layer from |
340 | | /// @param[in] dataLen The length of the data |
341 | | /// @param[in] packet The packet the layer belongs to |
342 | | /// @param[in] extraArgs Extra arguments to be forwarded to the factory. |
343 | | /// @return The return value of the factory functor. |
344 | | template <typename TFactory, typename... Args> |
345 | | Layer* constructNextLayerFromFactory(TFactory factoryFn, uint8_t* data, size_t dataLen, Packet* packet, |
346 | | Args&&... extraArgs) |
347 | 753k | { |
348 | 753k | if (hasNextLayer()) |
349 | 0 | { |
350 | 0 | throw std::runtime_error("Next layer already exists"); |
351 | 0 | } |
352 | | |
353 | | // cppcheck-suppress redundantInitialization |
354 | 753k | Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); |
355 | 753k | setNextLayer(newLayer); |
356 | 753k | return newLayer; |
357 | 753k | } pcpp::Layer* pcpp::Layer::constructNextLayerFromFactory<pcpp::BgpLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*)>(pcpp::BgpLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*), unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 347 | 200k | { | 348 | 200k | if (hasNextLayer()) | 349 | 0 | { | 350 | 0 | throw std::runtime_error("Next layer already exists"); | 351 | 0 | } | 352 | | | 353 | | // cppcheck-suppress redundantInitialization | 354 | 200k | Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 355 | 200k | setNextLayer(newLayer); | 356 | 200k | return newLayer; | 357 | 200k | } |
pcpp::Layer* pcpp::Layer::constructNextLayerFromFactory<pcpp::Layer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*)>(pcpp::Layer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*), unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 347 | 60.0k | { | 348 | 60.0k | if (hasNextLayer()) | 349 | 0 | { | 350 | 0 | throw std::runtime_error("Next layer already exists"); | 351 | 0 | } | 352 | | | 353 | | // cppcheck-suppress redundantInitialization | 354 | 60.0k | Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 355 | 60.0k | setNextLayer(newLayer); | 356 | 60.0k | return newLayer; | 357 | 60.0k | } |
pcpp::Layer* pcpp::Layer::constructNextLayerFromFactory<pcpp::SSLLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*)>(pcpp::SSLLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*), unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 347 | 220k | { | 348 | 220k | if (hasNextLayer()) | 349 | 0 | { | 350 | 0 | throw std::runtime_error("Next layer already exists"); | 351 | 0 | } | 352 | | | 353 | | // cppcheck-suppress redundantInitialization | 354 | 220k | Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 355 | 220k | setNextLayer(newLayer); | 356 | 220k | return newLayer; | 357 | 220k | } |
pcpp::Layer* pcpp::Layer::constructNextLayerFromFactory<pcpp::SSHLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*)>(pcpp::SSHLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*), unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 347 | 16.8k | { | 348 | 16.8k | if (hasNextLayer()) | 349 | 0 | { | 350 | 0 | throw std::runtime_error("Next layer already exists"); | 351 | 0 | } | 352 | | | 353 | | // cppcheck-suppress redundantInitialization | 354 | 16.8k | Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 355 | 16.8k | setNextLayer(newLayer); | 356 | 16.8k | return newLayer; | 357 | 16.8k | } |
pcpp::Layer* pcpp::Layer::constructNextLayerFromFactory<pcpp::DoIpLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*)>(pcpp::DoIpLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*), unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 347 | 64.9k | { | 348 | 64.9k | if (hasNextLayer()) | 349 | 0 | { | 350 | 0 | throw std::runtime_error("Next layer already exists"); | 351 | 0 | } | 352 | | | 353 | | // cppcheck-suppress redundantInitialization | 354 | 64.9k | Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 355 | 64.9k | setNextLayer(newLayer); | 356 | 64.9k | return newLayer; | 357 | 64.9k | } |
pcpp::Layer* pcpp::Layer::constructNextLayerFromFactory<pcpp::LdapLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*)>(pcpp::LdapLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*), unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 347 | 68.3k | { | 348 | 68.3k | if (hasNextLayer()) | 349 | 0 | { | 350 | 0 | throw std::runtime_error("Next layer already exists"); | 351 | 0 | } | 352 | | | 353 | | // cppcheck-suppress redundantInitialization | 354 | 68.3k | Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 355 | 68.3k | setNextLayer(newLayer); | 356 | 68.3k | return newLayer; | 357 | 68.3k | } |
pcpp::Layer* pcpp::Layer::constructNextLayerFromFactory<pcpp::PostgresLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*)>(pcpp::PostgresLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*), unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 347 | 67 | { | 348 | 67 | if (hasNextLayer()) | 349 | 0 | { | 350 | 0 | throw std::runtime_error("Next layer already exists"); | 351 | 0 | } | 352 | | | 353 | | // cppcheck-suppress redundantInitialization | 354 | 67 | Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 355 | 67 | setNextLayer(newLayer); | 356 | 67 | return newLayer; | 357 | 67 | } |
pcpp::Layer* pcpp::Layer::constructNextLayerFromFactory<pcpp::SipLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*, unsigned short, unsigned short), unsigned short&, unsigned short&>(pcpp::SipLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*, unsigned short, unsigned short), unsigned char*, unsigned long, pcpp::Packet*, unsigned short&, unsigned short&) Line | Count | Source | 347 | 69.8k | { | 348 | 69.8k | if (hasNextLayer()) | 349 | 0 | { | 350 | 0 | throw std::runtime_error("Next layer already exists"); | 351 | 0 | } | 352 | | | 353 | | // cppcheck-suppress redundantInitialization | 354 | 69.8k | Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 355 | 69.8k | setNextLayer(newLayer); | 356 | 69.8k | return newLayer; | 357 | 69.8k | } |
pcpp::Layer* pcpp::Layer::constructNextLayerFromFactory<pcpp::WireGuardLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*)>(pcpp::WireGuardLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*), unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 347 | 2.47k | { | 348 | 2.47k | if (hasNextLayer()) | 349 | 0 | { | 350 | 0 | throw std::runtime_error("Next layer already exists"); | 351 | 0 | } | 352 | | | 353 | | // cppcheck-suppress redundantInitialization | 354 | 2.47k | Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 355 | 2.47k | setNextLayer(newLayer); | 356 | 2.47k | return newLayer; | 357 | 2.47k | } |
pcpp::Layer* pcpp::Layer::constructNextLayerFromFactory<pcpp::SipLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*)>(pcpp::SipLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*), unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 347 | 49.9k | { | 348 | 49.9k | if (hasNextLayer()) | 349 | 0 | { | 350 | 0 | throw std::runtime_error("Next layer already exists"); | 351 | 0 | } | 352 | | | 353 | | // cppcheck-suppress redundantInitialization | 354 | 49.9k | Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 355 | 49.9k | setNextLayer(newLayer); | 356 | 49.9k | return newLayer; | 357 | 49.9k | } |
Unexecuted instantiation: pcpp::Layer* pcpp::Layer::constructNextLayerFromFactory<pcpp::StpLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*)>(pcpp::StpLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*), unsigned char*, unsigned long, pcpp::Packet*) |
358 | | |
359 | | /// Try to construct the next layer in the protocol stack. |
360 | | /// |
361 | | /// This overload infers the Packet from the current layer. |
362 | | /// |
363 | | /// The method checks if the data is valid for the layer type T before constructing it by calling |
364 | | /// T::isDataValid(data, dataLen). If the data is invalid, no layer is constructed and a nullptr is returned. |
365 | | /// |
366 | | /// @tparam T The type of the layer to construct |
367 | | /// @tparam Args The types of the extra arguments to pass to the layer constructor |
368 | | /// @param[in] data The data to construct the layer from |
369 | | /// @param[in] dataLen The length of the data |
370 | | /// @param[in] extraArgs Extra arguments to be forwarded to the layer constructor |
371 | | /// @return The constructed layer or nullptr if the data is invalid |
372 | | template <typename T, typename... Args> |
373 | | Layer* tryConstructNextLayer(uint8_t* data, size_t dataLen, Args&&... extraArgs) |
374 | 0 | { |
375 | 0 | return tryConstructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...); |
376 | 0 | } |
377 | | |
378 | | /// Try to construct the next layer in the protocol stack. |
379 | | /// |
380 | | /// The method checks if the data is valid for the layer type T before constructing it by calling |
381 | | /// T::isDataValid(data, dataLen). If the data is invalid, no layer is constructed and a nullptr is returned. |
382 | | /// |
383 | | /// @tparam T The type of the layer to construct |
384 | | /// @tparam Args The types of the extra arguments to pass to the layer constructor |
385 | | /// @param[in] data The data to construct the layer from |
386 | | /// @param[in] dataLen The length of the data |
387 | | /// @param[in] packet The packet the layer belongs to |
388 | | /// @param[in] extraArgs Extra arguments to be forwarded to the layer constructor |
389 | | /// @return The constructed layer or nullptr if the data is invalid |
390 | | template <typename T, typename... Args> |
391 | | Layer* tryConstructNextLayer(uint8_t* data, size_t dataLen, Packet* packet, Args&&... extraArgs) |
392 | 2.49M | { |
393 | 2.49M | if (T::isDataValid(data, dataLen)) |
394 | 2.45M | { |
395 | 2.45M | return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...); |
396 | 2.45M | } |
397 | 41.6k | return nullptr; |
398 | 2.49M | } pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::IPv4Layer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 392 | 944k | { | 393 | 944k | if (T::isDataValid(data, dataLen)) | 394 | 929k | { | 395 | 929k | return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...); | 396 | 929k | } | 397 | 15.1k | return nullptr; | 398 | 944k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::IPv6Layer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 392 | 168k | { | 393 | 168k | if (T::isDataValid(data, dataLen)) | 394 | 164k | { | 395 | 164k | return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...); | 396 | 164k | } | 397 | 4.02k | return nullptr; | 398 | 168k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::PPP_PPTPLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 392 | 67.4k | { | 393 | 67.4k | if (T::isDataValid(data, dataLen)) | 394 | 67.4k | { | 395 | 67.4k | return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...); | 396 | 67.4k | } | 397 | 0 | return nullptr; | 398 | 67.4k | } |
Unexecuted instantiation: pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::EthLayer>(unsigned char*, unsigned long, pcpp::Packet*) Unexecuted instantiation: pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::EthDot3Layer>(unsigned char*, unsigned long, pcpp::Packet*) Unexecuted instantiation: pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::GtpV2Layer>(unsigned char*, unsigned long, pcpp::Packet*) pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::UdpLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 392 | 366k | { | 393 | 366k | if (T::isDataValid(data, dataLen)) | 394 | 363k | { | 395 | 363k | return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...); | 396 | 363k | } | 397 | 2.68k | return nullptr; | 398 | 366k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::TcpLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 392 | 539k | { | 393 | 539k | if (T::isDataValid(data, dataLen)) | 394 | 525k | { | 395 | 525k | return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...); | 396 | 525k | } | 397 | 13.1k | return nullptr; | 398 | 539k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::IcmpLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 392 | 42.9k | { | 393 | 42.9k | if (T::isDataValid(data, dataLen)) | 394 | 41.6k | { | 395 | 41.6k | return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...); | 396 | 41.6k | } | 397 | 1.26k | return nullptr; | 398 | 42.9k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::GREv0Layer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 392 | 10.0k | { | 393 | 10.0k | if (T::isDataValid(data, dataLen)) | 394 | 10.0k | { | 395 | 10.0k | return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...); | 396 | 10.0k | } | 397 | 0 | return nullptr; | 398 | 10.0k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::GREv1Layer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 392 | 75.2k | { | 393 | 75.2k | if (T::isDataValid(data, dataLen)) | 394 | 75.1k | { | 395 | 75.1k | return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...); | 396 | 75.1k | } | 397 | 60 | return nullptr; | 398 | 75.2k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::IgmpV1Layer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 392 | 3.13k | { | 393 | 3.13k | if (T::isDataValid(data, dataLen)) | 394 | 3.13k | { | 395 | 3.13k | return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...); | 396 | 3.13k | } | 397 | 0 | return nullptr; | 398 | 3.13k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::IgmpV2Layer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 392 | 7.73k | { | 393 | 7.73k | if (T::isDataValid(data, dataLen)) | 394 | 7.73k | { | 395 | 7.73k | return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...); | 396 | 7.73k | } | 397 | 0 | return nullptr; | 398 | 7.73k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::IgmpV3QueryLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 392 | 1.71k | { | 393 | 1.71k | if (T::isDataValid(data, dataLen)) | 394 | 1.71k | { | 395 | 1.71k | return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...); | 396 | 1.71k | } | 397 | 0 | return nullptr; | 398 | 1.71k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::IgmpV3ReportLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 392 | 2.23k | { | 393 | 2.23k | if (T::isDataValid(data, dataLen)) | 394 | 2.23k | { | 395 | 2.23k | return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...); | 396 | 2.23k | } | 397 | 0 | return nullptr; | 398 | 2.23k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::AuthenticationHeaderLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 392 | 5.62k | { | 393 | 5.62k | if (T::isDataValid(data, dataLen)) | 394 | 5.19k | { | 395 | 5.19k | return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...); | 396 | 5.19k | } | 397 | 433 | return nullptr; | 398 | 5.62k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::ESPLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 392 | 6.78k | { | 393 | 6.78k | if (T::isDataValid(data, dataLen)) | 394 | 6.70k | { | 395 | 6.70k | return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...); | 396 | 6.70k | } | 397 | 80 | return nullptr; | 398 | 6.78k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::VrrpV2Layer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 392 | 3.98k | { | 393 | 3.98k | if (T::isDataValid(data, dataLen)) | 394 | 3.98k | { | 395 | 3.98k | return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...); | 396 | 3.98k | } | 397 | 0 | return nullptr; | 398 | 3.98k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::VrrpV3Layer, pcpp::IPAddress::AddressType>(unsigned char*, unsigned long, pcpp::Packet*, pcpp::IPAddress::AddressType&&) Line | Count | Source | 392 | 3.24k | { | 393 | 3.24k | if (T::isDataValid(data, dataLen)) | 394 | 3.24k | { | 395 | 3.24k | return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...); | 396 | 3.24k | } | 397 | 0 | return nullptr; | 398 | 3.24k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::PPPoESessionLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 392 | 42.1k | { | 393 | 42.1k | if (T::isDataValid(data, dataLen)) | 394 | 42.1k | { | 395 | 42.1k | return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...); | 396 | 42.1k | } | 397 | 8 | return nullptr; | 398 | 42.1k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::PPPoEDiscoveryLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 392 | 230 | { | 393 | 230 | if (T::isDataValid(data, dataLen)) | 394 | 227 | { | 395 | 227 | return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...); | 396 | 227 | } | 397 | 3 | return nullptr; | 398 | 230 | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::CotpLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 392 | 17.1k | { | 393 | 17.1k | if (T::isDataValid(data, dataLen)) | 394 | 13.2k | { | 395 | 13.2k | return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...); | 396 | 13.2k | } | 397 | 3.91k | return nullptr; | 398 | 17.1k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::DhcpLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 392 | 15.1k | { | 393 | 15.1k | if (T::isDataValid(data, dataLen)) | 394 | 15.1k | { | 395 | 15.1k | return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...); | 396 | 15.1k | } | 397 | 82 | return nullptr; | 398 | 15.1k | } |
Unexecuted instantiation: pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::VxlanLayer>(unsigned char*, unsigned long, pcpp::Packet*) pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::LLCLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 392 | 6.81k | { | 393 | 6.81k | if (T::isDataValid(data, dataLen)) | 394 | 6.43k | { | 395 | 6.43k | return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...); | 396 | 6.43k | } | 397 | 380 | return nullptr; | 398 | 6.81k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::S7CommLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 392 | 10.1k | { | 393 | 10.1k | if (T::isDataValid(data, dataLen)) | 394 | 9.87k | { | 395 | 9.87k | return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...); | 396 | 9.87k | } | 397 | 246 | return nullptr; | 398 | 10.1k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::ArpLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 392 | 3.44k | { | 393 | 3.44k | if (T::isDataValid(data, dataLen)) | 394 | 3.39k | { | 395 | 3.39k | return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...); | 396 | 3.39k | } | 397 | 54 | return nullptr; | 398 | 3.44k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::VlanLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 392 | 155k | { | 393 | 155k | if (T::isDataValid(data, dataLen)) | 394 | 155k | { | 395 | 155k | return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...); | 396 | 155k | } | 397 | 69 | return nullptr; | 398 | 155k | } |
Unexecuted instantiation: pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::MplsLayer>(unsigned char*, unsigned long, pcpp::Packet*) pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::WakeOnLanLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 392 | 72 | { | 393 | 72 | if (T::isDataValid(data, dataLen)) | 394 | 0 | { | 395 | 0 | return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...); | 396 | 0 | } | 397 | 72 | return nullptr; | 398 | 72 | } |
|
399 | | |
400 | | /// @brief Try to construct the next layer in the protocol stack with a fallback option. |
401 | | /// |
402 | | /// This overload infers the Packet from the current layer. |
403 | | /// |
404 | | /// The method checks if the data is valid for the layer type T before constructing it by calling |
405 | | /// T::isDataValid(data, dataLen). If the data is invalid, it constructs the layer of type TFallback. |
406 | | /// |
407 | | /// @tparam T The type of the layer to construct |
408 | | /// @tparam TFallback The fallback layer type to construct if T fails |
409 | | /// @tparam Args The types of the extra arguments to pass to the layer constructor of T |
410 | | /// @param[in] data The data to construct the layer from |
411 | | /// @param[in] dataLen The length of the data |
412 | | /// @param[in] extraArgs Extra arguments to be forwarded to the layer constructor of T |
413 | | /// @return The constructed layer of type T or TFallback |
414 | | /// @remarks The parameters extraArgs are forwarded to the factory function, but not to the TFallback |
415 | | /// constructor. |
416 | | template <typename T, typename TFallback, typename... Args> |
417 | | Layer* tryConstructNextLayerWithFallback(uint8_t* data, size_t dataLen, Args&&... extraArgs) |
418 | 1.58M | { |
419 | 1.58M | return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(), |
420 | 1.58M | std::forward<Args>(extraArgs)...); |
421 | 1.58M | } pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::IPv4Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long) Line | Count | Source | 418 | 942k | { | 419 | 942k | return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(), | 420 | 942k | std::forward<Args>(extraArgs)...); | 421 | 942k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::IPv6Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long) Line | Count | Source | 418 | 167k | { | 419 | 167k | return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(), | 420 | 167k | std::forward<Args>(extraArgs)...); | 421 | 167k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::PPP_PPTPLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long) Line | Count | Source | 418 | 67.4k | { | 419 | 67.4k | return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(), | 420 | 67.4k | std::forward<Args>(extraArgs)...); | 421 | 67.4k | } |
Unexecuted instantiation: pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::EthDot3Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long) Unexecuted instantiation: pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::GtpV2Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long) pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::UdpLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long) Line | Count | Source | 418 | 36.2k | { | 419 | 36.2k | return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(), | 420 | 36.2k | std::forward<Args>(extraArgs)...); | 421 | 36.2k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::TcpLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long) Line | Count | Source | 418 | 99.1k | { | 419 | 99.1k | return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(), | 420 | 99.1k | std::forward<Args>(extraArgs)...); | 421 | 99.1k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::GREv0Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long) Line | Count | Source | 418 | 6.84k | { | 419 | 6.84k | return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(), | 420 | 6.84k | std::forward<Args>(extraArgs)...); | 421 | 6.84k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::GREv1Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long) Line | Count | Source | 418 | 5.96k | { | 419 | 5.96k | return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(), | 420 | 5.96k | std::forward<Args>(extraArgs)...); | 421 | 5.96k | } |
Unexecuted instantiation: pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::AuthenticationHeaderLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long) pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::ESPLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long) Line | Count | Source | 418 | 4.03k | { | 419 | 4.03k | return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(), | 420 | 4.03k | std::forward<Args>(extraArgs)...); | 421 | 4.03k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::PPPoESessionLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long) Line | Count | Source | 418 | 42.1k | { | 419 | 42.1k | return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(), | 420 | 42.1k | std::forward<Args>(extraArgs)...); | 421 | 42.1k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::PPPoEDiscoveryLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long) Line | Count | Source | 418 | 230 | { | 419 | 230 | return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(), | 420 | 230 | std::forward<Args>(extraArgs)...); | 421 | 230 | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::CotpLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long) Line | Count | Source | 418 | 17.1k | { | 419 | 17.1k | return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(), | 420 | 17.1k | std::forward<Args>(extraArgs)...); | 421 | 17.1k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::DhcpLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long) Line | Count | Source | 418 | 15.1k | { | 419 | 15.1k | return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(), | 420 | 15.1k | std::forward<Args>(extraArgs)...); | 421 | 15.1k | } |
Unexecuted instantiation: pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::VxlanLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long) pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::LLCLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long) Line | Count | Source | 418 | 6.81k | { | 419 | 6.81k | return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(), | 420 | 6.81k | std::forward<Args>(extraArgs)...); | 421 | 6.81k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::S7CommLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long) Line | Count | Source | 418 | 10.1k | { | 419 | 10.1k | return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(), | 420 | 10.1k | std::forward<Args>(extraArgs)...); | 421 | 10.1k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::ArpLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long) Line | Count | Source | 418 | 3.44k | { | 419 | 3.44k | return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(), | 420 | 3.44k | std::forward<Args>(extraArgs)...); | 421 | 3.44k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::VlanLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long) Line | Count | Source | 418 | 155k | { | 419 | 155k | return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(), | 420 | 155k | std::forward<Args>(extraArgs)...); | 421 | 155k | } |
Unexecuted instantiation: pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::MplsLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long) pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::WakeOnLanLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long) Line | Count | Source | 418 | 72 | { | 419 | 72 | return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(), | 420 | 72 | std::forward<Args>(extraArgs)...); | 421 | 72 | } |
|
422 | | |
423 | | /// Try to construct the next layer in the protocol stack with a fallback option. |
424 | | /// |
425 | | /// The method checks if the data is valid for the layer type T before constructing it by calling |
426 | | /// T::isDataValid(data, dataLen). If the data is invalid, it constructs the layer of type TFallback. |
427 | | /// |
428 | | /// @tparam T The type of the layer to construct |
429 | | /// @tparam TFallback The fallback layer type to construct if T fails |
430 | | /// @tparam Args The types of the extra arguments to pass to the layer constructor of T |
431 | | /// @param[in] data The data to construct the layer from |
432 | | /// @param[in] dataLen The length of the data |
433 | | /// @param[in] packet The packet the layer belongs to |
434 | | /// @param[in] extraArgs Extra arguments to be forwarded to the layer constructor of T |
435 | | /// @return The constructed layer of type T or TFallback |
436 | | /// @remarks The parameters extraArgs are forwarded to the factory function, but not to the TFallback |
437 | | /// constructor. |
438 | | template <typename T, typename TFallback, typename... Args> |
439 | | Layer* tryConstructNextLayerWithFallback(uint8_t* data, size_t dataLen, Packet* packet, Args&&... extraArgs) |
440 | 2.49M | { |
441 | 2.49M | if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...)) |
442 | 2.45M | { |
443 | 2.45M | return m_NextLayer; |
444 | 2.45M | } |
445 | | |
446 | 41.6k | return constructNextLayer<TFallback>(data, dataLen, packet); |
447 | 2.49M | } pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::IPv4Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 440 | 944k | { | 441 | 944k | if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...)) | 442 | 929k | { | 443 | 929k | return m_NextLayer; | 444 | 929k | } | 445 | | | 446 | 15.1k | return constructNextLayer<TFallback>(data, dataLen, packet); | 447 | 944k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::IPv6Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 440 | 168k | { | 441 | 168k | if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...)) | 442 | 164k | { | 443 | 164k | return m_NextLayer; | 444 | 164k | } | 445 | | | 446 | 4.02k | return constructNextLayer<TFallback>(data, dataLen, packet); | 447 | 168k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::PPP_PPTPLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 440 | 67.4k | { | 441 | 67.4k | if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...)) | 442 | 67.4k | { | 443 | 67.4k | return m_NextLayer; | 444 | 67.4k | } | 445 | | | 446 | 0 | return constructNextLayer<TFallback>(data, dataLen, packet); | 447 | 67.4k | } |
Unexecuted instantiation: pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::EthDot3Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*) Unexecuted instantiation: pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::GtpV2Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*) pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::UdpLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 440 | 366k | { | 441 | 366k | if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...)) | 442 | 363k | { | 443 | 363k | return m_NextLayer; | 444 | 363k | } | 445 | | | 446 | 2.68k | return constructNextLayer<TFallback>(data, dataLen, packet); | 447 | 366k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::TcpLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 440 | 539k | { | 441 | 539k | if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...)) | 442 | 525k | { | 443 | 525k | return m_NextLayer; | 444 | 525k | } | 445 | | | 446 | 13.1k | return constructNextLayer<TFallback>(data, dataLen, packet); | 447 | 539k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::IcmpLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 440 | 42.9k | { | 441 | 42.9k | if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...)) | 442 | 41.6k | { | 443 | 41.6k | return m_NextLayer; | 444 | 41.6k | } | 445 | | | 446 | 1.26k | return constructNextLayer<TFallback>(data, dataLen, packet); | 447 | 42.9k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::GREv0Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 440 | 10.0k | { | 441 | 10.0k | if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...)) | 442 | 10.0k | { | 443 | 10.0k | return m_NextLayer; | 444 | 10.0k | } | 445 | | | 446 | 0 | return constructNextLayer<TFallback>(data, dataLen, packet); | 447 | 10.0k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::GREv1Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 440 | 75.2k | { | 441 | 75.2k | if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...)) | 442 | 75.1k | { | 443 | 75.1k | return m_NextLayer; | 444 | 75.1k | } | 445 | | | 446 | 60 | return constructNextLayer<TFallback>(data, dataLen, packet); | 447 | 75.2k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::IgmpV1Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 440 | 3.13k | { | 441 | 3.13k | if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...)) | 442 | 3.13k | { | 443 | 3.13k | return m_NextLayer; | 444 | 3.13k | } | 445 | | | 446 | 0 | return constructNextLayer<TFallback>(data, dataLen, packet); | 447 | 3.13k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::IgmpV2Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 440 | 7.73k | { | 441 | 7.73k | if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...)) | 442 | 7.73k | { | 443 | 7.73k | return m_NextLayer; | 444 | 7.73k | } | 445 | | | 446 | 0 | return constructNextLayer<TFallback>(data, dataLen, packet); | 447 | 7.73k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::IgmpV3QueryLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 440 | 1.71k | { | 441 | 1.71k | if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...)) | 442 | 1.71k | { | 443 | 1.71k | return m_NextLayer; | 444 | 1.71k | } | 445 | | | 446 | 0 | return constructNextLayer<TFallback>(data, dataLen, packet); | 447 | 1.71k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::IgmpV3ReportLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 440 | 2.23k | { | 441 | 2.23k | if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...)) | 442 | 2.23k | { | 443 | 2.23k | return m_NextLayer; | 444 | 2.23k | } | 445 | | | 446 | 0 | return constructNextLayer<TFallback>(data, dataLen, packet); | 447 | 2.23k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::AuthenticationHeaderLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 440 | 5.62k | { | 441 | 5.62k | if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...)) | 442 | 5.19k | { | 443 | 5.19k | return m_NextLayer; | 444 | 5.19k | } | 445 | | | 446 | 433 | return constructNextLayer<TFallback>(data, dataLen, packet); | 447 | 5.62k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::ESPLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 440 | 6.78k | { | 441 | 6.78k | if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...)) | 442 | 6.70k | { | 443 | 6.70k | return m_NextLayer; | 444 | 6.70k | } | 445 | | | 446 | 80 | return constructNextLayer<TFallback>(data, dataLen, packet); | 447 | 6.78k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::VrrpV2Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 440 | 3.98k | { | 441 | 3.98k | if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...)) | 442 | 3.98k | { | 443 | 3.98k | return m_NextLayer; | 444 | 3.98k | } | 445 | | | 446 | 0 | return constructNextLayer<TFallback>(data, dataLen, packet); | 447 | 3.98k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::VrrpV3Layer, pcpp::PayloadLayer, pcpp::IPAddress::AddressType>(unsigned char*, unsigned long, pcpp::Packet*, pcpp::IPAddress::AddressType&&) Line | Count | Source | 440 | 3.24k | { | 441 | 3.24k | if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...)) | 442 | 3.24k | { | 443 | 3.24k | return m_NextLayer; | 444 | 3.24k | } | 445 | | | 446 | 0 | return constructNextLayer<TFallback>(data, dataLen, packet); | 447 | 3.24k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::PPPoESessionLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 440 | 42.1k | { | 441 | 42.1k | if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...)) | 442 | 42.1k | { | 443 | 42.1k | return m_NextLayer; | 444 | 42.1k | } | 445 | | | 446 | 8 | return constructNextLayer<TFallback>(data, dataLen, packet); | 447 | 42.1k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::PPPoEDiscoveryLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 440 | 230 | { | 441 | 230 | if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...)) | 442 | 227 | { | 443 | 227 | return m_NextLayer; | 444 | 227 | } | 445 | | | 446 | 3 | return constructNextLayer<TFallback>(data, dataLen, packet); | 447 | 230 | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::CotpLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 440 | 17.1k | { | 441 | 17.1k | if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...)) | 442 | 13.2k | { | 443 | 13.2k | return m_NextLayer; | 444 | 13.2k | } | 445 | | | 446 | 3.91k | return constructNextLayer<TFallback>(data, dataLen, packet); | 447 | 17.1k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::DhcpLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 440 | 15.1k | { | 441 | 15.1k | if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...)) | 442 | 15.1k | { | 443 | 15.1k | return m_NextLayer; | 444 | 15.1k | } | 445 | | | 446 | 82 | return constructNextLayer<TFallback>(data, dataLen, packet); | 447 | 15.1k | } |
Unexecuted instantiation: pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::VxlanLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*) pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::LLCLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 440 | 6.81k | { | 441 | 6.81k | if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...)) | 442 | 6.43k | { | 443 | 6.43k | return m_NextLayer; | 444 | 6.43k | } | 445 | | | 446 | 380 | return constructNextLayer<TFallback>(data, dataLen, packet); | 447 | 6.81k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::S7CommLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 440 | 10.1k | { | 441 | 10.1k | if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...)) | 442 | 9.87k | { | 443 | 9.87k | return m_NextLayer; | 444 | 9.87k | } | 445 | | | 446 | 246 | return constructNextLayer<TFallback>(data, dataLen, packet); | 447 | 10.1k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::ArpLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 440 | 3.44k | { | 441 | 3.44k | if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...)) | 442 | 3.39k | { | 443 | 3.39k | return m_NextLayer; | 444 | 3.39k | } | 445 | | | 446 | 54 | return constructNextLayer<TFallback>(data, dataLen, packet); | 447 | 3.44k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::VlanLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 440 | 155k | { | 441 | 155k | if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...)) | 442 | 155k | { | 443 | 155k | return m_NextLayer; | 444 | 155k | } | 445 | | | 446 | 69 | return constructNextLayer<TFallback>(data, dataLen, packet); | 447 | 155k | } |
Unexecuted instantiation: pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::MplsLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*) pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::WakeOnLanLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 440 | 72 | { | 441 | 72 | if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...)) | 442 | 0 | { | 443 | 0 | return m_NextLayer; | 444 | 0 | } | 445 | | | 446 | 72 | return constructNextLayer<TFallback>(data, dataLen, packet); | 447 | 72 | } |
|
448 | | |
449 | | /// @brief Try to construct the next layer in the protocol stack using a factory functor with a fallback option. |
450 | | /// |
451 | | /// The method will attempt to construct the next layer using the provided factory function. |
452 | | /// If the factory function returns nullptr, indicating failure to create the layer, the method will then |
453 | | /// construct a layer of type TFallback. |
454 | | /// |
455 | | /// The factory functor is expected to have the following signature: |
456 | | /// Layer* factoryFn(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet, ...); |
457 | | /// |
458 | | /// This overload infers the Packet from the current layer. |
459 | | /// |
460 | | /// @tparam TFallback The fallback layer type to construct if the factory fails. |
461 | | /// @tparam TFactory The factory functor type. |
462 | | /// @tparam ...Args Parameter pack for extra arguments to pass to the factory functor. |
463 | | /// @param[in] factoryFn The factory functor to create the layer. |
464 | | /// @param[in] data The data to construct the layer from |
465 | | /// @param[in] dataLen The length of the data |
466 | | /// @param[in] extraArgs Extra arguments to be forwarded to the factory. |
467 | | /// @return The return value of the factory functor. |
468 | | /// @remarks The parameters extraArgs are forwarded to the factory function, but not to the TFallback |
469 | | /// constructor. |
470 | | template <typename TFallback, typename TFactory, typename... Args> |
471 | | Layer* tryConstructNextLayerFromFactoryWithFallback(TFactory factoryFn, uint8_t* data, size_t dataLen, |
472 | | Args&&... extraArgs) |
473 | 282k | { |
474 | | // Note that the fallback is first to allow template argument deduction of the factory type. |
475 | 282k | return tryConstructNextLayerFromFactoryWithFallback<TFallback, TFactory>( |
476 | 282k | factoryFn, data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...); |
477 | 282k | } pcpp::Layer* pcpp::Layer::tryConstructNextLayerFromFactoryWithFallback<pcpp::PayloadLayer, pcpp::BgpLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*)>(pcpp::BgpLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*), unsigned char*, unsigned long) Line | Count | Source | 473 | 52.5k | { | 474 | | // Note that the fallback is first to allow template argument deduction of the factory type. | 475 | 52.5k | return tryConstructNextLayerFromFactoryWithFallback<TFallback, TFactory>( | 476 | 52.5k | factoryFn, data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...); | 477 | 52.5k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerFromFactoryWithFallback<pcpp::PayloadLayer, pcpp::DoIpLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*)>(pcpp::DoIpLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*), unsigned char*, unsigned long) Line | Count | Source | 473 | 64.9k | { | 474 | | // Note that the fallback is first to allow template argument deduction of the factory type. | 475 | 64.9k | return tryConstructNextLayerFromFactoryWithFallback<TFallback, TFactory>( | 476 | 64.9k | factoryFn, data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...); | 477 | 64.9k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerFromFactoryWithFallback<pcpp::PayloadLayer, pcpp::LdapLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*)>(pcpp::LdapLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*), unsigned char*, unsigned long) Line | Count | Source | 473 | 42.6k | { | 474 | | // Note that the fallback is first to allow template argument deduction of the factory type. | 475 | 42.6k | return tryConstructNextLayerFromFactoryWithFallback<TFallback, TFactory>( | 476 | 42.6k | factoryFn, data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...); | 477 | 42.6k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerFromFactoryWithFallback<pcpp::PayloadLayer, pcpp::PostgresLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*)>(pcpp::PostgresLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*), unsigned char*, unsigned long) Line | Count | Source | 473 | 67 | { | 474 | | // Note that the fallback is first to allow template argument deduction of the factory type. | 475 | 67 | return tryConstructNextLayerFromFactoryWithFallback<TFallback, TFactory>( | 476 | 67 | factoryFn, data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...); | 477 | 67 | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerFromFactoryWithFallback<pcpp::PayloadLayer, pcpp::SipLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*, unsigned short, unsigned short), unsigned short&, unsigned short&>(pcpp::SipLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*, unsigned short, unsigned short), unsigned char*, unsigned long, unsigned short&, unsigned short&) Line | Count | Source | 473 | 69.8k | { | 474 | | // Note that the fallback is first to allow template argument deduction of the factory type. | 475 | 69.8k | return tryConstructNextLayerFromFactoryWithFallback<TFallback, TFactory>( | 476 | 69.8k | factoryFn, data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...); | 477 | 69.8k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerFromFactoryWithFallback<pcpp::PayloadLayer, pcpp::WireGuardLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*)>(pcpp::WireGuardLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*), unsigned char*, unsigned long) Line | Count | Source | 473 | 2.47k | { | 474 | | // Note that the fallback is first to allow template argument deduction of the factory type. | 475 | 2.47k | return tryConstructNextLayerFromFactoryWithFallback<TFallback, TFactory>( | 476 | 2.47k | factoryFn, data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...); | 477 | 2.47k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerFromFactoryWithFallback<pcpp::PayloadLayer, pcpp::SipLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*)>(pcpp::SipLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*), unsigned char*, unsigned long) Line | Count | Source | 473 | 49.9k | { | 474 | | // Note that the fallback is first to allow template argument deduction of the factory type. | 475 | 49.9k | return tryConstructNextLayerFromFactoryWithFallback<TFallback, TFactory>( | 476 | 49.9k | factoryFn, data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...); | 477 | 49.9k | } |
|
478 | | |
479 | | /// @brief Try to construct the next layer in the protocol stack using a factory functor with a fallback option. |
480 | | /// |
481 | | /// The method will attempt to construct the next layer using the provided factory function. |
482 | | /// If the factory function returns nullptr, indicating failure to create the layer, the method will then |
483 | | /// construct a layer of type TFallback. |
484 | | /// |
485 | | /// The factory functor is expected to have the following signature: |
486 | | /// Layer* factoryFn(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet, ...); |
487 | | /// |
488 | | /// @tparam TFallback The fallback layer type to construct if the factory fails. |
489 | | /// @tparam TFactory The factory functor type. |
490 | | /// @tparam ...Args Parameter pack for extra arguments to pass to the factory functor. |
491 | | /// @param[in] factoryFn The factory functor to create the layer. |
492 | | /// @param[in] data The data to construct the layer from |
493 | | /// @param[in] dataLen The length of the data |
494 | | /// @param[in] packet The packet the layer belongs to |
495 | | /// @param[in] extraArgs Extra arguments to be forwarded to the factory. |
496 | | /// @return The return value of the factory functor. |
497 | | /// @remarks The parameters extraArgs are forwarded to the factory function, but not to the TFallback |
498 | | /// constructor. |
499 | | template <typename TFallback, typename TFactory, typename... Args> |
500 | | Layer* tryConstructNextLayerFromFactoryWithFallback(TFactory factoryFn, uint8_t* data, size_t dataLen, |
501 | | Packet* packet, Args&&... extraArgs) |
502 | 282k | { |
503 | 282k | auto nextLayer = constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, packet, |
504 | 282k | std::forward<Args>(extraArgs)...); |
505 | 282k | if (nextLayer != nullptr) |
506 | 217k | { |
507 | 217k | return nextLayer; |
508 | 217k | } |
509 | | |
510 | | // factory failed, construct fallback layer |
511 | 65.2k | return constructNextLayer<TFallback>(data, dataLen, packet); |
512 | 282k | } pcpp::Layer* pcpp::Layer::tryConstructNextLayerFromFactoryWithFallback<pcpp::PayloadLayer, pcpp::BgpLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*)>(pcpp::BgpLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*), unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 502 | 52.5k | { | 503 | 52.5k | auto nextLayer = constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, packet, | 504 | 52.5k | std::forward<Args>(extraArgs)...); | 505 | 52.5k | if (nextLayer != nullptr) | 506 | 49.3k | { | 507 | 49.3k | return nextLayer; | 508 | 49.3k | } | 509 | | | 510 | | // factory failed, construct fallback layer | 511 | 3.23k | return constructNextLayer<TFallback>(data, dataLen, packet); | 512 | 52.5k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerFromFactoryWithFallback<pcpp::PayloadLayer, pcpp::DoIpLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*)>(pcpp::DoIpLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*), unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 502 | 64.9k | { | 503 | 64.9k | auto nextLayer = constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, packet, | 504 | 64.9k | std::forward<Args>(extraArgs)...); | 505 | 64.9k | if (nextLayer != nullptr) | 506 | 64.4k | { | 507 | 64.4k | return nextLayer; | 508 | 64.4k | } | 509 | | | 510 | | // factory failed, construct fallback layer | 511 | 566 | return constructNextLayer<TFallback>(data, dataLen, packet); | 512 | 64.9k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerFromFactoryWithFallback<pcpp::PayloadLayer, pcpp::LdapLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*)>(pcpp::LdapLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*), unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 502 | 42.6k | { | 503 | 42.6k | auto nextLayer = constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, packet, | 504 | 42.6k | std::forward<Args>(extraArgs)...); | 505 | 42.6k | if (nextLayer != nullptr) | 506 | 35.1k | { | 507 | 35.1k | return nextLayer; | 508 | 35.1k | } | 509 | | | 510 | | // factory failed, construct fallback layer | 511 | 7.50k | return constructNextLayer<TFallback>(data, dataLen, packet); | 512 | 42.6k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerFromFactoryWithFallback<pcpp::PayloadLayer, pcpp::PostgresLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*)>(pcpp::PostgresLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*), unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 502 | 67 | { | 503 | 67 | auto nextLayer = constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, packet, | 504 | 67 | std::forward<Args>(extraArgs)...); | 505 | 67 | if (nextLayer != nullptr) | 506 | 67 | { | 507 | 67 | return nextLayer; | 508 | 67 | } | 509 | | | 510 | | // factory failed, construct fallback layer | 511 | 0 | return constructNextLayer<TFallback>(data, dataLen, packet); | 512 | 67 | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerFromFactoryWithFallback<pcpp::PayloadLayer, pcpp::SipLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*, unsigned short, unsigned short), unsigned short&, unsigned short&>(pcpp::SipLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*, unsigned short, unsigned short), unsigned char*, unsigned long, pcpp::Packet*, unsigned short&, unsigned short&) Line | Count | Source | 502 | 69.8k | { | 503 | 69.8k | auto nextLayer = constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, packet, | 504 | 69.8k | std::forward<Args>(extraArgs)...); | 505 | 69.8k | if (nextLayer != nullptr) | 506 | 65.6k | { | 507 | 65.6k | return nextLayer; | 508 | 65.6k | } | 509 | | | 510 | | // factory failed, construct fallback layer | 511 | 4.24k | return constructNextLayer<TFallback>(data, dataLen, packet); | 512 | 69.8k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerFromFactoryWithFallback<pcpp::PayloadLayer, pcpp::WireGuardLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*)>(pcpp::WireGuardLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*), unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 502 | 2.47k | { | 503 | 2.47k | auto nextLayer = constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, packet, | 504 | 2.47k | std::forward<Args>(extraArgs)...); | 505 | 2.47k | if (nextLayer != nullptr) | 506 | 2.47k | { | 507 | 2.47k | return nextLayer; | 508 | 2.47k | } | 509 | | | 510 | | // factory failed, construct fallback layer | 511 | 0 | return constructNextLayer<TFallback>(data, dataLen, packet); | 512 | 2.47k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerFromFactoryWithFallback<pcpp::PayloadLayer, pcpp::SipLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*)>(pcpp::SipLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*), unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 502 | 49.9k | { | 503 | 49.9k | auto nextLayer = constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, packet, | 504 | 49.9k | std::forward<Args>(extraArgs)...); | 505 | 49.9k | if (nextLayer != nullptr) | 506 | 193 | { | 507 | 193 | return nextLayer; | 508 | 193 | } | 509 | | | 510 | | // factory failed, construct fallback layer | 511 | 49.7k | return constructNextLayer<TFallback>(data, dataLen, packet); | 512 | 49.9k | } |
|
513 | | |
514 | | /// @brief Check if the data is large enough to reinterpret as a type |
515 | | /// |
516 | | /// The data must be non-null and at least as large as the type |
517 | | /// |
518 | | /// @tparam T The type to reinterpret as |
519 | | /// @param data The data to check |
520 | | /// @param dataLen The length of the data |
521 | | /// @return True if the data is large enough to reinterpret as T, false otherwise |
522 | | template <typename T> static bool canReinterpretAs(const uint8_t* data, size_t dataLen) |
523 | 1.66M | { |
524 | 1.66M | return data != nullptr && dataLen >= sizeof(T); |
525 | 1.66M | } bool pcpp::Layer::canReinterpretAs<pcpp::arphdr>(unsigned char const*, unsigned long) Line | Count | Source | 523 | 3.44k | { | 524 | 3.44k | return data != nullptr && dataLen >= sizeof(T); | 525 | 3.44k | } |
bool pcpp::Layer::canReinterpretAs<pcpp::iphdr>(unsigned char const*, unsigned long) Line | Count | Source | 523 | 945k | { | 524 | 945k | return data != nullptr && dataLen >= sizeof(T); | 525 | 945k | } |
bool pcpp::Layer::canReinterpretAs<pcpp::dhcp_header>(unsigned char const*, unsigned long) Line | Count | Source | 523 | 15.1k | { | 524 | 15.1k | return data != nullptr && dataLen >= sizeof(T); | 525 | 15.1k | } |
bool pcpp::Layer::canReinterpretAs<pcpp::vrrp_header>(unsigned char const*, unsigned long) Line | Count | Source | 523 | 7.22k | { | 524 | 7.22k | return data != nullptr && dataLen >= sizeof(T); | 525 | 7.22k | } |
bool pcpp::Layer::canReinterpretAs<pcpp::ip6_hdr>(unsigned char const*, unsigned long) Line | Count | Source | 523 | 168k | { | 524 | 168k | return data != nullptr && dataLen >= sizeof(T); | 525 | 168k | } |
bool pcpp::Layer::canReinterpretAs<pcpp::vlan_header>(unsigned char const*, unsigned long) Line | Count | Source | 523 | 155k | { | 524 | 155k | return data != nullptr && dataLen >= sizeof(T); | 525 | 155k | } |
Unexecuted instantiation: bool pcpp::Layer::canReinterpretAs<pcpp::MplsLayer::mpls_header>(unsigned char const*, unsigned long) bool pcpp::Layer::canReinterpretAs<pcpp::igmp_header>(unsigned char const*, unsigned long) Line | Count | Source | 523 | 10.8k | { | 524 | 10.8k | return data != nullptr && dataLen >= sizeof(T); | 525 | 10.8k | } |
bool pcpp::Layer::canReinterpretAs<pcpp::igmpv3_query_header>(unsigned char const*, unsigned long) Line | Count | Source | 523 | 1.71k | { | 524 | 1.71k | return data != nullptr && dataLen >= sizeof(T); | 525 | 1.71k | } |
bool pcpp::Layer::canReinterpretAs<pcpp::igmpv3_report_header>(unsigned char const*, unsigned long) Line | Count | Source | 523 | 2.23k | { | 524 | 2.23k | return data != nullptr && dataLen >= sizeof(T); | 525 | 2.23k | } |
bool pcpp::Layer::canReinterpretAs<pcpp::ssl_tls_record_layer>(unsigned char const*, unsigned long) Line | Count | Source | 523 | 220k | { | 524 | 220k | return data != nullptr && dataLen >= sizeof(T); | 525 | 220k | } |
bool pcpp::Layer::canReinterpretAs<pcpp::tpkthdr>(unsigned char const*, unsigned long) Line | Count | Source | 523 | 133k | { | 524 | 133k | return data != nullptr && dataLen >= sizeof(T); | 525 | 133k | } |
Unexecuted instantiation: bool pcpp::Layer::canReinterpretAs<pcpp::vxlan_header>(unsigned char const*, unsigned long) Unexecuted instantiation: bool pcpp::Layer::canReinterpretAs<pcpp::stp_tcn_bpdu>(unsigned char const*, unsigned long) Unexecuted instantiation: bool pcpp::Layer::canReinterpretAs<pcpp::stp_conf_bpdu>(unsigned char const*, unsigned long) Unexecuted instantiation: bool pcpp::Layer::canReinterpretAs<pcpp::rstp_conf_bpdu>(unsigned char const*, unsigned long) Unexecuted instantiation: bool pcpp::Layer::canReinterpretAs<pcpp::mstp_conf_bpdu>(unsigned char const*, unsigned long) |
526 | | }; |
527 | | |
528 | | inline std::ostream& operator<<(std::ostream& os, const pcpp::Layer& layer) |
529 | 0 | { |
530 | 0 | os << layer.toString(); |
531 | 0 | return os; |
532 | 0 | } |
533 | | } // namespace pcpp |