Coverage Report

Created: 2026-06-10 07:57

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