Coverage Report

Created: 2026-11-12 06:50

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/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
12.4M
    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
246M
    {
128
246M
      return m_NextLayer;
129
246M
    }
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
3.38M
    {
134
3.38M
      return m_PrevLayer;
135
3.38M
    }
136
137
    /// @return The protocol enum
138
    ProtocolType getProtocol() const
139
178M
    {
140
178M
      return m_Protocol;
141
178M
    }
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
539k
    {
151
539k
      return m_Data;
152
539k
    }
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
6.00M
    {
157
6.00M
      return m_DataLen;
158
6.00M
    }
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
109k
    {
169
109k
      return m_DataLen - getHeaderLen();
170
109k
    }
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
12.4M
    {
183
12.4M
      return m_AllocationInfo.attachedPacket != nullptr;
184
12.4M
    }
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
242k
    {
240
242k
      return static_cast<uint8_t*>(m_Data + offset);
241
242k
    }
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
12.1M
        : m_Data(data), m_DataLen(dataLen), m_Protocol(protocol), m_NextLayer(nullptr), m_PrevLayer(prevLayer),
277
12.1M
          m_AllocationInfo{ packet, false }
278
12.1M
    {}
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
11.7M
    {
288
11.7M
      return m_AllocationInfo.attachedPacket;
289
11.7M
    }
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
5.75k
    {
295
5.75k
      return m_AllocationInfo.attachedPacket;
296
5.75k
    }
297
298
    void setNextLayer(Layer* nextLayer)
299
10.3M
    {
300
10.3M
      m_NextLayer = nextLayer;
301
10.3M
    }
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
16.0M
    {
328
16.0M
      return m_NextLayer != nullptr;
329
16.0M
    }
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
531k
    {
344
531k
      return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
345
531k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
343
195k
    {
344
195k
      return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
345
195k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::VrrpV3Layer, pcpp::IPAddress::AddressType>(unsigned char*, unsigned long, pcpp::IPAddress::AddressType&&)
Line
Count
Source
343
7.84k
    {
344
7.84k
      return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
345
7.84k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::DnsLayer>(unsigned char*, unsigned long)
Line
Count
Source
343
94.1k
    {
344
94.1k
      return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
345
94.1k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::RadiusLayer>(unsigned char*, unsigned long)
Line
Count
Source
343
31.5k
    {
344
31.5k
      return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
345
31.5k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::GtpV1Layer>(unsigned char*, unsigned long)
Line
Count
Source
343
74.8k
    {
344
74.8k
      return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
345
74.8k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::GtpV2Layer>(unsigned char*, unsigned long)
Line
Count
Source
343
10.3k
    {
344
10.3k
      return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
345
10.3k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::DhcpV6Layer>(unsigned char*, unsigned long)
Line
Count
Source
343
24.9k
    {
344
24.9k
      return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
345
24.9k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::NtpLayer>(unsigned char*, unsigned long)
Line
Count
Source
343
23.2k
    {
344
23.2k
      return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
345
23.2k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::WakeOnLanLayer>(unsigned char*, unsigned long)
Line
Count
Source
343
1.26k
    {
344
1.26k
      return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
345
1.26k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::SdpLayer>(unsigned char*, unsigned long)
Line
Count
Source
343
68.7k
    {
344
68.7k
      return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
345
68.7k
    }
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
8.96M
    {
358
8.96M
      if (hasNextLayer())
359
0
      {
360
0
        throw std::runtime_error("Next layer already exists");
361
0
      }
362
363
8.96M
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
364
8.96M
      setNextLayer(newLayer);
365
8.96M
      return newLayer;
366
8.96M
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::IPv4Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
357
1.72M
    {
358
1.72M
      if (hasNextLayer())
359
0
      {
360
0
        throw std::runtime_error("Next layer already exists");
361
0
      }
362
363
1.72M
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
364
1.72M
      setNextLayer(newLayer);
365
1.72M
      return newLayer;
366
1.72M
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
357
577k
    {
358
577k
      if (hasNextLayer())
359
0
      {
360
0
        throw std::runtime_error("Next layer already exists");
361
0
      }
362
363
577k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
364
577k
      setNextLayer(newLayer);
365
577k
      return newLayer;
366
577k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::IPv6Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
357
287k
    {
358
287k
      if (hasNextLayer())
359
0
      {
360
0
        throw std::runtime_error("Next layer already exists");
361
0
      }
362
363
287k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
364
287k
      setNextLayer(newLayer);
365
287k
      return newLayer;
366
287k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::ArpLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
357
23.1k
    {
358
23.1k
      if (hasNextLayer())
359
0
      {
360
0
        throw std::runtime_error("Next layer already exists");
361
0
      }
362
363
23.1k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
364
23.1k
      setNextLayer(newLayer);
365
23.1k
      return newLayer;
366
23.1k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::VlanLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
357
375k
    {
358
375k
      if (hasNextLayer())
359
0
      {
360
0
        throw std::runtime_error("Next layer already exists");
361
0
      }
362
363
375k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
364
375k
      setNextLayer(newLayer);
365
375k
      return newLayer;
366
375k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::PPPoESessionLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
357
80.8k
    {
358
80.8k
      if (hasNextLayer())
359
0
      {
360
0
        throw std::runtime_error("Next layer already exists");
361
0
      }
362
363
80.8k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
364
80.8k
      setNextLayer(newLayer);
365
80.8k
      return newLayer;
366
80.8k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::PPPoEDiscoveryLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
357
6.63k
    {
358
6.63k
      if (hasNextLayer())
359
0
      {
360
0
        throw std::runtime_error("Next layer already exists");
361
0
      }
362
363
6.63k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
364
6.63k
      setNextLayer(newLayer);
365
6.63k
      return newLayer;
366
6.63k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::MplsLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
357
3.09M
    {
358
3.09M
      if (hasNextLayer())
359
0
      {
360
0
        throw std::runtime_error("Next layer already exists");
361
0
      }
362
363
3.09M
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
364
3.09M
      setNextLayer(newLayer);
365
3.09M
      return newLayer;
366
3.09M
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::LLCLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
357
14.0k
    {
358
14.0k
      if (hasNextLayer())
359
0
      {
360
0
        throw std::runtime_error("Next layer already exists");
361
0
      }
362
363
14.0k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
364
14.0k
      setNextLayer(newLayer);
365
14.0k
      return newLayer;
366
14.0k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::WakeOnLanLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
357
1.33k
    {
358
1.33k
      if (hasNextLayer())
359
0
      {
360
0
        throw std::runtime_error("Next layer already exists");
361
0
      }
362
363
1.33k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
364
1.33k
      setNextLayer(newLayer);
365
1.33k
      return newLayer;
366
1.33k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::UdpLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
357
667k
    {
358
667k
      if (hasNextLayer())
359
0
      {
360
0
        throw std::runtime_error("Next layer already exists");
361
0
      }
362
363
667k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
364
667k
      setNextLayer(newLayer);
365
667k
      return newLayer;
366
667k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::TcpLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
357
1.04M
    {
358
1.04M
      if (hasNextLayer())
359
0
      {
360
0
        throw std::runtime_error("Next layer already exists");
361
0
      }
362
363
1.04M
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
364
1.04M
      setNextLayer(newLayer);
365
1.04M
      return newLayer;
366
1.04M
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::IcmpLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
357
65.8k
    {
358
65.8k
      if (hasNextLayer())
359
0
      {
360
0
        throw std::runtime_error("Next layer already exists");
361
0
      }
362
363
65.8k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
364
65.8k
      setNextLayer(newLayer);
365
65.8k
      return newLayer;
366
65.8k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::GREv0Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
357
22.4k
    {
358
22.4k
      if (hasNextLayer())
359
0
      {
360
0
        throw std::runtime_error("Next layer already exists");
361
0
      }
362
363
22.4k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
364
22.4k
      setNextLayer(newLayer);
365
22.4k
      return newLayer;
366
22.4k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::GREv1Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
357
120k
    {
358
120k
      if (hasNextLayer())
359
0
      {
360
0
        throw std::runtime_error("Next layer already exists");
361
0
      }
362
363
120k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
364
120k
      setNextLayer(newLayer);
365
120k
      return newLayer;
366
120k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::IgmpV1Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
357
6.32k
    {
358
6.32k
      if (hasNextLayer())
359
0
      {
360
0
        throw std::runtime_error("Next layer already exists");
361
0
      }
362
363
6.32k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
364
6.32k
      setNextLayer(newLayer);
365
6.32k
      return newLayer;
366
6.32k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::IgmpV2Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
357
11.3k
    {
358
11.3k
      if (hasNextLayer())
359
0
      {
360
0
        throw std::runtime_error("Next layer already exists");
361
0
      }
362
363
11.3k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
364
11.3k
      setNextLayer(newLayer);
365
11.3k
      return newLayer;
366
11.3k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::IgmpV3QueryLayer>(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::IgmpV3ReportLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
357
4.63k
    {
358
4.63k
      if (hasNextLayer())
359
0
      {
360
0
        throw std::runtime_error("Next layer already exists");
361
0
      }
362
363
4.63k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
364
4.63k
      setNextLayer(newLayer);
365
4.63k
      return newLayer;
366
4.63k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::AuthenticationHeaderLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
357
5.74k
    {
358
5.74k
      if (hasNextLayer())
359
0
      {
360
0
        throw std::runtime_error("Next layer already exists");
361
0
      }
362
363
5.74k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
364
5.74k
      setNextLayer(newLayer);
365
5.74k
      return newLayer;
366
5.74k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::ESPLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
357
5.88k
    {
358
5.88k
      if (hasNextLayer())
359
0
      {
360
0
        throw std::runtime_error("Next layer already exists");
361
0
      }
362
363
5.88k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
364
5.88k
      setNextLayer(newLayer);
365
5.88k
      return newLayer;
366
5.88k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::VrrpV2Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
357
8.68k
    {
358
8.68k
      if (hasNextLayer())
359
0
      {
360
0
        throw std::runtime_error("Next layer already exists");
361
0
      }
362
363
8.68k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
364
8.68k
      setNextLayer(newLayer);
365
8.68k
      return newLayer;
366
8.68k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::VrrpV3Layer, pcpp::IPAddress::AddressType>(unsigned char*, unsigned long, pcpp::Packet*, pcpp::IPAddress::AddressType&&)
Line
Count
Source
357
12.8k
    {
358
12.8k
      if (hasNextLayer())
359
0
      {
360
0
        throw std::runtime_error("Next layer already exists");
361
0
      }
362
363
12.8k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
364
12.8k
      setNextLayer(newLayer);
365
12.8k
      return newLayer;
366
12.8k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::HttpRequestLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
357
51.1k
    {
358
51.1k
      if (hasNextLayer())
359
0
      {
360
0
        throw std::runtime_error("Next layer already exists");
361
0
      }
362
363
51.1k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
364
51.1k
      setNextLayer(newLayer);
365
51.1k
      return newLayer;
366
51.1k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::HttpResponseLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
357
22.2k
    {
358
22.2k
      if (hasNextLayer())
359
0
      {
360
0
        throw std::runtime_error("Next layer already exists");
361
0
      }
362
363
22.2k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
364
22.2k
      setNextLayer(newLayer);
365
22.2k
      return newLayer;
366
22.2k
    }
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.73k
    {
358
2.73k
      if (hasNextLayer())
359
0
      {
360
0
        throw std::runtime_error("Next layer already exists");
361
0
      }
362
363
2.73k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
364
2.73k
      setNextLayer(newLayer);
365
2.73k
      return newLayer;
366
2.73k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::DnsOverTcpLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
357
16.4k
    {
358
16.4k
      if (hasNextLayer())
359
0
      {
360
0
        throw std::runtime_error("Next layer already exists");
361
0
      }
362
363
16.4k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
364
16.4k
      setNextLayer(newLayer);
365
16.4k
      return newLayer;
366
16.4k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::TelnetLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
357
73.6k
    {
358
73.6k
      if (hasNextLayer())
359
0
      {
360
0
        throw std::runtime_error("Next layer already exists");
361
0
      }
362
363
73.6k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
364
73.6k
      setNextLayer(newLayer);
365
73.6k
      return newLayer;
366
73.6k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::FtpResponseLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
357
23.6k
    {
358
23.6k
      if (hasNextLayer())
359
0
      {
360
0
        throw std::runtime_error("Next layer already exists");
361
0
      }
362
363
23.6k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
364
23.6k
      setNextLayer(newLayer);
365
23.6k
      return newLayer;
366
23.6k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::FtpRequestLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
357
8.36k
    {
358
8.36k
      if (hasNextLayer())
359
0
      {
360
0
        throw std::runtime_error("Next layer already exists");
361
0
      }
362
363
8.36k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
364
8.36k
      setNextLayer(newLayer);
365
8.36k
      return newLayer;
366
8.36k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::FtpDataLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
357
4.89k
    {
358
4.89k
      if (hasNextLayer())
359
0
      {
360
0
        throw std::runtime_error("Next layer already exists");
361
0
      }
362
363
4.89k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
364
4.89k
      setNextLayer(newLayer);
365
4.89k
      return newLayer;
366
4.89k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::TpktLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
357
33.8k
    {
358
33.8k
      if (hasNextLayer())
359
0
      {
360
0
        throw std::runtime_error("Next layer already exists");
361
0
      }
362
363
33.8k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
364
33.8k
      setNextLayer(newLayer);
365
33.8k
      return newLayer;
366
33.8k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::SmtpResponseLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
357
6.10k
    {
358
6.10k
      if (hasNextLayer())
359
0
      {
360
0
        throw std::runtime_error("Next layer already exists");
361
0
      }
362
363
6.10k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
364
6.10k
      setNextLayer(newLayer);
365
6.10k
      return newLayer;
366
6.10k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::SmtpRequestLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
357
11.4k
    {
358
11.4k
      if (hasNextLayer())
359
0
      {
360
0
        throw std::runtime_error("Next layer already exists");
361
0
      }
362
363
11.4k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
364
11.4k
      setNextLayer(newLayer);
365
11.4k
      return newLayer;
366
11.4k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::GtpV2Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
357
20.8k
    {
358
20.8k
      if (hasNextLayer())
359
0
      {
360
0
        throw std::runtime_error("Next layer already exists");
361
0
      }
362
363
20.8k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
364
20.8k
      setNextLayer(newLayer);
365
20.8k
      return newLayer;
366
20.8k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::ModbusLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
357
2.67k
    {
358
2.67k
      if (hasNextLayer())
359
0
      {
360
0
        throw std::runtime_error("Next layer already exists");
361
0
      }
362
363
2.67k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
364
2.67k
      setNextLayer(newLayer);
365
2.67k
      return newLayer;
366
2.67k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::CotpLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
357
30.6k
    {
358
30.6k
      if (hasNextLayer())
359
0
      {
360
0
        throw std::runtime_error("Next layer already exists");
361
0
      }
362
363
30.6k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
364
30.6k
      setNextLayer(newLayer);
365
30.6k
      return newLayer;
366
30.6k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::DhcpLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
357
38.1k
    {
358
38.1k
      if (hasNextLayer())
359
0
      {
360
0
        throw std::runtime_error("Next layer already exists");
361
0
      }
362
363
38.1k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
364
38.1k
      setNextLayer(newLayer);
365
38.1k
      return newLayer;
366
38.1k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::VxlanLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
357
7.23k
    {
358
7.23k
      if (hasNextLayer())
359
0
      {
360
0
        throw std::runtime_error("Next layer already exists");
361
0
      }
362
363
7.23k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
364
7.23k
      setNextLayer(newLayer);
365
7.23k
      return newLayer;
366
7.23k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::GeneveLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
357
5.66k
    {
358
5.66k
      if (hasNextLayer())
359
0
      {
360
0
        throw std::runtime_error("Next layer already exists");
361
0
      }
362
363
5.66k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
364
5.66k
      setNextLayer(newLayer);
365
5.66k
      return newLayer;
366
5.66k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::DnsLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
357
94.1k
    {
358
94.1k
      if (hasNextLayer())
359
0
      {
360
0
        throw std::runtime_error("Next layer already exists");
361
0
      }
362
363
94.1k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
364
94.1k
      setNextLayer(newLayer);
365
94.1k
      return newLayer;
366
94.1k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::RadiusLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
357
31.5k
    {
358
31.5k
      if (hasNextLayer())
359
0
      {
360
0
        throw std::runtime_error("Next layer already exists");
361
0
      }
362
363
31.5k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
364
31.5k
      setNextLayer(newLayer);
365
31.5k
      return newLayer;
366
31.5k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::GtpV1Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
357
74.8k
    {
358
74.8k
      if (hasNextLayer())
359
0
      {
360
0
        throw std::runtime_error("Next layer already exists");
361
0
      }
362
363
74.8k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
364
74.8k
      setNextLayer(newLayer);
365
74.8k
      return newLayer;
366
74.8k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::DhcpV6Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
357
24.9k
    {
358
24.9k
      if (hasNextLayer())
359
0
      {
360
0
        throw std::runtime_error("Next layer already exists");
361
0
      }
362
363
24.9k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
364
24.9k
      setNextLayer(newLayer);
365
24.9k
      return newLayer;
366
24.9k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::NtpLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
357
23.2k
    {
358
23.2k
      if (hasNextLayer())
359
0
      {
360
0
        throw std::runtime_error("Next layer already exists");
361
0
      }
362
363
23.2k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
364
23.2k
      setNextLayer(newLayer);
365
23.2k
      return newLayer;
366
23.2k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::EthLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
357
12.2k
    {
358
12.2k
      if (hasNextLayer())
359
0
      {
360
0
        throw std::runtime_error("Next layer already exists");
361
0
      }
362
363
12.2k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
364
12.2k
      setNextLayer(newLayer);
365
12.2k
      return newLayer;
366
12.2k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::S7CommLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
357
17.7k
    {
358
17.7k
      if (hasNextLayer())
359
0
      {
360
0
        throw std::runtime_error("Next layer already exists");
361
0
      }
362
363
17.7k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
364
17.7k
      setNextLayer(newLayer);
365
17.7k
      return newLayer;
366
17.7k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::EthDot3Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
357
32
    {
358
32
      if (hasNextLayer())
359
0
      {
360
0
        throw std::runtime_error("Next layer already exists");
361
0
      }
362
363
32
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
364
32
      setNextLayer(newLayer);
365
32
      return newLayer;
366
32
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::PPP_PPTPLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
357
101k
    {
358
101k
      if (hasNextLayer())
359
0
      {
360
0
        throw std::runtime_error("Next layer already exists");
361
0
      }
362
363
101k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
364
101k
      setNextLayer(newLayer);
365
101k
      return newLayer;
366
101k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::SdpLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
357
68.7k
    {
358
68.7k
      if (hasNextLayer())
359
0
      {
360
0
        throw std::runtime_error("Next layer already exists");
361
0
      }
362
363
68.7k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
364
68.7k
      setNextLayer(newLayer);
365
68.7k
      return newLayer;
366
68.7k
    }
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
878k
    {
388
878k
      return constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, getAttachedPacket(),
389
878k
                                                     std::forward<Args>(extraArgs)...);
390
878k
    }
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
132k
    {
388
132k
      return constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, getAttachedPacket(),
389
132k
                                                     std::forward<Args>(extraArgs)...);
390
132k
    }
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
4.78k
    {
388
4.78k
      return constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, getAttachedPacket(),
389
4.78k
                                                     std::forward<Args>(extraArgs)...);
390
4.78k
    }
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
503k
    {
388
503k
      return constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, getAttachedPacket(),
389
503k
                                                     std::forward<Args>(extraArgs)...);
390
503k
    }
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
37.4k
    {
388
37.4k
      return constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, getAttachedPacket(),
389
37.4k
                                                     std::forward<Args>(extraArgs)...);
390
37.4k
    }
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
168k
    {
388
168k
      return constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, getAttachedPacket(),
389
168k
                                                     std::forward<Args>(extraArgs)...);
390
168k
    }
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
31.1k
    {
388
31.1k
      return constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, getAttachedPacket(),
389
31.1k
                                                     std::forward<Args>(extraArgs)...);
390
31.1k
    }
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
1.31M
    {
412
1.31M
      if (hasNextLayer())
413
0
      {
414
0
        throw std::runtime_error("Next layer already exists");
415
0
      }
416
417
      // cppcheck-suppress redundantInitialization
418
1.31M
      Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
419
1.31M
      setNextLayer(newLayer);
420
1.31M
      return newLayer;
421
1.31M
    }
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
132k
    {
412
132k
      if (hasNextLayer())
413
0
      {
414
0
        throw std::runtime_error("Next layer already exists");
415
0
      }
416
417
      // cppcheck-suppress redundantInitialization
418
132k
      Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
419
132k
      setNextLayer(newLayer);
420
132k
      return newLayer;
421
132k
    }
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
4.78k
    {
412
4.78k
      if (hasNextLayer())
413
0
      {
414
0
        throw std::runtime_error("Next layer already exists");
415
0
      }
416
417
      // cppcheck-suppress redundantInitialization
418
4.78k
      Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
419
4.78k
      setNextLayer(newLayer);
420
4.78k
      return newLayer;
421
4.78k
    }
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
503k
    {
412
503k
      if (hasNextLayer())
413
0
      {
414
0
        throw std::runtime_error("Next layer already exists");
415
0
      }
416
417
      // cppcheck-suppress redundantInitialization
418
503k
      Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
419
503k
      setNextLayer(newLayer);
420
503k
      return newLayer;
421
503k
    }
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
253k
    {
412
253k
      if (hasNextLayer())
413
0
      {
414
0
        throw std::runtime_error("Next layer already exists");
415
0
      }
416
417
      // cppcheck-suppress redundantInitialization
418
253k
      Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
419
253k
      setNextLayer(newLayer);
420
253k
      return newLayer;
421
253k
    }
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
37.4k
    {
412
37.4k
      if (hasNextLayer())
413
0
      {
414
0
        throw std::runtime_error("Next layer already exists");
415
0
      }
416
417
      // cppcheck-suppress redundantInitialization
418
37.4k
      Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
419
37.4k
      setNextLayer(newLayer);
420
37.4k
      return newLayer;
421
37.4k
    }
pcpp::Layer* pcpp::Layer::constructNextLayerFromFactory<pcpp::DoIpLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*)>(pcpp::DoIpLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*), unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
411
61.5k
    {
412
61.5k
      if (hasNextLayer())
413
0
      {
414
0
        throw std::runtime_error("Next layer already exists");
415
0
      }
416
417
      // cppcheck-suppress redundantInitialization
418
61.5k
      Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
419
61.5k
      setNextLayer(newLayer);
420
61.5k
      return newLayer;
421
61.5k
    }
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
80.0k
    {
412
80.0k
      if (hasNextLayer())
413
0
      {
414
0
        throw std::runtime_error("Next layer already exists");
415
0
      }
416
417
      // cppcheck-suppress redundantInitialization
418
80.0k
      Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
419
80.0k
      setNextLayer(newLayer);
420
80.0k
      return newLayer;
421
80.0k
    }
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
5.48k
    {
412
5.48k
      if (hasNextLayer())
413
0
      {
414
0
        throw std::runtime_error("Next layer already exists");
415
0
      }
416
417
      // cppcheck-suppress redundantInitialization
418
5.48k
      Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
419
5.48k
      setNextLayer(newLayer);
420
5.48k
      return newLayer;
421
5.48k
    }
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
19.9k
    {
412
19.9k
      if (hasNextLayer())
413
0
      {
414
0
        throw std::runtime_error("Next layer already exists");
415
0
      }
416
417
      // cppcheck-suppress redundantInitialization
418
19.9k
      Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
419
19.9k
      setNextLayer(newLayer);
420
19.9k
      return newLayer;
421
19.9k
    }
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
3.70k
    {
412
3.70k
      if (hasNextLayer())
413
0
      {
414
0
        throw std::runtime_error("Next layer already exists");
415
0
      }
416
417
      // cppcheck-suppress redundantInitialization
418
3.70k
      Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
419
3.70k
      setNextLayer(newLayer);
420
3.70k
      return newLayer;
421
3.70k
    }
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
106k
    {
412
106k
      if (hasNextLayer())
413
0
      {
414
0
        throw std::runtime_error("Next layer already exists");
415
0
      }
416
417
      // cppcheck-suppress redundantInitialization
418
106k
      Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
419
106k
      setNextLayer(newLayer);
420
106k
      return newLayer;
421
106k
    }
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
5.86k
    {
412
5.86k
      if (hasNextLayer())
413
0
      {
414
0
        throw std::runtime_error("Next layer already exists");
415
0
      }
416
417
      // cppcheck-suppress redundantInitialization
418
5.86k
      Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
419
5.86k
      setNextLayer(newLayer);
420
5.86k
      return newLayer;
421
5.86k
    }
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*)
Line
Count
Source
411
310
    {
412
310
      if (hasNextLayer())
413
0
      {
414
0
        throw std::runtime_error("Next layer already exists");
415
0
      }
416
417
      // cppcheck-suppress redundantInitialization
418
310
      Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
419
310
      setNextLayer(newLayer);
420
310
      return newLayer;
421
310
    }
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
103k
    {
412
103k
      if (hasNextLayer())
413
0
      {
414
0
        throw std::runtime_error("Next layer already exists");
415
0
      }
416
417
      // cppcheck-suppress redundantInitialization
418
103k
      Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
419
103k
      setNextLayer(newLayer);
420
103k
      return newLayer;
421
103k
    }
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
5.46k
    {
439
5.46k
      return tryConstructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
440
5.46k
    }
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
7.85M
    {
457
7.85M
      if (T::isDataValid(data, dataLen))
458
7.79M
      {
459
7.79M
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
460
7.79M
      }
461
58.0k
      return nullptr;
462
7.85M
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::IPv4Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
456
1.74M
    {
457
1.74M
      if (T::isDataValid(data, dataLen))
458
1.72M
      {
459
1.72M
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
460
1.72M
      }
461
24.2k
      return nullptr;
462
1.74M
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::IPv6Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
456
292k
    {
457
292k
      if (T::isDataValid(data, dataLen))
458
287k
      {
459
287k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
460
287k
      }
461
5.04k
      return nullptr;
462
292k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::ArpLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
456
23.4k
    {
457
23.4k
      if (T::isDataValid(data, dataLen))
458
23.1k
      {
459
23.1k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
460
23.1k
      }
461
283
      return nullptr;
462
23.4k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::VlanLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
456
376k
    {
457
376k
      if (T::isDataValid(data, dataLen))
458
375k
      {
459
375k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
460
375k
      }
461
389
      return nullptr;
462
376k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::PPPoESessionLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
456
81.0k
    {
457
81.0k
      if (T::isDataValid(data, dataLen))
458
80.8k
      {
459
80.8k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
460
80.8k
      }
461
203
      return nullptr;
462
81.0k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::PPPoEDiscoveryLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
456
6.64k
    {
457
6.64k
      if (T::isDataValid(data, dataLen))
458
6.63k
      {
459
6.63k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
460
6.63k
      }
461
11
      return nullptr;
462
6.64k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::MplsLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
456
3.09M
    {
457
3.09M
      if (T::isDataValid(data, dataLen))
458
3.09M
      {
459
3.09M
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
460
3.09M
      }
461
557
      return nullptr;
462
3.09M
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::LLCLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
456
15.7k
    {
457
15.7k
      if (T::isDataValid(data, dataLen))
458
14.0k
      {
459
14.0k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
460
14.0k
      }
461
1.73k
      return nullptr;
462
15.7k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::WakeOnLanLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
456
456
    {
457
456
      if (T::isDataValid(data, dataLen))
458
63
      {
459
63
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
460
63
      }
461
393
      return nullptr;
462
456
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::UdpLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
456
668k
    {
457
668k
      if (T::isDataValid(data, dataLen))
458
667k
      {
459
667k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
460
667k
      }
461
1.89k
      return nullptr;
462
668k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::TcpLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
456
1.05M
    {
457
1.05M
      if (T::isDataValid(data, dataLen))
458
1.04M
      {
459
1.04M
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
460
1.04M
      }
461
11.1k
      return nullptr;
462
1.05M
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::IcmpLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
456
67.5k
    {
457
67.5k
      if (T::isDataValid(data, dataLen))
458
65.8k
      {
459
65.8k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
460
65.8k
      }
461
1.68k
      return nullptr;
462
67.5k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::GREv0Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
456
22.4k
    {
457
22.4k
      if (T::isDataValid(data, dataLen))
458
22.4k
      {
459
22.4k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
460
22.4k
      }
461
0
      return nullptr;
462
22.4k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::GREv1Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
456
120k
    {
457
120k
      if (T::isDataValid(data, dataLen))
458
120k
      {
459
120k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
460
120k
      }
461
74
      return nullptr;
462
120k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::IgmpV1Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
456
6.32k
    {
457
6.32k
      if (T::isDataValid(data, dataLen))
458
6.32k
      {
459
6.32k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
460
6.32k
      }
461
0
      return nullptr;
462
6.32k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::IgmpV2Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
456
11.3k
    {
457
11.3k
      if (T::isDataValid(data, dataLen))
458
11.3k
      {
459
11.3k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
460
11.3k
      }
461
0
      return nullptr;
462
11.3k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::IgmpV3QueryLayer>(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::IgmpV3ReportLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
456
4.63k
    {
457
4.63k
      if (T::isDataValid(data, dataLen))
458
4.63k
      {
459
4.63k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
460
4.63k
      }
461
0
      return nullptr;
462
4.63k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::AuthenticationHeaderLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
456
6.16k
    {
457
6.16k
      if (T::isDataValid(data, dataLen))
458
5.74k
      {
459
5.74k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
460
5.74k
      }
461
418
      return nullptr;
462
6.16k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::ESPLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
456
5.95k
    {
457
5.95k
      if (T::isDataValid(data, dataLen))
458
5.88k
      {
459
5.88k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
460
5.88k
      }
461
73
      return nullptr;
462
5.95k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::VrrpV2Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
456
8.68k
    {
457
8.68k
      if (T::isDataValid(data, dataLen))
458
8.68k
      {
459
8.68k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
460
8.68k
      }
461
0
      return nullptr;
462
8.68k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::VrrpV3Layer, pcpp::IPAddress::AddressType>(unsigned char*, unsigned long, pcpp::Packet*, pcpp::IPAddress::AddressType&&)
Line
Count
Source
456
5.01k
    {
457
5.01k
      if (T::isDataValid(data, dataLen))
458
5.01k
      {
459
5.01k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
460
5.01k
      }
461
0
      return nullptr;
462
5.01k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::CotpLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
456
33.6k
    {
457
33.6k
      if (T::isDataValid(data, dataLen))
458
30.6k
      {
459
30.6k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
460
30.6k
      }
461
3.02k
      return nullptr;
462
33.6k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::DhcpLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
456
39.2k
    {
457
39.2k
      if (T::isDataValid(data, dataLen))
458
38.1k
      {
459
38.1k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
460
38.1k
      }
461
1.14k
      return nullptr;
462
39.2k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::VxlanLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
456
7.23k
    {
457
7.23k
      if (T::isDataValid(data, dataLen))
458
7.23k
      {
459
7.23k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
460
7.23k
      }
461
5
      return nullptr;
462
7.23k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::GeneveLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
456
5.71k
    {
457
5.71k
      if (T::isDataValid(data, dataLen))
458
5.66k
      {
459
5.66k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
460
5.66k
      }
461
50
      return nullptr;
462
5.71k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::EthLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
456
12.6k
    {
457
12.6k
      if (T::isDataValid(data, dataLen))
458
12.2k
      {
459
12.2k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
460
12.2k
      }
461
417
      return nullptr;
462
12.6k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::S7CommLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
456
20.2k
    {
457
20.2k
      if (T::isDataValid(data, dataLen))
458
17.7k
      {
459
17.7k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
460
17.7k
      }
461
2.55k
      return nullptr;
462
20.2k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::EthDot3Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
456
32
    {
457
32
      if (T::isDataValid(data, dataLen))
458
32
      {
459
32
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
460
32
      }
461
0
      return nullptr;
462
32
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::PPP_PPTPLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
456
101k
    {
457
101k
      if (T::isDataValid(data, dataLen))
458
101k
      {
459
101k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
460
101k
      }
461
407
      return nullptr;
462
101k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::GtpV2Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
456
12.8k
    {
457
12.8k
      if (T::isDataValid(data, dataLen))
458
10.5k
      {
459
10.5k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
460
10.5k
      }
461
2.27k
      return nullptr;
462
12.8k
    }
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
6.11M
    {
483
6.11M
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
484
6.11M
                                                             std::forward<Args>(extraArgs)...);
485
6.11M
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::IPv4Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
482
1.74M
    {
483
1.74M
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
484
1.74M
                                                             std::forward<Args>(extraArgs)...);
485
1.74M
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::IPv6Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
482
285k
    {
483
285k
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
484
285k
                                                             std::forward<Args>(extraArgs)...);
485
285k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::ArpLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
482
23.4k
    {
483
23.4k
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
484
23.4k
                                                             std::forward<Args>(extraArgs)...);
485
23.4k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::VlanLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
482
376k
    {
483
376k
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
484
376k
                                                             std::forward<Args>(extraArgs)...);
485
376k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::PPPoESessionLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
482
81.0k
    {
483
81.0k
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
484
81.0k
                                                             std::forward<Args>(extraArgs)...);
485
81.0k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::PPPoEDiscoveryLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
482
6.64k
    {
483
6.64k
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
484
6.64k
                                                             std::forward<Args>(extraArgs)...);
485
6.64k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::MplsLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
482
3.09M
    {
483
3.09M
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
484
3.09M
                                                             std::forward<Args>(extraArgs)...);
485
3.09M
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::LLCLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
482
15.7k
    {
483
15.7k
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
484
15.7k
                                                             std::forward<Args>(extraArgs)...);
485
15.7k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::WakeOnLanLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
482
456
    {
483
456
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
484
456
                                                             std::forward<Args>(extraArgs)...);
485
456
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::UdpLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
482
43.9k
    {
483
43.9k
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
484
43.9k
                                                             std::forward<Args>(extraArgs)...);
485
43.9k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::TcpLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
482
196k
    {
483
196k
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
484
196k
                                                             std::forward<Args>(extraArgs)...);
485
196k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::GREv0Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
482
7.07k
    {
483
7.07k
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
484
7.07k
                                                             std::forward<Args>(extraArgs)...);
485
7.07k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::GREv1Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
482
5.99k
    {
483
5.99k
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
484
5.99k
                                                             std::forward<Args>(extraArgs)...);
485
5.99k
    }
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
3.19k
    {
483
3.19k
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
484
3.19k
                                                             std::forward<Args>(extraArgs)...);
485
3.19k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::CotpLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
482
33.6k
    {
483
33.6k
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
484
33.6k
                                                             std::forward<Args>(extraArgs)...);
485
33.6k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::DhcpLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
482
39.2k
    {
483
39.2k
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
484
39.2k
                                                             std::forward<Args>(extraArgs)...);
485
39.2k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::VxlanLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
482
7.23k
    {
483
7.23k
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
484
7.23k
                                                             std::forward<Args>(extraArgs)...);
485
7.23k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::GeneveLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
482
5.71k
    {
483
5.71k
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
484
5.71k
                                                             std::forward<Args>(extraArgs)...);
485
5.71k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::EthLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
482
7.22k
    {
483
7.22k
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
484
7.22k
                                                             std::forward<Args>(extraArgs)...);
485
7.22k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::S7CommLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
482
20.2k
    {
483
20.2k
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
484
20.2k
                                                             std::forward<Args>(extraArgs)...);
485
20.2k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::EthDot3Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
482
32
    {
483
32
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
484
32
                                                             std::forward<Args>(extraArgs)...);
485
32
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::PPP_PPTPLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
482
101k
    {
483
101k
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
484
101k
                                                             std::forward<Args>(extraArgs)...);
485
101k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::GtpV2Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
482
12.8k
    {
483
12.8k
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
484
12.8k
                                                             std::forward<Args>(extraArgs)...);
485
12.8k
    }
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
7.85M
    {
505
7.85M
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
506
7.79M
      {
507
7.79M
        return m_NextLayer;
508
7.79M
      }
509
510
58.0k
      return constructNextLayer<TFallback>(data, dataLen, packet);
511
7.85M
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::IPv4Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
504
1.74M
    {
505
1.74M
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
506
1.72M
      {
507
1.72M
        return m_NextLayer;
508
1.72M
      }
509
510
24.2k
      return constructNextLayer<TFallback>(data, dataLen, packet);
511
1.74M
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::IPv6Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
504
292k
    {
505
292k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
506
287k
      {
507
287k
        return m_NextLayer;
508
287k
      }
509
510
5.04k
      return constructNextLayer<TFallback>(data, dataLen, packet);
511
292k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::ArpLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
504
23.4k
    {
505
23.4k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
506
23.1k
      {
507
23.1k
        return m_NextLayer;
508
23.1k
      }
509
510
283
      return constructNextLayer<TFallback>(data, dataLen, packet);
511
23.4k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::VlanLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
504
376k
    {
505
376k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
506
375k
      {
507
375k
        return m_NextLayer;
508
375k
      }
509
510
389
      return constructNextLayer<TFallback>(data, dataLen, packet);
511
376k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::PPPoESessionLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
504
81.0k
    {
505
81.0k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
506
80.8k
      {
507
80.8k
        return m_NextLayer;
508
80.8k
      }
509
510
203
      return constructNextLayer<TFallback>(data, dataLen, packet);
511
81.0k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::PPPoEDiscoveryLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
504
6.64k
    {
505
6.64k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
506
6.63k
      {
507
6.63k
        return m_NextLayer;
508
6.63k
      }
509
510
11
      return constructNextLayer<TFallback>(data, dataLen, packet);
511
6.64k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::MplsLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
504
3.09M
    {
505
3.09M
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
506
3.09M
      {
507
3.09M
        return m_NextLayer;
508
3.09M
      }
509
510
557
      return constructNextLayer<TFallback>(data, dataLen, packet);
511
3.09M
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::LLCLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
504
15.7k
    {
505
15.7k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
506
14.0k
      {
507
14.0k
        return m_NextLayer;
508
14.0k
      }
509
510
1.73k
      return constructNextLayer<TFallback>(data, dataLen, packet);
511
15.7k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::WakeOnLanLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
504
456
    {
505
456
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
506
63
      {
507
63
        return m_NextLayer;
508
63
      }
509
510
393
      return constructNextLayer<TFallback>(data, dataLen, packet);
511
456
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::UdpLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
504
668k
    {
505
668k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
506
667k
      {
507
667k
        return m_NextLayer;
508
667k
      }
509
510
1.89k
      return constructNextLayer<TFallback>(data, dataLen, packet);
511
668k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::TcpLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
504
1.05M
    {
505
1.05M
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
506
1.04M
      {
507
1.04M
        return m_NextLayer;
508
1.04M
      }
509
510
11.1k
      return constructNextLayer<TFallback>(data, dataLen, packet);
511
1.05M
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::IcmpLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
504
67.5k
    {
505
67.5k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
506
65.8k
      {
507
65.8k
        return m_NextLayer;
508
65.8k
      }
509
510
1.68k
      return constructNextLayer<TFallback>(data, dataLen, packet);
511
67.5k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::GREv0Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
504
22.4k
    {
505
22.4k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
506
22.4k
      {
507
22.4k
        return m_NextLayer;
508
22.4k
      }
509
510
0
      return constructNextLayer<TFallback>(data, dataLen, packet);
511
22.4k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::GREv1Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
504
120k
    {
505
120k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
506
120k
      {
507
120k
        return m_NextLayer;
508
120k
      }
509
510
74
      return constructNextLayer<TFallback>(data, dataLen, packet);
511
120k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::IgmpV1Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
504
6.32k
    {
505
6.32k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
506
6.32k
      {
507
6.32k
        return m_NextLayer;
508
6.32k
      }
509
510
0
      return constructNextLayer<TFallback>(data, dataLen, packet);
511
6.32k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::IgmpV2Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
504
11.3k
    {
505
11.3k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
506
11.3k
      {
507
11.3k
        return m_NextLayer;
508
11.3k
      }
509
510
0
      return constructNextLayer<TFallback>(data, dataLen, packet);
511
11.3k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::IgmpV3QueryLayer, 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::IgmpV3ReportLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
504
4.63k
    {
505
4.63k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
506
4.63k
      {
507
4.63k
        return m_NextLayer;
508
4.63k
      }
509
510
0
      return constructNextLayer<TFallback>(data, dataLen, packet);
511
4.63k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::AuthenticationHeaderLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
504
6.16k
    {
505
6.16k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
506
5.74k
      {
507
5.74k
        return m_NextLayer;
508
5.74k
      }
509
510
418
      return constructNextLayer<TFallback>(data, dataLen, packet);
511
6.16k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::ESPLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
504
5.95k
    {
505
5.95k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
506
5.88k
      {
507
5.88k
        return m_NextLayer;
508
5.88k
      }
509
510
73
      return constructNextLayer<TFallback>(data, dataLen, packet);
511
5.95k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::VrrpV2Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
504
8.68k
    {
505
8.68k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
506
8.68k
      {
507
8.68k
        return m_NextLayer;
508
8.68k
      }
509
510
0
      return constructNextLayer<TFallback>(data, dataLen, packet);
511
8.68k
    }
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
5.01k
    {
505
5.01k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
506
5.01k
      {
507
5.01k
        return m_NextLayer;
508
5.01k
      }
509
510
0
      return constructNextLayer<TFallback>(data, dataLen, packet);
511
5.01k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::CotpLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
504
33.6k
    {
505
33.6k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
506
30.6k
      {
507
30.6k
        return m_NextLayer;
508
30.6k
      }
509
510
3.02k
      return constructNextLayer<TFallback>(data, dataLen, packet);
511
33.6k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::DhcpLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
504
39.2k
    {
505
39.2k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
506
38.1k
      {
507
38.1k
        return m_NextLayer;
508
38.1k
      }
509
510
1.14k
      return constructNextLayer<TFallback>(data, dataLen, packet);
511
39.2k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::VxlanLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
504
7.23k
    {
505
7.23k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
506
7.23k
      {
507
7.23k
        return m_NextLayer;
508
7.23k
      }
509
510
5
      return constructNextLayer<TFallback>(data, dataLen, packet);
511
7.23k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::GeneveLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
504
5.71k
    {
505
5.71k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
506
5.66k
      {
507
5.66k
        return m_NextLayer;
508
5.66k
      }
509
510
50
      return constructNextLayer<TFallback>(data, dataLen, packet);
511
5.71k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::EthLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
504
7.22k
    {
505
7.22k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
506
6.84k
      {
507
6.84k
        return m_NextLayer;
508
6.84k
      }
509
510
385
      return constructNextLayer<TFallback>(data, dataLen, packet);
511
7.22k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::S7CommLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
504
20.2k
    {
505
20.2k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
506
17.7k
      {
507
17.7k
        return m_NextLayer;
508
17.7k
      }
509
510
2.55k
      return constructNextLayer<TFallback>(data, dataLen, packet);
511
20.2k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::EthDot3Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
504
32
    {
505
32
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
506
32
      {
507
32
        return m_NextLayer;
508
32
      }
509
510
0
      return constructNextLayer<TFallback>(data, dataLen, packet);
511
32
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::PPP_PPTPLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
504
101k
    {
505
101k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
506
101k
      {
507
101k
        return m_NextLayer;
508
101k
      }
509
510
407
      return constructNextLayer<TFallback>(data, dataLen, packet);
511
101k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::GtpV2Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
504
12.8k
    {
505
12.8k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
506
10.5k
      {
507
10.5k
        return m_NextLayer;
508
10.5k
      }
509
510
2.27k
      return constructNextLayer<TFallback>(data, dataLen, packet);
511
12.8k
    }
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
441k
    {
538
      // Note that the fallback is first to allow template argument deduction of the factory type.
539
441k
      return tryConstructNextLayerFromFactoryWithFallback<TFallback, TFactory>(
540
441k
          factoryFn, data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
541
441k
    }
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
85.0k
    {
538
      // Note that the fallback is first to allow template argument deduction of the factory type.
539
85.0k
      return tryConstructNextLayerFromFactoryWithFallback<TFallback, TFactory>(
540
85.0k
          factoryFn, data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
541
85.0k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerFromFactoryWithFallback<pcpp::PayloadLayer, pcpp::DoIpLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*)>(pcpp::DoIpLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*), unsigned char*, unsigned long)
Line
Count
Source
537
61.5k
    {
538
      // Note that the fallback is first to allow template argument deduction of the factory type.
539
61.5k
      return tryConstructNextLayerFromFactoryWithFallback<TFallback, TFactory>(
540
61.5k
          factoryFn, data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
541
61.5k
    }
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
48.9k
    {
538
      // Note that the fallback is first to allow template argument deduction of the factory type.
539
48.9k
      return tryConstructNextLayerFromFactoryWithFallback<TFallback, TFactory>(
540
48.9k
          factoryFn, data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
541
48.9k
    }
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
5.48k
    {
538
      // Note that the fallback is first to allow template argument deduction of the factory type.
539
5.48k
      return tryConstructNextLayerFromFactoryWithFallback<TFallback, TFactory>(
540
5.48k
          factoryFn, data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
541
5.48k
    }
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
19.9k
    {
538
      // Note that the fallback is first to allow template argument deduction of the factory type.
539
19.9k
      return tryConstructNextLayerFromFactoryWithFallback<TFallback, TFactory>(
540
19.9k
          factoryFn, data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
541
19.9k
    }
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
3.70k
    {
538
      // Note that the fallback is first to allow template argument deduction of the factory type.
539
3.70k
      return tryConstructNextLayerFromFactoryWithFallback<TFallback, TFactory>(
540
3.70k
          factoryFn, data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
541
3.70k
    }
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
106k
    {
538
      // Note that the fallback is first to allow template argument deduction of the factory type.
539
106k
      return tryConstructNextLayerFromFactoryWithFallback<TFallback, TFactory>(
540
106k
          factoryFn, data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
541
106k
    }
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
5.86k
    {
538
      // Note that the fallback is first to allow template argument deduction of the factory type.
539
5.86k
      return tryConstructNextLayerFromFactoryWithFallback<TFallback, TFactory>(
540
5.86k
          factoryFn, data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
541
5.86k
    }
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)
Line
Count
Source
537
310
    {
538
      // Note that the fallback is first to allow template argument deduction of the factory type.
539
310
      return tryConstructNextLayerFromFactoryWithFallback<TFallback, TFactory>(
540
310
          factoryFn, data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
541
310
    }
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
103k
    {
538
      // Note that the fallback is first to allow template argument deduction of the factory type.
539
103k
      return tryConstructNextLayerFromFactoryWithFallback<TFallback, TFactory>(
540
103k
          factoryFn, data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
541
103k
    }
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
441k
    {
567
441k
      auto nextLayer = constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, packet,
568
441k
                                                               std::forward<Args>(extraArgs)...);
569
441k
      if (nextLayer != nullptr)
570
315k
      {
571
315k
        return nextLayer;
572
315k
      }
573
574
      // factory failed, construct fallback layer
575
125k
      return constructNextLayer<TFallback>(data, dataLen, packet);
576
441k
    }
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
85.0k
    {
567
85.0k
      auto nextLayer = constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, packet,
568
85.0k
                                                               std::forward<Args>(extraArgs)...);
569
85.0k
      if (nextLayer != nullptr)
570
80.2k
      {
571
80.2k
        return nextLayer;
572
80.2k
      }
573
574
      // factory failed, construct fallback layer
575
4.88k
      return constructNextLayer<TFallback>(data, dataLen, packet);
576
85.0k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerFromFactoryWithFallback<pcpp::PayloadLayer, pcpp::DoIpLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*)>(pcpp::DoIpLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*), unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
566
61.5k
    {
567
61.5k
      auto nextLayer = constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, packet,
568
61.5k
                                                               std::forward<Args>(extraArgs)...);
569
61.5k
      if (nextLayer != nullptr)
570
60.4k
      {
571
60.4k
        return nextLayer;
572
60.4k
      }
573
574
      // factory failed, construct fallback layer
575
1.14k
      return constructNextLayer<TFallback>(data, dataLen, packet);
576
61.5k
    }
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
48.9k
    {
567
48.9k
      auto nextLayer = constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, packet,
568
48.9k
                                                               std::forward<Args>(extraArgs)...);
569
48.9k
      if (nextLayer != nullptr)
570
33.6k
      {
571
33.6k
        return nextLayer;
572
33.6k
      }
573
574
      // factory failed, construct fallback layer
575
15.2k
      return constructNextLayer<TFallback>(data, dataLen, packet);
576
48.9k
    }
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
5.48k
    {
567
5.48k
      auto nextLayer = constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, packet,
568
5.48k
                                                               std::forward<Args>(extraArgs)...);
569
5.48k
      if (nextLayer != nullptr)
570
5.48k
      {
571
5.48k
        return nextLayer;
572
5.48k
      }
573
574
      // factory failed, construct fallback layer
575
0
      return constructNextLayer<TFallback>(data, dataLen, packet);
576
5.48k
    }
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
19.9k
    {
567
19.9k
      auto nextLayer = constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, packet,
568
19.9k
                                                               std::forward<Args>(extraArgs)...);
569
19.9k
      if (nextLayer != nullptr)
570
19.9k
      {
571
19.9k
        return nextLayer;
572
19.9k
      }
573
574
      // factory failed, construct fallback layer
575
0
      return constructNextLayer<TFallback>(data, dataLen, packet);
576
19.9k
    }
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
3.70k
    {
567
3.70k
      auto nextLayer = constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, packet,
568
3.70k
                                                               std::forward<Args>(extraArgs)...);
569
3.70k
      if (nextLayer != nullptr)
570
3.39k
      {
571
3.39k
        return nextLayer;
572
3.39k
      }
573
574
      // factory failed, construct fallback layer
575
314
      return constructNextLayer<TFallback>(data, dataLen, packet);
576
3.70k
    }
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
106k
    {
567
106k
      auto nextLayer = constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, packet,
568
106k
                                                               std::forward<Args>(extraArgs)...);
569
106k
      if (nextLayer != nullptr)
570
101k
      {
571
101k
        return nextLayer;
572
101k
      }
573
574
      // factory failed, construct fallback layer
575
5.66k
      return constructNextLayer<TFallback>(data, dataLen, packet);
576
106k
    }
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
5.86k
    {
567
5.86k
      auto nextLayer = constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, packet,
568
5.86k
                                                               std::forward<Args>(extraArgs)...);
569
5.86k
      if (nextLayer != nullptr)
570
5.69k
      {
571
5.69k
        return nextLayer;
572
5.69k
      }
573
574
      // factory failed, construct fallback layer
575
170
      return constructNextLayer<TFallback>(data, dataLen, packet);
576
5.86k
    }
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*)
Line
Count
Source
566
310
    {
567
310
      auto nextLayer = constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, packet,
568
310
                                                               std::forward<Args>(extraArgs)...);
569
310
      if (nextLayer != nullptr)
570
310
      {
571
310
        return nextLayer;
572
310
      }
573
574
      // factory failed, construct fallback layer
575
0
      return constructNextLayer<TFallback>(data, dataLen, packet);
576
310
    }
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
103k
    {
567
103k
      auto nextLayer = constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, packet,
568
103k
                                                               std::forward<Args>(extraArgs)...);
569
103k
      if (nextLayer != nullptr)
570
5.09k
      {
571
5.09k
        return nextLayer;
572
5.09k
      }
573
574
      // factory failed, construct fallback layer
575
98.3k
      return constructNextLayer<TFallback>(data, dataLen, packet);
576
103k
    }
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
6.47M
    {
588
6.47M
      return data != nullptr && dataLen >= sizeof(T);
589
6.47M
    }
bool pcpp::Layer::canReinterpretAs<pcpp::arphdr>(unsigned char const*, unsigned long)
Line
Count
Source
587
23.4k
    {
588
23.4k
      return data != nullptr && dataLen >= sizeof(T);
589
23.4k
    }
bool pcpp::Layer::canReinterpretAs<pcpp::iphdr>(unsigned char const*, unsigned long)
Line
Count
Source
587
1.79M
    {
588
1.79M
      return data != nullptr && dataLen >= sizeof(T);
589
1.79M
    }
bool pcpp::Layer::canReinterpretAs<pcpp::dhcp_header>(unsigned char const*, unsigned long)
Line
Count
Source
587
39.2k
    {
588
39.2k
      return data != nullptr && dataLen >= sizeof(T);
589
39.2k
    }
bool pcpp::Layer::canReinterpretAs<pcpp::vrrp_header>(unsigned char const*, unsigned long)
Line
Count
Source
587
13.6k
    {
588
13.6k
      return data != nullptr && dataLen >= sizeof(T);
589
13.6k
    }
bool pcpp::Layer::canReinterpretAs<pcpp::ip6_hdr>(unsigned char const*, unsigned long)
Line
Count
Source
587
297k
    {
588
297k
      return data != nullptr && dataLen >= sizeof(T);
589
297k
    }
bool pcpp::Layer::canReinterpretAs<pcpp::vlan_header>(unsigned char const*, unsigned long)
Line
Count
Source
587
376k
    {
588
376k
      return data != nullptr && dataLen >= sizeof(T);
589
376k
    }
bool pcpp::Layer::canReinterpretAs<pcpp::MplsLayer::mpls_header>(unsigned char const*, unsigned long)
Line
Count
Source
587
3.09M
    {
588
3.09M
      return data != nullptr && dataLen >= sizeof(T);
589
3.09M
    }
bool pcpp::Layer::canReinterpretAs<pcpp::igmp_header>(unsigned char const*, unsigned long)
Line
Count
Source
587
17.7k
    {
588
17.7k
      return data != nullptr && dataLen >= sizeof(T);
589
17.7k
    }
bool pcpp::Layer::canReinterpretAs<pcpp::igmpv3_query_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::igmpv3_report_header>(unsigned char const*, unsigned long)
Line
Count
Source
587
4.63k
    {
588
4.63k
      return data != nullptr && dataLen >= sizeof(T);
589
4.63k
    }
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
1.89k
    {
588
1.89k
      return data != nullptr && dataLen >= sizeof(T);
589
1.89k
    }
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
    }
bool pcpp::Layer::canReinterpretAs<pcpp::tpkthdr>(unsigned char const*, unsigned long)
Line
Count
Source
587
291k
    {
588
291k
      return data != nullptr && dataLen >= sizeof(T);
589
291k
    }
bool pcpp::Layer::canReinterpretAs<pcpp::vxlan_header>(unsigned char const*, unsigned long)
Line
Count
Source
587
7.23k
    {
588
7.23k
      return data != nullptr && dataLen >= sizeof(T);
589
7.23k
    }
bool pcpp::Layer::canReinterpretAs<pcpp::GeneveLayer::geneve_header>(unsigned char const*, unsigned long)
Line
Count
Source
587
5.71k
    {
588
5.71k
      return data != nullptr && dataLen >= sizeof(T);
589
5.71k
    }
bool pcpp::Layer::canReinterpretAs<pcpp::GvcpRequestLayer::gvcp_request_header>(unsigned char const*, unsigned long)
Line
Count
Source
587
310
    {
588
310
      return data != nullptr && dataLen >= sizeof(T);
589
310
    }
bool pcpp::Layer::canReinterpretAs<pcpp::GvcpAcknowledgeLayer::gvcp_ack_header>(unsigned char const*, unsigned long)
Line
Count
Source
587
310
    {
588
310
      return data != nullptr && dataLen >= sizeof(T);
589
310
    }
bool pcpp::Layer::canReinterpretAs<pcpp::ssl_tls_record_layer>(unsigned char const*, unsigned long)
Line
Count
Source
587
503k
    {
588
503k
      return data != nullptr && dataLen >= sizeof(T);
589
503k
    }
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