/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 "Serializers.h" |
7 | | #include <ostream> |
8 | | #include <string> |
9 | | #include <stdexcept> |
10 | | #include <utility> |
11 | | |
12 | | /// @file |
13 | | |
14 | | /// @namespace pcpp |
15 | | /// @brief The main namespace for the PcapPlusPlus lib |
16 | | namespace pcpp |
17 | | { |
18 | | |
19 | | /// @class IDataContainer |
20 | | /// An interface (virtual abstract class) that indicates an object that holds a pointer to a buffer data. The Layer |
21 | | /// class is an example of such object, hence it inherits this interface |
22 | | class IDataContainer |
23 | | { |
24 | | public: |
25 | | /// Get a pointer to the data |
26 | | /// @param[in] offset Get a pointer in a certain offset. Default is 0 - get a pointer to start of data |
27 | | /// @return A pointer to the data |
28 | | virtual uint8_t* getDataPtr(size_t offset = 0) const = 0; |
29 | | |
30 | 4.52M | virtual ~IDataContainer() = default; |
31 | | }; |
32 | | |
33 | | class Packet; |
34 | | |
35 | | namespace internal |
36 | | { |
37 | | /// @brief Holds information about a Layer's data and object ownership. |
38 | | struct LayerAllocationInfo |
39 | | { |
40 | | /// @brief Pointer to the Packet this layer is attached to (if any). |
41 | | /// |
42 | | /// If the layer is attached to a Packet, the layer's memory span (data) is considered managed by the |
43 | | /// Packet. The Packet is responsible for keeping the layer's memory span valid and updating it should it |
44 | | /// become necessary as long as the layer is attached to it. |
45 | | /// |
46 | | /// In an event the Packet is destroyed, all of its attached layers's memory views are considered invalid. |
47 | | /// Accessing layer data after the Packet is destroyed results in undefined behavior. |
48 | | /// |
49 | | /// If nullptr, the layer is not attached to any Packet and is considered unmanaged. |
50 | | /// It also means the layer's memory span is considered owned by the layer itself and will be freed when |
51 | | /// the layer is destroyed. |
52 | | Packet* attachedPacket = nullptr; |
53 | | |
54 | | /// @brief Controls if the layer object is considered owned by the attached Packet |
55 | | /// |
56 | | /// If 'true', the Layer object is considered owned by the attached Packet and will be freed by it on Packet |
57 | | /// destruction. |
58 | | /// |
59 | | /// If 'false', the Layer object is considered unmanaged and the user is responsible for freeing it. |
60 | | /// This is commonly the case for layers created on the stack and attached to a Packet. |
61 | | bool ownedByPacket = false; |
62 | | |
63 | | /// @brief Sets the state of attachment to a specified Packet |
64 | | /// @param packet Pointer to the Packet this layer is attached to (or nullptr if not attached to any Packet) |
65 | | /// @param managed True if the layer object's lifetime is to be managed by the Packet, false otherwise |
66 | | /// @param force If true, bypasses the check for existing attachment. Default is false. |
67 | | /// @throws std::runtime_error if the layer is already attached to a Packet and 'force' is false |
68 | | void attachPacket(Packet* packet, bool managed, bool force = false) |
69 | 0 | { |
70 | 0 | if (!force && attachedPacket != nullptr) |
71 | 0 | { |
72 | 0 | throw std::runtime_error("Layer is already attached to a Packet"); |
73 | 0 | } |
74 | | |
75 | 0 | attachedPacket = packet; |
76 | 0 | ownedByPacket = managed; |
77 | 0 | } |
78 | | |
79 | | /// @brief Clears the attachment to any Packet, resetting to unmanaged state. |
80 | | void detach() |
81 | 0 | { |
82 | 0 | attachedPacket = nullptr; |
83 | 0 | ownedByPacket = false; |
84 | 0 | } |
85 | | }; |
86 | | } // namespace internal |
87 | | |
88 | | /// @class Layer |
89 | | /// Layer is the base class for all protocol layers. Each protocol supported in PcapPlusPlus has a class that |
90 | | /// inherits Layer. |
91 | | /// The protocol layer class expose all properties and methods relevant for viewing and editing protocol fields. |
92 | | /// For example: a pointer to a structured header (e.g tcphdr, iphdr, etc.), protocol header size, payload size, |
93 | | /// compute fields that can be automatically computed, print protocol data to string, etc. |
94 | | /// Each protocol instance is obviously part of a protocol stack (which construct a packet). This protocol stack is |
95 | | /// represented in PcapPlusPlus in a linked list, and each layer is an element in this list. That's why each layer |
96 | | /// has properties to the next and previous layer in the protocol stack. The Layer class, as a base class, is |
97 | | /// abstract and the user can't create an instance of it (it has a private constructor). Each layer holds a pointer |
98 | | /// to the relevant place in the packet. The layer sees all the data from this pointer forward until the end of the |
99 | | /// packet. Here is an example packet showing this concept: |
100 | | /// |
101 | | /// @code{.unparsed} |
102 | | /// ==================================================== |
103 | | /// |Eth |IPv4 |TCP |Packet | |
104 | | /// |Header |Header |Header |Payload | |
105 | | /// ==================================================== |
106 | | /// |
107 | | /// |--------------------------------------------------| |
108 | | /// EthLayer data |
109 | | /// |---------------------------------------| |
110 | | /// IPv4Layer data |
111 | | /// |---------------------------| |
112 | | /// TcpLayer data |
113 | | /// |----------------| |
114 | | /// PayloadLayer data |
115 | | /// @endcode |
116 | | class Layer : public IDataContainer |
117 | | { |
118 | | friend class Packet; |
119 | | |
120 | | public: |
121 | | /// A destructor for this class. Frees the data if it was allocated by the layer constructor (see |
122 | | /// isAllocatedToPacket() for more info) |
123 | | ~Layer() override; |
124 | | |
125 | | /// @return A pointer to the next layer in the protocol stack or nullptr if the layer is the last one |
126 | | Layer* getNextLayer() const |
127 | 85.2M | { |
128 | 85.2M | return m_NextLayer; |
129 | 85.2M | } |
130 | | |
131 | | /// @return A pointer to the previous layer in the protocol stack or nullptr if the layer is the first one |
132 | | Layer* getPrevLayer() const |
133 | 1.25M | { |
134 | 1.25M | return m_PrevLayer; |
135 | 1.25M | } |
136 | | |
137 | | /// @return The protocol enum |
138 | | ProtocolType getProtocol() const |
139 | 61.4M | { |
140 | 61.4M | return m_Protocol; |
141 | 61.4M | } |
142 | | |
143 | | /// Check if the layer's protocol matches a protocol family |
144 | | /// @param protocolTypeFamily The protocol family to check |
145 | | /// @return True if the layer's protocol matches the protocol family, false otherwise |
146 | | bool isMemberOfProtocolFamily(ProtocolTypeFamily protocolTypeFamily) const; |
147 | | |
148 | | /// @return A pointer to the layer raw data. In most cases it'll be a pointer to the first byte of the header |
149 | | uint8_t* getData() const |
150 | 235k | { |
151 | 235k | return m_Data; |
152 | 235k | } |
153 | | |
154 | | /// @return The length in bytes of the data from the first byte of the header until the end of the packet |
155 | | size_t getDataLen() const |
156 | 2.42M | { |
157 | 2.42M | return m_DataLen; |
158 | 2.42M | } |
159 | | |
160 | | /// @return A pointer for the layer payload, meaning the first byte after the header |
161 | | uint8_t* getLayerPayload() const |
162 | 0 | { |
163 | 0 | return m_Data + getHeaderLen(); |
164 | 0 | } |
165 | | |
166 | | /// @return The size in bytes of the payload |
167 | | size_t getLayerPayloadSize() const |
168 | 26.2k | { |
169 | 26.2k | return m_DataLen - getHeaderLen(); |
170 | 26.2k | } |
171 | | |
172 | | /// Raw data in layers can come from one of sources: |
173 | | /// 1. from an existing packet - this is the case when parsing packets received from files or the network. In |
174 | | /// this case the data was already allocated by someone else, and layer only holds the pointer to the relevant |
175 | | /// place inside this data |
176 | | /// 2. when creating packets, data is allocated when layer is created. In this case the layer is responsible for |
177 | | /// freeing it as well |
178 | | /// |
179 | | /// @return Returns true if the data was allocated by an external source (a packet) or false if it was allocated |
180 | | /// by the layer itself |
181 | | bool isAllocatedToPacket() const |
182 | 4.52M | { |
183 | 4.52M | return m_AllocationInfo.attachedPacket != nullptr; |
184 | 4.52M | } |
185 | | |
186 | | /// @brief Copy the raw data of this layer to another array |
187 | | /// |
188 | | /// @warning The method does not perform any bounds checking on the destination array. The caller MUST ensure |
189 | | /// that the destination array has enough space to hold the getDataLen() bytes. |
190 | | /// |
191 | | /// @warning Prefer the overload of copyData() that accepts a destination size to ensure safe copying of data. |
192 | | /// |
193 | | /// @param[out] toArr The destination byte array |
194 | | void copyData(uint8_t* toArr) const; |
195 | | |
196 | | /// @brief Copy the raw data of this layer to another array, with a specified maximum size. |
197 | | /// |
198 | | /// The method copies up to 'destSize' bytes of the layer's raw data into the provided destination array. |
199 | | /// If the layer's data length is greater than 'destSize', only the first 'destSize' bytes will be copied. |
200 | | /// |
201 | | /// To ensure sufficient space is available in the destination array, use getDataLen() to determine the actual |
202 | | /// length of the layer's data before calling this method. |
203 | | /// |
204 | | /// @param[out] dest The destination byte array |
205 | | /// @param[in] destSize The maximum number of bytes to copy |
206 | | /// @return The number of bytes copied to the destination array. |
207 | | size_t copyData(uint8_t* dest, size_t destSize) const; |
208 | | |
209 | | /// @struct SerializedFields |
210 | | /// Field descriptors for the fields serialized by Layer::serialize(). |
211 | | struct SerializedFields |
212 | | { |
213 | | /// @return A vector containing all layer field descriptors. |
214 | | static std::vector<FieldDescriptor> all() |
215 | 0 | { |
216 | 0 | return { ProtocolName, ProtocolId, Length }; |
217 | 0 | } |
218 | | |
219 | | /// Field descriptor for the layer protocol name. |
220 | | static const FieldDescriptor ProtocolName; |
221 | | |
222 | | /// Field descriptor for the layer protocol ID. |
223 | | static const FieldDescriptor ProtocolId; |
224 | | |
225 | | /// Field descriptor for the layer length. |
226 | | static const FieldDescriptor Length; |
227 | | |
228 | | /// Maximum field ID used by the layer. |
229 | | static constexpr uint16_t MaxID = 1; |
230 | | }; |
231 | | |
232 | | /// Serialize the layer using the provided serializer. |
233 | | /// @param[in] serializer The serializer to use. |
234 | | void serialize(ISerializer& serializer) const; |
235 | | |
236 | | // implement abstract methods |
237 | | |
238 | | uint8_t* getDataPtr(size_t offset = 0) const override |
239 | 106k | { |
240 | 106k | return static_cast<uint8_t*>(m_Data + offset); |
241 | 106k | } |
242 | | |
243 | | // abstract methods |
244 | | |
245 | | /// Each layer is responsible for parsing the next layer |
246 | | virtual void parseNextLayer() = 0; |
247 | | |
248 | | /// @return The header length in bytes |
249 | | virtual size_t getHeaderLen() const = 0; |
250 | | |
251 | | /// Each layer can compute field values automatically using this method. This is an abstract method |
252 | | virtual void computeCalculateFields() = 0; |
253 | | |
254 | | /// @return A string representation of the layer most important data (should look like the layer description in |
255 | | /// Wireshark) |
256 | | virtual std::string toString() const = 0; |
257 | | |
258 | | /// @return The OSI Model layer this protocol belongs to |
259 | | virtual OsiModelLayer getOsiModelLayer() const = 0; |
260 | | |
261 | | protected: |
262 | | uint8_t* m_Data; |
263 | | size_t m_DataLen; |
264 | | ProtocolType m_Protocol; |
265 | | Layer* m_NextLayer; |
266 | | Layer* m_PrevLayer; |
267 | | |
268 | | private: |
269 | | internal::LayerAllocationInfo m_AllocationInfo; |
270 | | |
271 | | protected: |
272 | 0 | Layer() : m_Data(nullptr), m_DataLen(0), m_Protocol(UnknownProtocol), m_NextLayer(nullptr), m_PrevLayer(nullptr) |
273 | 0 | {} |
274 | | |
275 | | Layer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet, ProtocolType protocol = UnknownProtocol) |
276 | 4.40M | : m_Data(data), m_DataLen(dataLen), m_Protocol(protocol), m_NextLayer(nullptr), m_PrevLayer(prevLayer), |
277 | 4.40M | m_AllocationInfo{ packet, false } |
278 | 4.40M | {} |
279 | | |
280 | | // Copy c'tor |
281 | | Layer(const Layer& other); |
282 | | Layer& operator=(const Layer& other); |
283 | | |
284 | | /// @brief Get a pointer to the Packet this layer is attached to (if any). |
285 | | /// @return A pointer to the Packet this layer is attached to, or nullptr if the layer is not attached. |
286 | | Packet* getAttachedPacket() |
287 | 3.95M | { |
288 | 3.95M | return m_AllocationInfo.attachedPacket; |
289 | 3.95M | } |
290 | | |
291 | | /// @brief Get a pointer to the Packet this layer is attached to (if any). |
292 | | /// @return A const pointer to the Packet this layer is attached to, or nullptr if the layer is not attached. |
293 | | Packet const* getAttachedPacket() const |
294 | 3.78k | { |
295 | 3.78k | return m_AllocationInfo.attachedPacket; |
296 | 3.78k | } |
297 | | |
298 | | void setNextLayer(Layer* nextLayer) |
299 | 3.50M | { |
300 | 3.50M | m_NextLayer = nextLayer; |
301 | 3.50M | } |
302 | | void setPrevLayer(Layer* prevLayer) |
303 | 0 | { |
304 | 0 | m_PrevLayer = prevLayer; |
305 | 0 | } |
306 | | |
307 | | // ------ Memory Control Methods ----- |
308 | | // Used by derived classes to request buffer size changes. |
309 | | |
310 | | /// @brief Requests the layer to allocate a new data buffer of the specified length. |
311 | | /// |
312 | | /// If the layer is not attached to a Packet, it will allocate a new buffer of the specified length. |
313 | | /// If the layer is attached to a Packet, it will throw a std::logic_error, as that case is not yet supported. |
314 | | /// |
315 | | /// The primary use case for this method is initial allocation of the data buffer in derived classes. |
316 | | /// |
317 | | /// @param[in] dataLen The length of the new data buffer. |
318 | | /// @param[in] zeroInit If true, the new buffer will be zero-initialized. |
319 | | /// @throws std::runtime_error if the layer already has allocated data. |
320 | | /// @throws std::logic_error if the layer is attached to a Packet (not yet supported). |
321 | | void allocData(size_t dataLen, bool zeroInit = true); |
322 | | |
323 | | virtual bool extendLayer(int offsetInLayer, size_t numOfBytesToExtend); |
324 | | virtual bool shortenLayer(int offsetInLayer, size_t numOfBytesToShorten); |
325 | | |
326 | | bool hasNextLayer() const |
327 | 6.19M | { |
328 | 6.19M | return m_NextLayer != nullptr; |
329 | 6.19M | } |
330 | | |
331 | | /// @brief Construct the next layer in the protocol stack. No validation is performed on the data. |
332 | | /// |
333 | | /// This overload infers the Packet from the current layer. |
334 | | /// |
335 | | /// @tparam T The type of the layer to construct |
336 | | /// @tparam Args The types of the arguments to pass to the layer constructor |
337 | | /// @param data The data to construct the layer from |
338 | | /// @param dataLen The length of the data |
339 | | /// @param extraArgs Extra arguments to be forwarded to the layer constructor |
340 | | /// @return The constructed layer |
341 | | template <typename T, typename... Args> |
342 | | Layer* constructNextLayer(uint8_t* data, size_t dataLen, Args&&... extraArgs) |
343 | 215k | { |
344 | 215k | return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...); |
345 | 215k | } pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::PayloadLayer>(unsigned char*, unsigned long) Line | Count | Source | 343 | 92.1k | { | 344 | 92.1k | return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...); | 345 | 92.1k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::VrrpV3Layer, pcpp::IPAddress::AddressType>(unsigned char*, unsigned long, pcpp::IPAddress::AddressType&&) Line | Count | Source | 343 | 4.64k | { | 344 | 4.64k | return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...); | 345 | 4.64k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::DnsLayer>(unsigned char*, unsigned long) Line | Count | Source | 343 | 38.2k | { | 344 | 38.2k | return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...); | 345 | 38.2k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::RadiusLayer>(unsigned char*, unsigned long) Line | Count | Source | 343 | 21.8k | { | 344 | 21.8k | return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...); | 345 | 21.8k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::GtpV1Layer>(unsigned char*, unsigned long) Line | Count | Source | 343 | 21.7k | { | 344 | 21.7k | return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...); | 345 | 21.7k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::GtpV2Layer>(unsigned char*, unsigned long) Line | Count | Source | 343 | 8.59k | { | 344 | 8.59k | return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...); | 345 | 8.59k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::DhcpV6Layer>(unsigned char*, unsigned long) Line | Count | Source | 343 | 5.40k | { | 344 | 5.40k | return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...); | 345 | 5.40k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::NtpLayer>(unsigned char*, unsigned long) Line | Count | Source | 343 | 7.36k | { | 344 | 7.36k | return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...); | 345 | 7.36k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::WakeOnLanLayer>(unsigned char*, unsigned long) Line | Count | Source | 343 | 365 | { | 344 | 365 | return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...); | 345 | 365 | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::SdpLayer>(unsigned char*, unsigned long) Line | Count | Source | 343 | 15.2k | { | 344 | 15.2k | return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...); | 345 | 15.2k | } |
|
346 | | |
347 | | /// Construct the next layer in the protocol stack. No validation is performed on the data. |
348 | | /// @tparam T The type of the layer to construct |
349 | | /// @tparam Args The types of the arguments to pass to the layer constructor |
350 | | /// @param[in] data The data to construct the layer from |
351 | | /// @param[in] dataLen The length of the data |
352 | | /// @param[in] packet The packet the layer belongs to |
353 | | /// @param[in] extraArgs Extra arguments to be forwarded to the layer constructor |
354 | | /// @return The constructed layer |
355 | | template <typename T, typename... Args> |
356 | | Layer* constructNextLayer(uint8_t* data, size_t dataLen, Packet* packet, Args&&... extraArgs) |
357 | 2.90M | { |
358 | 2.90M | if (hasNextLayer()) |
359 | 0 | { |
360 | 0 | throw std::runtime_error("Next layer already exists"); |
361 | 0 | } |
362 | | |
363 | 2.90M | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); |
364 | 2.90M | setNextLayer(newLayer); |
365 | 2.90M | return newLayer; |
366 | 2.90M | } pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::IPv4Layer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 357 | 742k | { | 358 | 742k | if (hasNextLayer()) | 359 | 0 | { | 360 | 0 | throw std::runtime_error("Next layer already exists"); | 361 | 0 | } | 362 | | | 363 | 742k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 364 | 742k | setNextLayer(newLayer); | 365 | 742k | return newLayer; | 366 | 742k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 357 | 279k | { | 358 | 279k | if (hasNextLayer()) | 359 | 0 | { | 360 | 0 | throw std::runtime_error("Next layer already exists"); | 361 | 0 | } | 362 | | | 363 | 279k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 364 | 279k | setNextLayer(newLayer); | 365 | 279k | return newLayer; | 366 | 279k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::IPv6Layer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 357 | 162k | { | 358 | 162k | if (hasNextLayer()) | 359 | 0 | { | 360 | 0 | throw std::runtime_error("Next layer already exists"); | 361 | 0 | } | 362 | | | 363 | 162k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 364 | 162k | setNextLayer(newLayer); | 365 | 162k | return newLayer; | 366 | 162k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::VlanLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 357 | 60.4k | { | 358 | 60.4k | if (hasNextLayer()) | 359 | 0 | { | 360 | 0 | throw std::runtime_error("Next layer already exists"); | 361 | 0 | } | 362 | | | 363 | 60.4k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 364 | 60.4k | setNextLayer(newLayer); | 365 | 60.4k | return newLayer; | 366 | 60.4k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::MplsLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 357 | 343k | { | 358 | 343k | if (hasNextLayer()) | 359 | 0 | { | 360 | 0 | throw std::runtime_error("Next layer already exists"); | 361 | 0 | } | 362 | | | 363 | 343k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 364 | 343k | setNextLayer(newLayer); | 365 | 343k | return newLayer; | 366 | 343k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::PPP_PPTPLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 357 | 6.17k | { | 358 | 6.17k | if (hasNextLayer()) | 359 | 0 | { | 360 | 0 | throw std::runtime_error("Next layer already exists"); | 361 | 0 | } | 362 | | | 363 | 6.17k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 364 | 6.17k | setNextLayer(newLayer); | 365 | 6.17k | return newLayer; | 366 | 6.17k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::EthLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 357 | 6.01k | { | 358 | 6.01k | if (hasNextLayer()) | 359 | 0 | { | 360 | 0 | throw std::runtime_error("Next layer already exists"); | 361 | 0 | } | 362 | | | 363 | 6.01k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 364 | 6.01k | setNextLayer(newLayer); | 365 | 6.01k | return newLayer; | 366 | 6.01k | } |
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 | 357 | 16.9k | { | 358 | 16.9k | if (hasNextLayer()) | 359 | 0 | { | 360 | 0 | throw std::runtime_error("Next layer already exists"); | 361 | 0 | } | 362 | | | 363 | 16.9k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 364 | 16.9k | setNextLayer(newLayer); | 365 | 16.9k | return newLayer; | 366 | 16.9k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::UdpLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 357 | 250k | { | 358 | 250k | if (hasNextLayer()) | 359 | 0 | { | 360 | 0 | throw std::runtime_error("Next layer already exists"); | 361 | 0 | } | 362 | | | 363 | 250k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 364 | 250k | setNextLayer(newLayer); | 365 | 250k | return newLayer; | 366 | 250k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::TcpLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 357 | 576k | { | 358 | 576k | if (hasNextLayer()) | 359 | 0 | { | 360 | 0 | throw std::runtime_error("Next layer already exists"); | 361 | 0 | } | 362 | | | 363 | 576k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 364 | 576k | setNextLayer(newLayer); | 365 | 576k | return newLayer; | 366 | 576k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::IcmpLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 357 | 21.0k | { | 358 | 21.0k | if (hasNextLayer()) | 359 | 0 | { | 360 | 0 | throw std::runtime_error("Next layer already exists"); | 361 | 0 | } | 362 | | | 363 | 21.0k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 364 | 21.0k | setNextLayer(newLayer); | 365 | 21.0k | return newLayer; | 366 | 21.0k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::GREv0Layer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 357 | 15.8k | { | 358 | 15.8k | if (hasNextLayer()) | 359 | 0 | { | 360 | 0 | throw std::runtime_error("Next layer already exists"); | 361 | 0 | } | 362 | | | 363 | 15.8k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 364 | 15.8k | setNextLayer(newLayer); | 365 | 15.8k | return newLayer; | 366 | 15.8k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::GREv1Layer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 357 | 20.5k | { | 358 | 20.5k | if (hasNextLayer()) | 359 | 0 | { | 360 | 0 | throw std::runtime_error("Next layer already exists"); | 361 | 0 | } | 362 | | | 363 | 20.5k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 364 | 20.5k | setNextLayer(newLayer); | 365 | 20.5k | return newLayer; | 366 | 20.5k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::IgmpV1Layer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 357 | 2.87k | { | 358 | 2.87k | if (hasNextLayer()) | 359 | 0 | { | 360 | 0 | throw std::runtime_error("Next layer already exists"); | 361 | 0 | } | 362 | | | 363 | 2.87k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 364 | 2.87k | setNextLayer(newLayer); | 365 | 2.87k | return newLayer; | 366 | 2.87k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::IgmpV2Layer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 357 | 4.82k | { | 358 | 4.82k | if (hasNextLayer()) | 359 | 0 | { | 360 | 0 | throw std::runtime_error("Next layer already exists"); | 361 | 0 | } | 362 | | | 363 | 4.82k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 364 | 4.82k | setNextLayer(newLayer); | 365 | 4.82k | return newLayer; | 366 | 4.82k | } |
Unexecuted instantiation: pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::IgmpV3QueryLayer>(unsigned char*, unsigned long, pcpp::Packet*) pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::IgmpV3ReportLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 357 | 1.78k | { | 358 | 1.78k | if (hasNextLayer()) | 359 | 0 | { | 360 | 0 | throw std::runtime_error("Next layer already exists"); | 361 | 0 | } | 362 | | | 363 | 1.78k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 364 | 1.78k | setNextLayer(newLayer); | 365 | 1.78k | return newLayer; | 366 | 1.78k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::AuthenticationHeaderLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 357 | 1.42k | { | 358 | 1.42k | if (hasNextLayer()) | 359 | 0 | { | 360 | 0 | throw std::runtime_error("Next layer already exists"); | 361 | 0 | } | 362 | | | 363 | 1.42k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 364 | 1.42k | setNextLayer(newLayer); | 365 | 1.42k | return newLayer; | 366 | 1.42k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::ESPLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 357 | 95 | { | 358 | 95 | if (hasNextLayer()) | 359 | 0 | { | 360 | 0 | throw std::runtime_error("Next layer already exists"); | 361 | 0 | } | 362 | | | 363 | 95 | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 364 | 95 | setNextLayer(newLayer); | 365 | 95 | return newLayer; | 366 | 95 | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::VrrpV2Layer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 357 | 6.42k | { | 358 | 6.42k | if (hasNextLayer()) | 359 | 0 | { | 360 | 0 | throw std::runtime_error("Next layer already exists"); | 361 | 0 | } | 362 | | | 363 | 6.42k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 364 | 6.42k | setNextLayer(newLayer); | 365 | 6.42k | return newLayer; | 366 | 6.42k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::VrrpV3Layer, pcpp::IPAddress::AddressType>(unsigned char*, unsigned long, pcpp::Packet*, pcpp::IPAddress::AddressType&&) Line | Count | Source | 357 | 7.72k | { | 358 | 7.72k | if (hasNextLayer()) | 359 | 0 | { | 360 | 0 | throw std::runtime_error("Next layer already exists"); | 361 | 0 | } | 362 | | | 363 | 7.72k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 364 | 7.72k | setNextLayer(newLayer); | 365 | 7.72k | return newLayer; | 366 | 7.72k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::ArpLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 357 | 17.9k | { | 358 | 17.9k | if (hasNextLayer()) | 359 | 0 | { | 360 | 0 | throw std::runtime_error("Next layer already exists"); | 361 | 0 | } | 362 | | | 363 | 17.9k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 364 | 17.9k | setNextLayer(newLayer); | 365 | 17.9k | return newLayer; | 366 | 17.9k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::PPPoESessionLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 357 | 29.7k | { | 358 | 29.7k | if (hasNextLayer()) | 359 | 0 | { | 360 | 0 | throw std::runtime_error("Next layer already exists"); | 361 | 0 | } | 362 | | | 363 | 29.7k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 364 | 29.7k | setNextLayer(newLayer); | 365 | 29.7k | return newLayer; | 366 | 29.7k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::PPPoEDiscoveryLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 357 | 3.43k | { | 358 | 3.43k | if (hasNextLayer()) | 359 | 0 | { | 360 | 0 | throw std::runtime_error("Next layer already exists"); | 361 | 0 | } | 362 | | | 363 | 3.43k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 364 | 3.43k | setNextLayer(newLayer); | 365 | 3.43k | return newLayer; | 366 | 3.43k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::LLCLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 357 | 12.3k | { | 358 | 12.3k | if (hasNextLayer()) | 359 | 0 | { | 360 | 0 | throw std::runtime_error("Next layer already exists"); | 361 | 0 | } | 362 | | | 363 | 12.3k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 364 | 12.3k | setNextLayer(newLayer); | 365 | 12.3k | return newLayer; | 366 | 12.3k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::HttpRequestLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 357 | 75.4k | { | 358 | 75.4k | if (hasNextLayer()) | 359 | 0 | { | 360 | 0 | throw std::runtime_error("Next layer already exists"); | 361 | 0 | } | 362 | | | 363 | 75.4k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 364 | 75.4k | setNextLayer(newLayer); | 365 | 75.4k | return newLayer; | 366 | 75.4k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::HttpResponseLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 357 | 14.1k | { | 358 | 14.1k | if (hasNextLayer()) | 359 | 0 | { | 360 | 0 | throw std::runtime_error("Next layer already exists"); | 361 | 0 | } | 362 | | | 363 | 14.1k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 364 | 14.1k | setNextLayer(newLayer); | 365 | 14.1k | return newLayer; | 366 | 14.1k | } |
Unexecuted instantiation: pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::SipRequestLayer>(unsigned char*, unsigned long, pcpp::Packet*) pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::SipResponseLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 357 | 2.89k | { | 358 | 2.89k | if (hasNextLayer()) | 359 | 0 | { | 360 | 0 | throw std::runtime_error("Next layer already exists"); | 361 | 0 | } | 362 | | | 363 | 2.89k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 364 | 2.89k | setNextLayer(newLayer); | 365 | 2.89k | return newLayer; | 366 | 2.89k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::DnsOverTcpLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 357 | 3.26k | { | 358 | 3.26k | if (hasNextLayer()) | 359 | 0 | { | 360 | 0 | throw std::runtime_error("Next layer already exists"); | 361 | 0 | } | 362 | | | 363 | 3.26k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 364 | 3.26k | setNextLayer(newLayer); | 365 | 3.26k | return newLayer; | 366 | 3.26k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::TelnetLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 357 | 9.25k | { | 358 | 9.25k | if (hasNextLayer()) | 359 | 0 | { | 360 | 0 | throw std::runtime_error("Next layer already exists"); | 361 | 0 | } | 362 | | | 363 | 9.25k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 364 | 9.25k | setNextLayer(newLayer); | 365 | 9.25k | return newLayer; | 366 | 9.25k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::FtpResponseLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 357 | 13.2k | { | 358 | 13.2k | if (hasNextLayer()) | 359 | 0 | { | 360 | 0 | throw std::runtime_error("Next layer already exists"); | 361 | 0 | } | 362 | | | 363 | 13.2k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 364 | 13.2k | setNextLayer(newLayer); | 365 | 13.2k | return newLayer; | 366 | 13.2k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::FtpRequestLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 357 | 6.82k | { | 358 | 6.82k | if (hasNextLayer()) | 359 | 0 | { | 360 | 0 | throw std::runtime_error("Next layer already exists"); | 361 | 0 | } | 362 | | | 363 | 6.82k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 364 | 6.82k | setNextLayer(newLayer); | 365 | 6.82k | return newLayer; | 366 | 6.82k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::FtpDataLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 357 | 1.45k | { | 358 | 1.45k | if (hasNextLayer()) | 359 | 0 | { | 360 | 0 | throw std::runtime_error("Next layer already exists"); | 361 | 0 | } | 362 | | | 363 | 1.45k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 364 | 1.45k | setNextLayer(newLayer); | 365 | 1.45k | return newLayer; | 366 | 1.45k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::TpktLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 357 | 15.3k | { | 358 | 15.3k | if (hasNextLayer()) | 359 | 0 | { | 360 | 0 | throw std::runtime_error("Next layer already exists"); | 361 | 0 | } | 362 | | | 363 | 15.3k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 364 | 15.3k | setNextLayer(newLayer); | 365 | 15.3k | return newLayer; | 366 | 15.3k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::SmtpResponseLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 357 | 3.76k | { | 358 | 3.76k | if (hasNextLayer()) | 359 | 0 | { | 360 | 0 | throw std::runtime_error("Next layer already exists"); | 361 | 0 | } | 362 | | | 363 | 3.76k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 364 | 3.76k | setNextLayer(newLayer); | 365 | 3.76k | return newLayer; | 366 | 3.76k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::SmtpRequestLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 357 | 10.1k | { | 358 | 10.1k | if (hasNextLayer()) | 359 | 0 | { | 360 | 0 | throw std::runtime_error("Next layer already exists"); | 361 | 0 | } | 362 | | | 363 | 10.1k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 364 | 10.1k | setNextLayer(newLayer); | 365 | 10.1k | return newLayer; | 366 | 10.1k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::ModbusLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 357 | 1.68k | { | 358 | 1.68k | if (hasNextLayer()) | 359 | 0 | { | 360 | 0 | throw std::runtime_error("Next layer already exists"); | 361 | 0 | } | 362 | | | 363 | 1.68k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 364 | 1.68k | setNextLayer(newLayer); | 365 | 1.68k | return newLayer; | 366 | 1.68k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::CotpLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 357 | 13.1k | { | 358 | 13.1k | if (hasNextLayer()) | 359 | 0 | { | 360 | 0 | throw std::runtime_error("Next layer already exists"); | 361 | 0 | } | 362 | | | 363 | 13.1k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 364 | 13.1k | setNextLayer(newLayer); | 365 | 13.1k | return newLayer; | 366 | 13.1k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::DhcpLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 357 | 18.9k | { | 358 | 18.9k | if (hasNextLayer()) | 359 | 0 | { | 360 | 0 | throw std::runtime_error("Next layer already exists"); | 361 | 0 | } | 362 | | | 363 | 18.9k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 364 | 18.9k | setNextLayer(newLayer); | 365 | 18.9k | return newLayer; | 366 | 18.9k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::VxlanLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 357 | 6.12k | { | 358 | 6.12k | if (hasNextLayer()) | 359 | 0 | { | 360 | 0 | throw std::runtime_error("Next layer already exists"); | 361 | 0 | } | 362 | | | 363 | 6.12k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 364 | 6.12k | setNextLayer(newLayer); | 365 | 6.12k | return newLayer; | 366 | 6.12k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::DnsLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 357 | 38.2k | { | 358 | 38.2k | if (hasNextLayer()) | 359 | 0 | { | 360 | 0 | throw std::runtime_error("Next layer already exists"); | 361 | 0 | } | 362 | | | 363 | 38.2k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 364 | 38.2k | setNextLayer(newLayer); | 365 | 38.2k | return newLayer; | 366 | 38.2k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::RadiusLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 357 | 21.8k | { | 358 | 21.8k | if (hasNextLayer()) | 359 | 0 | { | 360 | 0 | throw std::runtime_error("Next layer already exists"); | 361 | 0 | } | 362 | | | 363 | 21.8k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 364 | 21.8k | setNextLayer(newLayer); | 365 | 21.8k | return newLayer; | 366 | 21.8k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::GtpV1Layer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 357 | 21.7k | { | 358 | 21.7k | if (hasNextLayer()) | 359 | 0 | { | 360 | 0 | throw std::runtime_error("Next layer already exists"); | 361 | 0 | } | 362 | | | 363 | 21.7k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 364 | 21.7k | setNextLayer(newLayer); | 365 | 21.7k | return newLayer; | 366 | 21.7k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::DhcpV6Layer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 357 | 5.40k | { | 358 | 5.40k | if (hasNextLayer()) | 359 | 0 | { | 360 | 0 | throw std::runtime_error("Next layer already exists"); | 361 | 0 | } | 362 | | | 363 | 5.40k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 364 | 5.40k | setNextLayer(newLayer); | 365 | 5.40k | return newLayer; | 366 | 5.40k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::NtpLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 357 | 7.36k | { | 358 | 7.36k | if (hasNextLayer()) | 359 | 0 | { | 360 | 0 | throw std::runtime_error("Next layer already exists"); | 361 | 0 | } | 362 | | | 363 | 7.36k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 364 | 7.36k | setNextLayer(newLayer); | 365 | 7.36k | return newLayer; | 366 | 7.36k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::WakeOnLanLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 357 | 428 | { | 358 | 428 | if (hasNextLayer()) | 359 | 0 | { | 360 | 0 | throw std::runtime_error("Next layer already exists"); | 361 | 0 | } | 362 | | | 363 | 428 | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 364 | 428 | setNextLayer(newLayer); | 365 | 428 | return newLayer; | 366 | 428 | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::S7CommLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 357 | 8.69k | { | 358 | 8.69k | if (hasNextLayer()) | 359 | 0 | { | 360 | 0 | throw std::runtime_error("Next layer already exists"); | 361 | 0 | } | 362 | | | 363 | 8.69k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 364 | 8.69k | setNextLayer(newLayer); | 365 | 8.69k | return newLayer; | 366 | 8.69k | } |
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::SdpLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 357 | 15.2k | { | 358 | 15.2k | if (hasNextLayer()) | 359 | 0 | { | 360 | 0 | throw std::runtime_error("Next layer already exists"); | 361 | 0 | } | 362 | | | 363 | 15.2k | Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 364 | 15.2k | setNextLayer(newLayer); | 365 | 15.2k | return newLayer; | 366 | 15.2k | } |
|
367 | | |
368 | | /// @brief Construct the next layer in the protocol stack using a factory functor. |
369 | | /// |
370 | | /// No validation is performed on the data, outside of what the factory functor may perform. |
371 | | /// If the factory returns a nullptr, no next layer is set. |
372 | | /// |
373 | | /// The factory functor is expected to have the following signature: |
374 | | /// Layer* factoryFn(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet, ...); |
375 | | /// |
376 | | /// This overload infers the Packet from the current layer. |
377 | | /// |
378 | | /// @tparam TFactory The factory functor type. |
379 | | /// @tparam ...Args Parameter pack for extra arguments to pass to the factory functor. |
380 | | /// @param[in] factoryFn The factory functor to create the layer. |
381 | | /// @param[in] data The data to construct the layer from |
382 | | /// @param[in] dataLen The length of the data |
383 | | /// @param[in] extraArgs Extra arguments to be forwarded to the factory. |
384 | | /// @return The return value of the factory functor. |
385 | | template <typename TFactory, typename... Args> |
386 | | Layer* constructNextLayerFromFactory(TFactory factoryFn, uint8_t* data, size_t dataLen, Args&&... extraArgs) |
387 | 456k | { |
388 | 456k | return constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, getAttachedPacket(), |
389 | 456k | std::forward<Args>(extraArgs)...); |
390 | 456k | } 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 | 387 | 37.6k | { | 388 | 37.6k | return constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, getAttachedPacket(), | 389 | 37.6k | std::forward<Args>(extraArgs)...); | 390 | 37.6k | } |
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 | 387 | 65.7k | { | 388 | 65.7k | return constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, getAttachedPacket(), | 389 | 65.7k | std::forward<Args>(extraArgs)...); | 390 | 65.7k | } |
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 | 387 | 332k | { | 388 | 332k | return constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, getAttachedPacket(), | 389 | 332k | std::forward<Args>(extraArgs)...); | 390 | 332k | } |
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 | 387 | 15.9k | { | 388 | 15.9k | return constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, getAttachedPacket(), | 389 | 15.9k | std::forward<Args>(extraArgs)...); | 390 | 15.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) Line | Count | Source | 387 | 50 | { | 388 | 50 | return constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, getAttachedPacket(), | 389 | 50 | std::forward<Args>(extraArgs)...); | 390 | 50 | } |
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) Line | Count | Source | 387 | 5.26k | { | 388 | 5.26k | return constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, getAttachedPacket(), | 389 | 5.26k | std::forward<Args>(extraArgs)...); | 390 | 5.26k | } |
|
391 | | |
392 | | /// @brief Construct the next layer in the protocol stack using a factory functor. |
393 | | /// |
394 | | /// No validation is performed on the data, outside of what the factory functor may perform. |
395 | | /// If the factory returns a nullptr, no next layer is set. |
396 | | /// |
397 | | /// The factory functor is expected to have the following signature: |
398 | | /// Layer* factoryFn(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet, ...); |
399 | | /// |
400 | | /// @tparam TFactory The factory functor type. |
401 | | /// @tparam ...Args Parameter pack for extra arguments to pass to the factory functor. |
402 | | /// @param[in] factoryFn The factory functor to create the layer. |
403 | | /// @param[in] data The data to construct the layer from |
404 | | /// @param[in] dataLen The length of the data |
405 | | /// @param[in] packet The packet the layer belongs to |
406 | | /// @param[in] extraArgs Extra arguments to be forwarded to the factory. |
407 | | /// @return The return value of the factory functor. |
408 | | template <typename TFactory, typename... Args> |
409 | | Layer* constructNextLayerFromFactory(TFactory factoryFn, uint8_t* data, size_t dataLen, Packet* packet, |
410 | | Args&&... extraArgs) |
411 | 576k | { |
412 | 576k | if (hasNextLayer()) |
413 | 0 | { |
414 | 0 | throw std::runtime_error("Next layer already exists"); |
415 | 0 | } |
416 | | |
417 | | // cppcheck-suppress redundantInitialization |
418 | 576k | Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); |
419 | 576k | setNextLayer(newLayer); |
420 | 576k | return newLayer; |
421 | 576k | } 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 | 411 | 68.4k | { | 412 | 68.4k | if (hasNextLayer()) | 413 | 0 | { | 414 | 0 | throw std::runtime_error("Next layer already exists"); | 415 | 0 | } | 416 | | | 417 | | // cppcheck-suppress redundantInitialization | 418 | 68.4k | Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 419 | 68.4k | setNextLayer(newLayer); | 420 | 68.4k | return newLayer; | 421 | 68.4k | } |
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 | 411 | 65.7k | { | 412 | 65.7k | if (hasNextLayer()) | 413 | 0 | { | 414 | 0 | throw std::runtime_error("Next layer already exists"); | 415 | 0 | } | 416 | | | 417 | | // cppcheck-suppress redundantInitialization | 418 | 65.7k | Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 419 | 65.7k | setNextLayer(newLayer); | 420 | 65.7k | return newLayer; | 421 | 65.7k | } |
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 | 411 | 332k | { | 412 | 332k | if (hasNextLayer()) | 413 | 0 | { | 414 | 0 | throw std::runtime_error("Next layer already exists"); | 415 | 0 | } | 416 | | | 417 | | // cppcheck-suppress redundantInitialization | 418 | 332k | Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 419 | 332k | setNextLayer(newLayer); | 420 | 332k | return newLayer; | 421 | 332k | } |
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 | 411 | 15.9k | { | 412 | 15.9k | if (hasNextLayer()) | 413 | 0 | { | 414 | 0 | throw std::runtime_error("Next layer already exists"); | 415 | 0 | } | 416 | | | 417 | | // cppcheck-suppress redundantInitialization | 418 | 15.9k | Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 419 | 15.9k | setNextLayer(newLayer); | 420 | 15.9k | return newLayer; | 421 | 15.9k | } |
Unexecuted instantiation: 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*) 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 | 411 | 1.72k | { | 412 | 1.72k | if (hasNextLayer()) | 413 | 0 | { | 414 | 0 | throw std::runtime_error("Next layer already exists"); | 415 | 0 | } | 416 | | | 417 | | // cppcheck-suppress redundantInitialization | 418 | 1.72k | Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 419 | 1.72k | setNextLayer(newLayer); | 420 | 1.72k | return newLayer; | 421 | 1.72k | } |
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 | 411 | 35 | { | 412 | 35 | if (hasNextLayer()) | 413 | 0 | { | 414 | 0 | throw std::runtime_error("Next layer already exists"); | 415 | 0 | } | 416 | | | 417 | | // cppcheck-suppress redundantInitialization | 418 | 35 | Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 419 | 35 | setNextLayer(newLayer); | 420 | 35 | return newLayer; | 421 | 35 | } |
pcpp::Layer* pcpp::Layer::constructNextLayerFromFactory<pcpp::MySqlLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*)>(pcpp::MySqlLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*), unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 411 | 17.2k | { | 412 | 17.2k | if (hasNextLayer()) | 413 | 0 | { | 414 | 0 | throw std::runtime_error("Next layer already exists"); | 415 | 0 | } | 416 | | | 417 | | // cppcheck-suppress redundantInitialization | 418 | 17.2k | Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 419 | 17.2k | setNextLayer(newLayer); | 420 | 17.2k | return newLayer; | 421 | 17.2k | } |
pcpp::Layer* pcpp::Layer::constructNextLayerFromFactory<pcpp::QuicV1Layer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*)>(pcpp::QuicV1Layer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*), unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 411 | 1.76k | { | 412 | 1.76k | if (hasNextLayer()) | 413 | 0 | { | 414 | 0 | throw std::runtime_error("Next layer already exists"); | 415 | 0 | } | 416 | | | 417 | | // cppcheck-suppress redundantInitialization | 418 | 1.76k | Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 419 | 1.76k | setNextLayer(newLayer); | 420 | 1.76k | return newLayer; | 421 | 1.76k | } |
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 | 411 | 17.7k | { | 412 | 17.7k | if (hasNextLayer()) | 413 | 0 | { | 414 | 0 | throw std::runtime_error("Next layer already exists"); | 415 | 0 | } | 416 | | | 417 | | // cppcheck-suppress redundantInitialization | 418 | 17.7k | Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 419 | 17.7k | setNextLayer(newLayer); | 420 | 17.7k | return newLayer; | 421 | 17.7k | } |
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 | 411 | 1.44k | { | 412 | 1.44k | if (hasNextLayer()) | 413 | 0 | { | 414 | 0 | throw std::runtime_error("Next layer already exists"); | 415 | 0 | } | 416 | | | 417 | | // cppcheck-suppress redundantInitialization | 418 | 1.44k | Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 419 | 1.44k | setNextLayer(newLayer); | 420 | 1.44k | return newLayer; | 421 | 1.44k | } |
Unexecuted instantiation: pcpp::Layer* pcpp::Layer::constructNextLayerFromFactory<pcpp::GvcpLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*)>(pcpp::GvcpLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*), unsigned char*, unsigned long, pcpp::Packet*) 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 | 411 | 49.3k | { | 412 | 49.3k | if (hasNextLayer()) | 413 | 0 | { | 414 | 0 | throw std::runtime_error("Next layer already exists"); | 415 | 0 | } | 416 | | | 417 | | // cppcheck-suppress redundantInitialization | 418 | 49.3k | Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 419 | 49.3k | setNextLayer(newLayer); | 420 | 49.3k | return newLayer; | 421 | 49.3k | } |
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*) Line | Count | Source | 411 | 5.26k | { | 412 | 5.26k | if (hasNextLayer()) | 413 | 0 | { | 414 | 0 | throw std::runtime_error("Next layer already exists"); | 415 | 0 | } | 416 | | | 417 | | // cppcheck-suppress redundantInitialization | 418 | 5.26k | Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...); | 419 | 5.26k | setNextLayer(newLayer); | 420 | 5.26k | return newLayer; | 421 | 5.26k | } |
|
422 | | |
423 | | /// Try to construct the next layer in the protocol stack. |
424 | | /// |
425 | | /// This overload infers the Packet from the current layer. |
426 | | /// |
427 | | /// The method checks if the data is valid for the layer type T before constructing it by calling |
428 | | /// T::isDataValid(data, dataLen). If the data is invalid, no layer is constructed and a nullptr is returned. |
429 | | /// |
430 | | /// @tparam T The type of the layer to construct |
431 | | /// @tparam Args The types of the extra arguments to pass to the layer constructor |
432 | | /// @param[in] data The data to construct the layer from |
433 | | /// @param[in] dataLen The length of the data |
434 | | /// @param[in] extraArgs Extra arguments to be forwarded to the layer constructor |
435 | | /// @return The constructed layer or nullptr if the data is invalid |
436 | | template <typename T, typename... Args> |
437 | | Layer* tryConstructNextLayer(uint8_t* data, size_t dataLen, Args&&... extraArgs) |
438 | 0 | { |
439 | 0 | return tryConstructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...); |
440 | 0 | } |
441 | | |
442 | | /// Try to construct the next layer in the protocol stack. |
443 | | /// |
444 | | /// The method checks if the data is valid for the layer type T before constructing it by calling |
445 | | /// T::isDataValid(data, dataLen). If the data is invalid, no layer is constructed and a nullptr is returned. |
446 | | /// |
447 | | /// @tparam T The type of the layer to construct |
448 | | /// @tparam Args The types of the extra arguments to pass to the layer constructor |
449 | | /// @param[in] data The data to construct the layer from |
450 | | /// @param[in] dataLen The length of the data |
451 | | /// @param[in] packet The packet the layer belongs to |
452 | | /// @param[in] extraArgs Extra arguments to be forwarded to the layer constructor |
453 | | /// @return The constructed layer or nullptr if the data is invalid |
454 | | template <typename T, typename... Args> |
455 | | Layer* tryConstructNextLayer(uint8_t* data, size_t dataLen, Packet* packet, Args&&... extraArgs) |
456 | 2.36M | { |
457 | 2.36M | if (T::isDataValid(data, dataLen)) |
458 | 2.34M | { |
459 | 2.34M | return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...); |
460 | 2.34M | } |
461 | 17.0k | return nullptr; |
462 | 2.36M | } pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::IPv4Layer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 456 | 747k | { | 457 | 747k | if (T::isDataValid(data, dataLen)) | 458 | 742k | { | 459 | 742k | return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...); | 460 | 742k | } | 461 | 5.00k | return nullptr; | 462 | 747k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::IPv6Layer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 456 | 163k | { | 457 | 163k | if (T::isDataValid(data, dataLen)) | 458 | 162k | { | 459 | 162k | return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...); | 460 | 162k | } | 461 | 365 | return nullptr; | 462 | 163k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::VlanLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 456 | 60.6k | { | 457 | 60.6k | if (T::isDataValid(data, dataLen)) | 458 | 60.4k | { | 459 | 60.4k | return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...); | 460 | 60.4k | } | 461 | 151 | return nullptr; | 462 | 60.6k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::MplsLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 456 | 343k | { | 457 | 343k | if (T::isDataValid(data, dataLen)) | 458 | 343k | { | 459 | 343k | return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...); | 460 | 343k | } | 461 | 0 | return nullptr; | 462 | 343k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::PPP_PPTPLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 456 | 6.57k | { | 457 | 6.57k | if (T::isDataValid(data, dataLen)) | 458 | 6.17k | { | 459 | 6.17k | return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...); | 460 | 6.17k | } | 461 | 392 | return nullptr; | 462 | 6.57k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::EthLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 456 | 6.12k | { | 457 | 6.12k | if (T::isDataValid(data, dataLen)) | 458 | 6.01k | { | 459 | 6.01k | return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...); | 460 | 6.01k | } | 461 | 103 | return nullptr; | 462 | 6.12k | } |
Unexecuted instantiation: pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::EthDot3Layer>(unsigned char*, unsigned long, pcpp::Packet*) pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::GtpV2Layer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 456 | 10.1k | { | 457 | 10.1k | if (T::isDataValid(data, dataLen)) | 458 | 8.31k | { | 459 | 8.31k | return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...); | 460 | 8.31k | } | 461 | 1.78k | return nullptr; | 462 | 10.1k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::UdpLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 456 | 250k | { | 457 | 250k | if (T::isDataValid(data, dataLen)) | 458 | 250k | { | 459 | 250k | return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...); | 460 | 250k | } | 461 | 47 | return nullptr; | 462 | 250k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::TcpLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 456 | 579k | { | 457 | 579k | if (T::isDataValid(data, dataLen)) | 458 | 576k | { | 459 | 576k | return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...); | 460 | 576k | } | 461 | 3.08k | return nullptr; | 462 | 579k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::IcmpLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 456 | 21.2k | { | 457 | 21.2k | if (T::isDataValid(data, dataLen)) | 458 | 21.0k | { | 459 | 21.0k | return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...); | 460 | 21.0k | } | 461 | 202 | return nullptr; | 462 | 21.2k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::GREv0Layer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 456 | 15.8k | { | 457 | 15.8k | if (T::isDataValid(data, dataLen)) | 458 | 15.8k | { | 459 | 15.8k | return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...); | 460 | 15.8k | } | 461 | 0 | return nullptr; | 462 | 15.8k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::GREv1Layer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 456 | 20.5k | { | 457 | 20.5k | if (T::isDataValid(data, dataLen)) | 458 | 20.5k | { | 459 | 20.5k | return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...); | 460 | 20.5k | } | 461 | 0 | return nullptr; | 462 | 20.5k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::IgmpV1Layer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 456 | 2.87k | { | 457 | 2.87k | if (T::isDataValid(data, dataLen)) | 458 | 2.87k | { | 459 | 2.87k | return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...); | 460 | 2.87k | } | 461 | 0 | return nullptr; | 462 | 2.87k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::IgmpV2Layer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 456 | 4.82k | { | 457 | 4.82k | if (T::isDataValid(data, dataLen)) | 458 | 4.82k | { | 459 | 4.82k | return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...); | 460 | 4.82k | } | 461 | 0 | return nullptr; | 462 | 4.82k | } |
Unexecuted instantiation: pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::IgmpV3QueryLayer>(unsigned char*, unsigned long, pcpp::Packet*) pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::IgmpV3ReportLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 456 | 1.78k | { | 457 | 1.78k | if (T::isDataValid(data, dataLen)) | 458 | 1.78k | { | 459 | 1.78k | return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...); | 460 | 1.78k | } | 461 | 0 | return nullptr; | 462 | 1.78k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::AuthenticationHeaderLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 456 | 1.42k | { | 457 | 1.42k | if (T::isDataValid(data, dataLen)) | 458 | 1.42k | { | 459 | 1.42k | return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...); | 460 | 1.42k | } | 461 | 6 | return nullptr; | 462 | 1.42k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::ESPLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 456 | 95 | { | 457 | 95 | if (T::isDataValid(data, dataLen)) | 458 | 95 | { | 459 | 95 | return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...); | 460 | 95 | } | 461 | 0 | return nullptr; | 462 | 95 | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::VrrpV2Layer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 456 | 6.42k | { | 457 | 6.42k | if (T::isDataValid(data, dataLen)) | 458 | 6.42k | { | 459 | 6.42k | return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...); | 460 | 6.42k | } | 461 | 0 | return nullptr; | 462 | 6.42k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::VrrpV3Layer, pcpp::IPAddress::AddressType>(unsigned char*, unsigned long, pcpp::Packet*, pcpp::IPAddress::AddressType&&) Line | Count | Source | 456 | 3.07k | { | 457 | 3.07k | if (T::isDataValid(data, dataLen)) | 458 | 3.07k | { | 459 | 3.07k | return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...); | 460 | 3.07k | } | 461 | 0 | return nullptr; | 462 | 3.07k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::ArpLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 456 | 18.0k | { | 457 | 18.0k | if (T::isDataValid(data, dataLen)) | 458 | 17.9k | { | 459 | 17.9k | return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...); | 460 | 17.9k | } | 461 | 132 | return nullptr; | 462 | 18.0k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::PPPoESessionLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 456 | 29.8k | { | 457 | 29.8k | if (T::isDataValid(data, dataLen)) | 458 | 29.7k | { | 459 | 29.7k | return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...); | 460 | 29.7k | } | 461 | 128 | return nullptr; | 462 | 29.8k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::PPPoEDiscoveryLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 456 | 3.43k | { | 457 | 3.43k | if (T::isDataValid(data, dataLen)) | 458 | 3.43k | { | 459 | 3.43k | return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...); | 460 | 3.43k | } | 461 | 0 | return nullptr; | 462 | 3.43k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::LLCLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 456 | 13.6k | { | 457 | 13.6k | if (T::isDataValid(data, dataLen)) | 458 | 12.3k | { | 459 | 12.3k | return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...); | 460 | 12.3k | } | 461 | 1.31k | return nullptr; | 462 | 13.6k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::CotpLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 456 | 15.2k | { | 457 | 15.2k | if (T::isDataValid(data, dataLen)) | 458 | 13.1k | { | 459 | 13.1k | return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...); | 460 | 13.1k | } | 461 | 2.11k | return nullptr; | 462 | 15.2k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::DhcpLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 456 | 19.3k | { | 457 | 19.3k | if (T::isDataValid(data, dataLen)) | 458 | 18.9k | { | 459 | 18.9k | return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...); | 460 | 18.9k | } | 461 | 396 | return nullptr; | 462 | 19.3k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::VxlanLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 456 | 6.12k | { | 457 | 6.12k | if (T::isDataValid(data, dataLen)) | 458 | 6.12k | { | 459 | 6.12k | return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...); | 460 | 6.12k | } | 461 | 0 | return nullptr; | 462 | 6.12k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::S7CommLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 456 | 10.2k | { | 457 | 10.2k | if (T::isDataValid(data, dataLen)) | 458 | 8.69k | { | 459 | 8.69k | return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...); | 460 | 8.69k | } | 461 | 1.59k | return nullptr; | 462 | 10.2k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::WakeOnLanLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 456 | 342 | { | 457 | 342 | if (T::isDataValid(data, dataLen)) | 458 | 63 | { | 459 | 63 | return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...); | 460 | 63 | } | 461 | 279 | return nullptr; | 462 | 342 | } |
|
463 | | |
464 | | /// @brief Try to construct the next layer in the protocol stack with a fallback option. |
465 | | /// |
466 | | /// This overload infers the Packet from the current layer. |
467 | | /// |
468 | | /// The method checks if the data is valid for the layer type T before constructing it by calling |
469 | | /// T::isDataValid(data, dataLen). If the data is invalid, it constructs the layer of type TFallback. |
470 | | /// |
471 | | /// @tparam T The type of the layer to construct |
472 | | /// @tparam TFallback The fallback layer type to construct if T fails |
473 | | /// @tparam Args The types of the extra arguments to pass to the layer constructor of T |
474 | | /// @param[in] data The data to construct the layer from |
475 | | /// @param[in] dataLen The length of the data |
476 | | /// @param[in] extraArgs Extra arguments to be forwarded to the layer constructor of T |
477 | | /// @return The constructed layer of type T or TFallback |
478 | | /// @remarks The parameters extraArgs are forwarded to the factory function, but not to the TFallback |
479 | | /// constructor. |
480 | | template <typename T, typename TFallback, typename... Args> |
481 | | Layer* tryConstructNextLayerWithFallback(uint8_t* data, size_t dataLen, Args&&... extraArgs) |
482 | 1.59M | { |
483 | 1.59M | return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(), |
484 | 1.59M | std::forward<Args>(extraArgs)...); |
485 | 1.59M | } pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::IPv4Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long) Line | Count | Source | 482 | 747k | { | 483 | 747k | return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(), | 484 | 747k | std::forward<Args>(extraArgs)...); | 485 | 747k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::IPv6Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long) Line | Count | Source | 482 | 156k | { | 483 | 156k | return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(), | 484 | 156k | std::forward<Args>(extraArgs)...); | 485 | 156k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::VlanLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long) Line | Count | Source | 482 | 60.6k | { | 483 | 60.6k | return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(), | 484 | 60.6k | std::forward<Args>(extraArgs)...); | 485 | 60.6k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::MplsLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long) Line | Count | Source | 482 | 343k | { | 483 | 343k | return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(), | 484 | 343k | std::forward<Args>(extraArgs)...); | 485 | 343k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::PPP_PPTPLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long) Line | Count | Source | 482 | 6.57k | { | 483 | 6.57k | return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(), | 484 | 6.57k | std::forward<Args>(extraArgs)...); | 485 | 6.57k | } |
Unexecuted instantiation: pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::EthDot3Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long) pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::GtpV2Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long) Line | Count | Source | 482 | 10.1k | { | 483 | 10.1k | return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(), | 484 | 10.1k | std::forward<Args>(extraArgs)...); | 485 | 10.1k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::UdpLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long) Line | Count | Source | 482 | 11.1k | { | 483 | 11.1k | return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(), | 484 | 11.1k | std::forward<Args>(extraArgs)...); | 485 | 11.1k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::TcpLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long) Line | Count | Source | 482 | 134k | { | 483 | 134k | return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(), | 484 | 134k | std::forward<Args>(extraArgs)...); | 485 | 134k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::GREv0Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long) Line | Count | Source | 482 | 2.83k | { | 483 | 2.83k | return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(), | 484 | 2.83k | std::forward<Args>(extraArgs)...); | 485 | 2.83k | } |
Unexecuted instantiation: pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::GREv1Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long) 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 | 482 | 15 | { | 483 | 15 | return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(), | 484 | 15 | std::forward<Args>(extraArgs)...); | 485 | 15 | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::ArpLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long) Line | Count | Source | 482 | 18.0k | { | 483 | 18.0k | return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(), | 484 | 18.0k | std::forward<Args>(extraArgs)...); | 485 | 18.0k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::PPPoESessionLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long) Line | Count | Source | 482 | 29.8k | { | 483 | 29.8k | return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(), | 484 | 29.8k | std::forward<Args>(extraArgs)...); | 485 | 29.8k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::PPPoEDiscoveryLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long) Line | Count | Source | 482 | 3.43k | { | 483 | 3.43k | return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(), | 484 | 3.43k | std::forward<Args>(extraArgs)...); | 485 | 3.43k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::LLCLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long) Line | Count | Source | 482 | 13.6k | { | 483 | 13.6k | return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(), | 484 | 13.6k | std::forward<Args>(extraArgs)...); | 485 | 13.6k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::CotpLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long) Line | Count | Source | 482 | 15.2k | { | 483 | 15.2k | return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(), | 484 | 15.2k | std::forward<Args>(extraArgs)...); | 485 | 15.2k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::DhcpLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long) Line | Count | Source | 482 | 19.3k | { | 483 | 19.3k | return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(), | 484 | 19.3k | std::forward<Args>(extraArgs)...); | 485 | 19.3k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::VxlanLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long) Line | Count | Source | 482 | 6.12k | { | 483 | 6.12k | return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(), | 484 | 6.12k | std::forward<Args>(extraArgs)...); | 485 | 6.12k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::EthLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long) Line | Count | Source | 482 | 6.12k | { | 483 | 6.12k | return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(), | 484 | 6.12k | std::forward<Args>(extraArgs)...); | 485 | 6.12k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::S7CommLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long) Line | Count | Source | 482 | 10.2k | { | 483 | 10.2k | return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(), | 484 | 10.2k | std::forward<Args>(extraArgs)...); | 485 | 10.2k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::WakeOnLanLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long) Line | Count | Source | 482 | 342 | { | 483 | 342 | return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(), | 484 | 342 | std::forward<Args>(extraArgs)...); | 485 | 342 | } |
|
486 | | |
487 | | /// Try to construct the next layer in the protocol stack with a fallback option. |
488 | | /// |
489 | | /// The method checks if the data is valid for the layer type T before constructing it by calling |
490 | | /// T::isDataValid(data, dataLen). If the data is invalid, it constructs the layer of type TFallback. |
491 | | /// |
492 | | /// @tparam T The type of the layer to construct |
493 | | /// @tparam TFallback The fallback layer type to construct if T fails |
494 | | /// @tparam Args The types of the extra arguments to pass to the layer constructor of T |
495 | | /// @param[in] data The data to construct the layer from |
496 | | /// @param[in] dataLen The length of the data |
497 | | /// @param[in] packet The packet the layer belongs to |
498 | | /// @param[in] extraArgs Extra arguments to be forwarded to the layer constructor of T |
499 | | /// @return The constructed layer of type T or TFallback |
500 | | /// @remarks The parameters extraArgs are forwarded to the factory function, but not to the TFallback |
501 | | /// constructor. |
502 | | template <typename T, typename TFallback, typename... Args> |
503 | | Layer* tryConstructNextLayerWithFallback(uint8_t* data, size_t dataLen, Packet* packet, Args&&... extraArgs) |
504 | 2.36M | { |
505 | 2.36M | if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...)) |
506 | 2.34M | { |
507 | 2.34M | return m_NextLayer; |
508 | 2.34M | } |
509 | | |
510 | 17.0k | return constructNextLayer<TFallback>(data, dataLen, packet); |
511 | 2.36M | } pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::IPv4Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 504 | 747k | { | 505 | 747k | if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...)) | 506 | 742k | { | 507 | 742k | return m_NextLayer; | 508 | 742k | } | 509 | | | 510 | 5.00k | return constructNextLayer<TFallback>(data, dataLen, packet); | 511 | 747k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::IPv6Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 504 | 163k | { | 505 | 163k | if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...)) | 506 | 162k | { | 507 | 162k | return m_NextLayer; | 508 | 162k | } | 509 | | | 510 | 365 | return constructNextLayer<TFallback>(data, dataLen, packet); | 511 | 163k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::VlanLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 504 | 60.6k | { | 505 | 60.6k | if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...)) | 506 | 60.4k | { | 507 | 60.4k | return m_NextLayer; | 508 | 60.4k | } | 509 | | | 510 | 151 | return constructNextLayer<TFallback>(data, dataLen, packet); | 511 | 60.6k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::MplsLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 504 | 343k | { | 505 | 343k | if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...)) | 506 | 343k | { | 507 | 343k | return m_NextLayer; | 508 | 343k | } | 509 | | | 510 | 0 | return constructNextLayer<TFallback>(data, dataLen, packet); | 511 | 343k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::PPP_PPTPLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 504 | 6.57k | { | 505 | 6.57k | if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...)) | 506 | 6.17k | { | 507 | 6.17k | return m_NextLayer; | 508 | 6.17k | } | 509 | | | 510 | 392 | return constructNextLayer<TFallback>(data, dataLen, packet); | 511 | 6.57k | } |
Unexecuted instantiation: pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::EthDot3Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*) pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::GtpV2Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 504 | 10.1k | { | 505 | 10.1k | if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...)) | 506 | 8.31k | { | 507 | 8.31k | return m_NextLayer; | 508 | 8.31k | } | 509 | | | 510 | 1.78k | return constructNextLayer<TFallback>(data, dataLen, packet); | 511 | 10.1k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::UdpLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 504 | 250k | { | 505 | 250k | if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...)) | 506 | 250k | { | 507 | 250k | return m_NextLayer; | 508 | 250k | } | 509 | | | 510 | 47 | return constructNextLayer<TFallback>(data, dataLen, packet); | 511 | 250k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::TcpLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 504 | 579k | { | 505 | 579k | if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...)) | 506 | 576k | { | 507 | 576k | return m_NextLayer; | 508 | 576k | } | 509 | | | 510 | 3.08k | return constructNextLayer<TFallback>(data, dataLen, packet); | 511 | 579k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::IcmpLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 504 | 21.2k | { | 505 | 21.2k | if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...)) | 506 | 21.0k | { | 507 | 21.0k | return m_NextLayer; | 508 | 21.0k | } | 509 | | | 510 | 202 | return constructNextLayer<TFallback>(data, dataLen, packet); | 511 | 21.2k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::GREv0Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 504 | 15.8k | { | 505 | 15.8k | if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...)) | 506 | 15.8k | { | 507 | 15.8k | return m_NextLayer; | 508 | 15.8k | } | 509 | | | 510 | 0 | return constructNextLayer<TFallback>(data, dataLen, packet); | 511 | 15.8k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::GREv1Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 504 | 20.5k | { | 505 | 20.5k | if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...)) | 506 | 20.5k | { | 507 | 20.5k | return m_NextLayer; | 508 | 20.5k | } | 509 | | | 510 | 0 | return constructNextLayer<TFallback>(data, dataLen, packet); | 511 | 20.5k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::IgmpV1Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 504 | 2.87k | { | 505 | 2.87k | if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...)) | 506 | 2.87k | { | 507 | 2.87k | return m_NextLayer; | 508 | 2.87k | } | 509 | | | 510 | 0 | return constructNextLayer<TFallback>(data, dataLen, packet); | 511 | 2.87k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::IgmpV2Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 504 | 4.82k | { | 505 | 4.82k | if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...)) | 506 | 4.82k | { | 507 | 4.82k | return m_NextLayer; | 508 | 4.82k | } | 509 | | | 510 | 0 | return constructNextLayer<TFallback>(data, dataLen, packet); | 511 | 4.82k | } |
Unexecuted instantiation: pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::IgmpV3QueryLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*) pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::IgmpV3ReportLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 504 | 1.78k | { | 505 | 1.78k | if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...)) | 506 | 1.78k | { | 507 | 1.78k | return m_NextLayer; | 508 | 1.78k | } | 509 | | | 510 | 0 | return constructNextLayer<TFallback>(data, dataLen, packet); | 511 | 1.78k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::AuthenticationHeaderLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 504 | 1.42k | { | 505 | 1.42k | if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...)) | 506 | 1.42k | { | 507 | 1.42k | return m_NextLayer; | 508 | 1.42k | } | 509 | | | 510 | 6 | return constructNextLayer<TFallback>(data, dataLen, packet); | 511 | 1.42k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::ESPLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 504 | 95 | { | 505 | 95 | if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...)) | 506 | 95 | { | 507 | 95 | return m_NextLayer; | 508 | 95 | } | 509 | | | 510 | 0 | return constructNextLayer<TFallback>(data, dataLen, packet); | 511 | 95 | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::VrrpV2Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 504 | 6.42k | { | 505 | 6.42k | if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...)) | 506 | 6.42k | { | 507 | 6.42k | return m_NextLayer; | 508 | 6.42k | } | 509 | | | 510 | 0 | return constructNextLayer<TFallback>(data, dataLen, packet); | 511 | 6.42k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::VrrpV3Layer, pcpp::PayloadLayer, pcpp::IPAddress::AddressType>(unsigned char*, unsigned long, pcpp::Packet*, pcpp::IPAddress::AddressType&&) Line | Count | Source | 504 | 3.07k | { | 505 | 3.07k | if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...)) | 506 | 3.07k | { | 507 | 3.07k | return m_NextLayer; | 508 | 3.07k | } | 509 | | | 510 | 0 | return constructNextLayer<TFallback>(data, dataLen, packet); | 511 | 3.07k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::ArpLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 504 | 18.0k | { | 505 | 18.0k | if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...)) | 506 | 17.9k | { | 507 | 17.9k | return m_NextLayer; | 508 | 17.9k | } | 509 | | | 510 | 132 | return constructNextLayer<TFallback>(data, dataLen, packet); | 511 | 18.0k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::PPPoESessionLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 504 | 29.8k | { | 505 | 29.8k | if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...)) | 506 | 29.7k | { | 507 | 29.7k | return m_NextLayer; | 508 | 29.7k | } | 509 | | | 510 | 128 | return constructNextLayer<TFallback>(data, dataLen, packet); | 511 | 29.8k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::PPPoEDiscoveryLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 504 | 3.43k | { | 505 | 3.43k | if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...)) | 506 | 3.43k | { | 507 | 3.43k | return m_NextLayer; | 508 | 3.43k | } | 509 | | | 510 | 0 | return constructNextLayer<TFallback>(data, dataLen, packet); | 511 | 3.43k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::LLCLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 504 | 13.6k | { | 505 | 13.6k | if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...)) | 506 | 12.3k | { | 507 | 12.3k | return m_NextLayer; | 508 | 12.3k | } | 509 | | | 510 | 1.31k | return constructNextLayer<TFallback>(data, dataLen, packet); | 511 | 13.6k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::CotpLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 504 | 15.2k | { | 505 | 15.2k | if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...)) | 506 | 13.1k | { | 507 | 13.1k | return m_NextLayer; | 508 | 13.1k | } | 509 | | | 510 | 2.11k | return constructNextLayer<TFallback>(data, dataLen, packet); | 511 | 15.2k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::DhcpLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 504 | 19.3k | { | 505 | 19.3k | if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...)) | 506 | 18.9k | { | 507 | 18.9k | return m_NextLayer; | 508 | 18.9k | } | 509 | | | 510 | 396 | return constructNextLayer<TFallback>(data, dataLen, packet); | 511 | 19.3k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::VxlanLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 504 | 6.12k | { | 505 | 6.12k | if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...)) | 506 | 6.12k | { | 507 | 6.12k | return m_NextLayer; | 508 | 6.12k | } | 509 | | | 510 | 0 | return constructNextLayer<TFallback>(data, dataLen, packet); | 511 | 6.12k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::EthLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 504 | 6.12k | { | 505 | 6.12k | if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...)) | 506 | 6.01k | { | 507 | 6.01k | return m_NextLayer; | 508 | 6.01k | } | 509 | | | 510 | 103 | return constructNextLayer<TFallback>(data, dataLen, packet); | 511 | 6.12k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::S7CommLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 504 | 10.2k | { | 505 | 10.2k | if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...)) | 506 | 8.69k | { | 507 | 8.69k | return m_NextLayer; | 508 | 8.69k | } | 509 | | | 510 | 1.59k | return constructNextLayer<TFallback>(data, dataLen, packet); | 511 | 10.2k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::WakeOnLanLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 504 | 342 | { | 505 | 342 | if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...)) | 506 | 63 | { | 507 | 63 | return m_NextLayer; | 508 | 63 | } | 509 | | | 510 | 279 | return constructNextLayer<TFallback>(data, dataLen, packet); | 511 | 342 | } |
|
512 | | |
513 | | /// @brief Try to construct the next layer in the protocol stack using a factory functor with a fallback option. |
514 | | /// |
515 | | /// The method will attempt to construct the next layer using the provided factory function. |
516 | | /// If the factory function returns nullptr, indicating failure to create the layer, the method will then |
517 | | /// construct a layer of type TFallback. |
518 | | /// |
519 | | /// The factory functor is expected to have the following signature: |
520 | | /// Layer* factoryFn(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet, ...); |
521 | | /// |
522 | | /// This overload infers the Packet from the current layer. |
523 | | /// |
524 | | /// @tparam TFallback The fallback layer type to construct if the factory fails. |
525 | | /// @tparam TFactory The factory functor type. |
526 | | /// @tparam ...Args Parameter pack for extra arguments to pass to the factory functor. |
527 | | /// @param[in] factoryFn The factory functor to create the layer. |
528 | | /// @param[in] data The data to construct the layer from |
529 | | /// @param[in] dataLen The length of the data |
530 | | /// @param[in] extraArgs Extra arguments to be forwarded to the factory. |
531 | | /// @return The return value of the factory functor. |
532 | | /// @remarks The parameters extraArgs are forwarded to the factory function, but not to the TFallback |
533 | | /// constructor. |
534 | | template <typename TFallback, typename TFactory, typename... Args> |
535 | | Layer* tryConstructNextLayerFromFactoryWithFallback(TFactory factoryFn, uint8_t* data, size_t dataLen, |
536 | | Args&&... extraArgs) |
537 | 120k | { |
538 | | // Note that the fallback is first to allow template argument deduction of the factory type. |
539 | 120k | return tryConstructNextLayerFromFactoryWithFallback<TFallback, TFactory>( |
540 | 120k | factoryFn, data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...); |
541 | 120k | } 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 | 537 | 30.8k | { | 538 | | // Note that the fallback is first to allow template argument deduction of the factory type. | 539 | 30.8k | return tryConstructNextLayerFromFactoryWithFallback<TFallback, TFactory>( | 540 | 30.8k | factoryFn, data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...); | 541 | 30.8k | } |
Unexecuted instantiation: 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::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 | 537 | 1.67k | { | 538 | | // Note that the fallback is first to allow template argument deduction of the factory type. | 539 | 1.67k | return tryConstructNextLayerFromFactoryWithFallback<TFallback, TFactory>( | 540 | 1.67k | factoryFn, data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...); | 541 | 1.67k | } |
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 | 537 | 35 | { | 538 | | // Note that the fallback is first to allow template argument deduction of the factory type. | 539 | 35 | return tryConstructNextLayerFromFactoryWithFallback<TFallback, TFactory>( | 540 | 35 | factoryFn, data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...); | 541 | 35 | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerFromFactoryWithFallback<pcpp::PayloadLayer, pcpp::MySqlLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*)>(pcpp::MySqlLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*), unsigned char*, unsigned long) Line | Count | Source | 537 | 17.2k | { | 538 | | // Note that the fallback is first to allow template argument deduction of the factory type. | 539 | 17.2k | return tryConstructNextLayerFromFactoryWithFallback<TFallback, TFactory>( | 540 | 17.2k | factoryFn, data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...); | 541 | 17.2k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerFromFactoryWithFallback<pcpp::PayloadLayer, pcpp::QuicV1Layer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*)>(pcpp::QuicV1Layer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*), unsigned char*, unsigned long) Line | Count | Source | 537 | 1.76k | { | 538 | | // Note that the fallback is first to allow template argument deduction of the factory type. | 539 | 1.76k | return tryConstructNextLayerFromFactoryWithFallback<TFallback, TFactory>( | 540 | 1.76k | factoryFn, data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...); | 541 | 1.76k | } |
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 | 537 | 17.7k | { | 538 | | // Note that the fallback is first to allow template argument deduction of the factory type. | 539 | 17.7k | return tryConstructNextLayerFromFactoryWithFallback<TFallback, TFactory>( | 540 | 17.7k | factoryFn, data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...); | 541 | 17.7k | } |
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 | 537 | 1.44k | { | 538 | | // Note that the fallback is first to allow template argument deduction of the factory type. | 539 | 1.44k | return tryConstructNextLayerFromFactoryWithFallback<TFallback, TFactory>( | 540 | 1.44k | factoryFn, data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...); | 541 | 1.44k | } |
Unexecuted instantiation: pcpp::Layer* pcpp::Layer::tryConstructNextLayerFromFactoryWithFallback<pcpp::PayloadLayer, pcpp::GvcpLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*)>(pcpp::GvcpLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*), unsigned char*, unsigned long) 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 | 537 | 49.3k | { | 538 | | // Note that the fallback is first to allow template argument deduction of the factory type. | 539 | 49.3k | return tryConstructNextLayerFromFactoryWithFallback<TFallback, TFactory>( | 540 | 49.3k | factoryFn, data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...); | 541 | 49.3k | } |
|
542 | | |
543 | | /// @brief Try to construct the next layer in the protocol stack using a factory functor with a fallback option. |
544 | | /// |
545 | | /// The method will attempt to construct the next layer using the provided factory function. |
546 | | /// If the factory function returns nullptr, indicating failure to create the layer, the method will then |
547 | | /// construct a layer of type TFallback. |
548 | | /// |
549 | | /// The factory functor is expected to have the following signature: |
550 | | /// Layer* factoryFn(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet, ...); |
551 | | /// |
552 | | /// @tparam TFallback The fallback layer type to construct if the factory fails. |
553 | | /// @tparam TFactory The factory functor type. |
554 | | /// @tparam ...Args Parameter pack for extra arguments to pass to the factory functor. |
555 | | /// @param[in] factoryFn The factory functor to create the layer. |
556 | | /// @param[in] data The data to construct the layer from |
557 | | /// @param[in] dataLen The length of the data |
558 | | /// @param[in] packet The packet the layer belongs to |
559 | | /// @param[in] extraArgs Extra arguments to be forwarded to the factory. |
560 | | /// @return The return value of the factory functor. |
561 | | /// @remarks The parameters extraArgs are forwarded to the factory function, but not to the TFallback |
562 | | /// constructor. |
563 | | template <typename TFallback, typename TFactory, typename... Args> |
564 | | Layer* tryConstructNextLayerFromFactoryWithFallback(TFactory factoryFn, uint8_t* data, size_t dataLen, |
565 | | Packet* packet, Args&&... extraArgs) |
566 | 120k | { |
567 | 120k | auto nextLayer = constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, packet, |
568 | 120k | std::forward<Args>(extraArgs)...); |
569 | 120k | if (nextLayer != nullptr) |
570 | 73.2k | { |
571 | 73.2k | return nextLayer; |
572 | 73.2k | } |
573 | | |
574 | | // factory failed, construct fallback layer |
575 | 46.8k | return constructNextLayer<TFallback>(data, dataLen, packet); |
576 | 120k | } 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 | 566 | 30.8k | { | 567 | 30.8k | auto nextLayer = constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, packet, | 568 | 30.8k | std::forward<Args>(extraArgs)...); | 569 | 30.8k | if (nextLayer != nullptr) | 570 | 29.4k | { | 571 | 29.4k | return nextLayer; | 572 | 29.4k | } | 573 | | | 574 | | // factory failed, construct fallback layer | 575 | 1.40k | return constructNextLayer<TFallback>(data, dataLen, packet); | 576 | 30.8k | } |
Unexecuted instantiation: 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*) 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 | 566 | 1.67k | { | 567 | 1.67k | auto nextLayer = constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, packet, | 568 | 1.67k | std::forward<Args>(extraArgs)...); | 569 | 1.67k | if (nextLayer != nullptr) | 570 | 118 | { | 571 | 118 | return nextLayer; | 572 | 118 | } | 573 | | | 574 | | // factory failed, construct fallback layer | 575 | 1.56k | return constructNextLayer<TFallback>(data, dataLen, packet); | 576 | 1.67k | } |
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 | 566 | 35 | { | 567 | 35 | auto nextLayer = constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, packet, | 568 | 35 | std::forward<Args>(extraArgs)...); | 569 | 35 | if (nextLayer != nullptr) | 570 | 35 | { | 571 | 35 | return nextLayer; | 572 | 35 | } | 573 | | | 574 | | // factory failed, construct fallback layer | 575 | 0 | return constructNextLayer<TFallback>(data, dataLen, packet); | 576 | 35 | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerFromFactoryWithFallback<pcpp::PayloadLayer, pcpp::MySqlLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*)>(pcpp::MySqlLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*), unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 566 | 17.2k | { | 567 | 17.2k | auto nextLayer = constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, packet, | 568 | 17.2k | std::forward<Args>(extraArgs)...); | 569 | 17.2k | if (nextLayer != nullptr) | 570 | 17.2k | { | 571 | 17.2k | return nextLayer; | 572 | 17.2k | } | 573 | | | 574 | | // factory failed, construct fallback layer | 575 | 0 | return constructNextLayer<TFallback>(data, dataLen, packet); | 576 | 17.2k | } |
pcpp::Layer* pcpp::Layer::tryConstructNextLayerFromFactoryWithFallback<pcpp::PayloadLayer, pcpp::QuicV1Layer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*)>(pcpp::QuicV1Layer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*), unsigned char*, unsigned long, pcpp::Packet*) Line | Count | Source | 566 | 1.76k | { | 567 | 1.76k | auto nextLayer = constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, packet, | 568 | 1.76k | std::forward<Args>(extraArgs)...); | 569 | 1.76k | if (nextLayer != nullptr) | 570 | 1.70k | { | 571 | 1.70k | return nextLayer; | 572 | 1.70k | } | 573 | | | 574 | | // factory failed, construct fallback layer | 575 | 61 | return constructNextLayer<TFallback>(data, dataLen, packet); | 576 | 1.76k | } |
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 | 566 | 17.7k | { | 567 | 17.7k | auto nextLayer = constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, packet, | 568 | 17.7k | std::forward<Args>(extraArgs)...); | 569 | 17.7k | if (nextLayer != nullptr) | 570 | 16.9k | { | 571 | 16.9k | return nextLayer; | 572 | 16.9k | } | 573 | | | 574 | | // factory failed, construct fallback layer | 575 | 814 | return constructNextLayer<TFallback>(data, dataLen, packet); | 576 | 17.7k | } |
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 | 566 | 1.44k | { | 567 | 1.44k | auto nextLayer = constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, packet, | 568 | 1.44k | std::forward<Args>(extraArgs)...); | 569 | 1.44k | if (nextLayer != nullptr) | 570 | 1.44k | { | 571 | 1.44k | return nextLayer; | 572 | 1.44k | } | 573 | | | 574 | | // factory failed, construct fallback layer | 575 | 0 | return constructNextLayer<TFallback>(data, dataLen, packet); | 576 | 1.44k | } |
Unexecuted instantiation: pcpp::Layer* pcpp::Layer::tryConstructNextLayerFromFactoryWithFallback<pcpp::PayloadLayer, pcpp::GvcpLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*)>(pcpp::GvcpLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*), unsigned char*, unsigned long, pcpp::Packet*) 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 | 566 | 49.3k | { | 567 | 49.3k | auto nextLayer = constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, packet, | 568 | 49.3k | std::forward<Args>(extraArgs)...); | 569 | 49.3k | if (nextLayer != nullptr) | 570 | 6.36k | { | 571 | 6.36k | return nextLayer; | 572 | 6.36k | } | 573 | | | 574 | | // factory failed, construct fallback layer | 575 | 42.9k | return constructNextLayer<TFallback>(data, dataLen, packet); | 576 | 49.3k | } |
|
577 | | |
578 | | /// @brief Check if the data is large enough to reinterpret as a type |
579 | | /// |
580 | | /// The data must be non-null and at least as large as the type |
581 | | /// |
582 | | /// @tparam T The type to reinterpret as |
583 | | /// @param data The data to check |
584 | | /// @param dataLen The length of the data |
585 | | /// @return True if the data is large enough to reinterpret as T, false otherwise |
586 | | template <typename T> static bool canReinterpretAs(const uint8_t* data, size_t dataLen) |
587 | 1.91M | { |
588 | 1.91M | return data != nullptr && dataLen >= sizeof(T); |
589 | 1.91M | } bool pcpp::Layer::canReinterpretAs<pcpp::arphdr>(unsigned char const*, unsigned long) Line | Count | Source | 587 | 18.0k | { | 588 | 18.0k | return data != nullptr && dataLen >= sizeof(T); | 589 | 18.0k | } |
bool pcpp::Layer::canReinterpretAs<pcpp::iphdr>(unsigned char const*, unsigned long) Line | Count | Source | 587 | 788k | { | 588 | 788k | return data != nullptr && dataLen >= sizeof(T); | 589 | 788k | } |
bool pcpp::Layer::canReinterpretAs<pcpp::dhcp_header>(unsigned char const*, unsigned long) Line | Count | Source | 587 | 19.3k | { | 588 | 19.3k | return data != nullptr && dataLen >= sizeof(T); | 589 | 19.3k | } |
bool pcpp::Layer::canReinterpretAs<pcpp::vrrp_header>(unsigned char const*, unsigned long) Line | Count | Source | 587 | 9.49k | { | 588 | 9.49k | return data != nullptr && dataLen >= sizeof(T); | 589 | 9.49k | } |
bool pcpp::Layer::canReinterpretAs<pcpp::ip6_hdr>(unsigned char const*, unsigned long) Line | Count | Source | 587 | 165k | { | 588 | 165k | return data != nullptr && dataLen >= sizeof(T); | 589 | 165k | } |
bool pcpp::Layer::canReinterpretAs<pcpp::vlan_header>(unsigned char const*, unsigned long) Line | Count | Source | 587 | 60.6k | { | 588 | 60.6k | return data != nullptr && dataLen >= sizeof(T); | 589 | 60.6k | } |
bool pcpp::Layer::canReinterpretAs<pcpp::MplsLayer::mpls_header>(unsigned char const*, unsigned long) Line | Count | Source | 587 | 343k | { | 588 | 343k | return data != nullptr && dataLen >= sizeof(T); | 589 | 343k | } |
bool pcpp::Layer::canReinterpretAs<pcpp::igmp_header>(unsigned char const*, unsigned long) Line | Count | Source | 587 | 7.70k | { | 588 | 7.70k | return data != nullptr && dataLen >= sizeof(T); | 589 | 7.70k | } |
Unexecuted instantiation: bool pcpp::Layer::canReinterpretAs<pcpp::igmpv3_query_header>(unsigned char const*, unsigned long) bool pcpp::Layer::canReinterpretAs<pcpp::igmpv3_report_header>(unsigned char const*, unsigned long) Line | Count | Source | 587 | 1.78k | { | 588 | 1.78k | return data != nullptr && dataLen >= sizeof(T); | 589 | 1.78k | } |
bool pcpp::Layer::canReinterpretAs<pcpp::ssl_tls_record_layer>(unsigned char const*, unsigned long) Line | Count | Source | 587 | 332k | { | 588 | 332k | return data != nullptr && dataLen >= sizeof(T); | 589 | 332k | } |
bool pcpp::Layer::canReinterpretAs<pcpp::tpkthdr>(unsigned char const*, unsigned long) Line | Count | Source | 587 | 156k | { | 588 | 156k | return data != nullptr && dataLen >= sizeof(T); | 589 | 156k | } |
bool pcpp::Layer::canReinterpretAs<pcpp::vxlan_header>(unsigned char const*, unsigned long) Line | Count | Source | 587 | 6.12k | { | 588 | 6.12k | return data != nullptr && dataLen >= sizeof(T); | 589 | 6.12k | } |
Unexecuted instantiation: bool pcpp::Layer::canReinterpretAs<pcpp::GvcpRequestLayer::gvcp_request_header>(unsigned char const*, unsigned long) Unexecuted instantiation: bool pcpp::Layer::canReinterpretAs<pcpp::GvcpAcknowledgeLayer::gvcp_ack_header>(unsigned char const*, unsigned long) bool pcpp::Layer::canReinterpretAs<pcpp::stp_tcn_bpdu>(unsigned char const*, unsigned long) Line | Count | Source | 587 | 1.60k | { | 588 | 1.60k | return data != nullptr && dataLen >= sizeof(T); | 589 | 1.60k | } |
bool pcpp::Layer::canReinterpretAs<pcpp::stp_conf_bpdu>(unsigned char const*, unsigned long) Line | Count | Source | 587 | 2.38k | { | 588 | 2.38k | return data != nullptr && dataLen >= sizeof(T); | 589 | 2.38k | } |
bool pcpp::Layer::canReinterpretAs<pcpp::rstp_conf_bpdu>(unsigned char const*, unsigned long) Line | Count | Source | 587 | 1.08k | { | 588 | 1.08k | return data != nullptr && dataLen >= sizeof(T); | 589 | 1.08k | } |
bool pcpp::Layer::canReinterpretAs<pcpp::mstp_conf_bpdu>(unsigned char const*, unsigned long) Line | Count | Source | 587 | 68 | { | 588 | 68 | return data != nullptr && dataLen >= sizeof(T); | 589 | 68 | } |
|
590 | | |
591 | | /// Serializes the layer's data into a provided serializer object. |
592 | | /// This is used for generating serialized representations (like JSON) of the packet layers. |
593 | | /// This method should be overridden by derived layers to provide specific serialization logic. |
594 | | /// |
595 | | /// @param[in] serializer The object scope serializer to which the layer details should be written. |
596 | | virtual void serializeLayer(ObjectScope& serializer) const |
597 | 0 | {} |
598 | | }; |
599 | | |
600 | | inline std::ostream& operator<<(std::ostream& os, const pcpp::Layer& layer) |
601 | 0 | { |
602 | 0 | os << layer.toString(); |
603 | 0 | return os; |
604 | 0 | } |
605 | | } // namespace pcpp |