Coverage Report

Created: 2026-04-12 07:26

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