Coverage Report

Created: 2026-05-30 07:22

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.15M
    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
97.5M
    {
127
97.5M
      return m_NextLayer;
128
97.5M
    }
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.14M
    {
133
2.14M
      return m_PrevLayer;
134
2.14M
    }
135
136
    /// @return The protocol enum
137
    ProtocolType getProtocol() const
138
69.9M
    {
139
69.9M
      return m_Protocol;
140
69.9M
    }
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
320k
    {
150
320k
      return m_Data;
151
320k
    }
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.41M
    {
156
3.41M
      return m_DataLen;
157
3.41M
    }
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
70.7k
    {
168
70.7k
      return m_DataLen - getHeaderLen();
169
70.7k
    }
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.15M
    {
182
5.15M
      return m_AllocationInfo.attachedPacket != nullptr;
183
5.15M
    }
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
112k
    {
193
112k
      return static_cast<uint8_t*>(m_Data + offset);
194
112k
    }
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.02M
        : m_Data(data), m_DataLen(dataLen), m_Protocol(protocol), m_NextLayer(nullptr), m_PrevLayer(prevLayer),
230
5.02M
          m_AllocationInfo{ packet, false }
231
5.02M
    {}
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
4.94M
    {
241
4.94M
      return m_AllocationInfo.attachedPacket;
242
4.94M
    }
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.43k
    {
248
3.43k
      return m_AllocationInfo.attachedPacket;
249
3.43k
    }
250
251
    void setNextLayer(Layer* nextLayer)
252
4.03M
    {
253
4.03M
      m_NextLayer = nextLayer;
254
4.03M
    }
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.05M
    {
265
7.05M
      return m_NextLayer != nullptr;
266
7.05M
    }
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
370k
    {
281
370k
      return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
282
370k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::VlanLayer>(unsigned char*, unsigned long)
Line
Count
Source
280
62.2k
    {
281
62.2k
      return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
282
62.2k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::MplsLayer>(unsigned char*, unsigned long)
Line
Count
Source
280
5.14k
    {
281
5.14k
      return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
282
5.14k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
280
107k
    {
281
107k
      return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
282
107k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::VrrpV3Layer, pcpp::IPAddress::AddressType>(unsigned char*, unsigned long, pcpp::IPAddress::AddressType&&)
Line
Count
Source
280
4.56k
    {
281
4.56k
      return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
282
4.56k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::ArpLayer>(unsigned char*, unsigned long)
Line
Count
Source
280
1.91k
    {
281
1.91k
      return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
282
1.91k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::DnsLayer>(unsigned char*, unsigned long)
Line
Count
Source
280
58.1k
    {
281
58.1k
      return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
282
58.1k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::RadiusLayer>(unsigned char*, unsigned long)
Line
Count
Source
280
12.8k
    {
281
12.8k
      return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
282
12.8k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::GtpV1Layer>(unsigned char*, unsigned long)
Line
Count
Source
280
34.5k
    {
281
34.5k
      return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
282
34.5k
    }
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
20.8k
    {
281
20.8k
      return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
282
20.8k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::NtpLayer>(unsigned char*, unsigned long)
Line
Count
Source
280
17.1k
    {
281
17.1k
      return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
282
17.1k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::WakeOnLanLayer>(unsigned char*, unsigned long)
Line
Count
Source
280
495
    {
281
495
      return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
282
495
    }
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
45.3k
    {
281
45.3k
      return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
282
45.3k
    }
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.24M
    {
295
3.24M
      if (hasNextLayer())
296
0
      {
297
0
        throw std::runtime_error("Next layer already exists");
298
0
      }
299
300
3.24M
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
301
3.24M
      setNextLayer(newLayer);
302
3.24M
      return newLayer;
303
3.24M
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::IPv4Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
294
953k
    {
295
953k
      if (hasNextLayer())
296
0
      {
297
0
        throw std::runtime_error("Next layer already exists");
298
0
      }
299
300
953k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
301
953k
      setNextLayer(newLayer);
302
953k
      return newLayer;
303
953k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
294
302k
    {
295
302k
      if (hasNextLayer())
296
0
      {
297
0
        throw std::runtime_error("Next layer already exists");
298
0
      }
299
300
302k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
301
302k
      setNextLayer(newLayer);
302
302k
      return newLayer;
303
302k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::IPv6Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
294
169k
    {
295
169k
      if (hasNextLayer())
296
0
      {
297
0
        throw std::runtime_error("Next layer already exists");
298
0
      }
299
300
169k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
301
169k
      setNextLayer(newLayer);
302
169k
      return newLayer;
303
169k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::VlanLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
294
223k
    {
295
223k
      if (hasNextLayer())
296
0
      {
297
0
        throw std::runtime_error("Next layer already exists");
298
0
      }
299
300
223k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
301
223k
      setNextLayer(newLayer);
302
223k
      return newLayer;
303
223k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::MplsLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
294
5.14k
    {
295
5.14k
      if (hasNextLayer())
296
0
      {
297
0
        throw std::runtime_error("Next layer already exists");
298
0
      }
299
300
5.14k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
301
5.14k
      setNextLayer(newLayer);
302
5.14k
      return newLayer;
303
5.14k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::PPP_PPTPLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
294
72.1k
    {
295
72.1k
      if (hasNextLayer())
296
0
      {
297
0
        throw std::runtime_error("Next layer already exists");
298
0
      }
299
300
72.1k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
301
72.1k
      setNextLayer(newLayer);
302
72.1k
      return newLayer;
303
72.1k
    }
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
360k
    {
295
360k
      if (hasNextLayer())
296
0
      {
297
0
        throw std::runtime_error("Next layer already exists");
298
0
      }
299
300
360k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
301
360k
      setNextLayer(newLayer);
302
360k
      return newLayer;
303
360k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::TcpLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
294
547k
    {
295
547k
      if (hasNextLayer())
296
0
      {
297
0
        throw std::runtime_error("Next layer already exists");
298
0
      }
299
300
547k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
301
547k
      setNextLayer(newLayer);
302
547k
      return newLayer;
303
547k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::IcmpLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
294
44.1k
    {
295
44.1k
      if (hasNextLayer())
296
0
      {
297
0
        throw std::runtime_error("Next layer already exists");
298
0
      }
299
300
44.1k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
301
44.1k
      setNextLayer(newLayer);
302
44.1k
      return newLayer;
303
44.1k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::GREv0Layer>(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::GREv1Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
294
79.9k
    {
295
79.9k
      if (hasNextLayer())
296
0
      {
297
0
        throw std::runtime_error("Next layer already exists");
298
0
      }
299
300
79.9k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
301
79.9k
      setNextLayer(newLayer);
302
79.9k
      return newLayer;
303
79.9k
    }
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.96k
    {
295
7.96k
      if (hasNextLayer())
296
0
      {
297
0
        throw std::runtime_error("Next layer already exists");
298
0
      }
299
300
7.96k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
301
7.96k
      setNextLayer(newLayer);
302
7.96k
      return newLayer;
303
7.96k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::IgmpV3QueryLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
294
1.87k
    {
295
1.87k
      if (hasNextLayer())
296
0
      {
297
0
        throw std::runtime_error("Next layer already exists");
298
0
      }
299
300
1.87k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
301
1.87k
      setNextLayer(newLayer);
302
1.87k
      return newLayer;
303
1.87k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::IgmpV3ReportLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
294
2.23k
    {
295
2.23k
      if (hasNextLayer())
296
0
      {
297
0
        throw std::runtime_error("Next layer already exists");
298
0
      }
299
300
2.23k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
301
2.23k
      setNextLayer(newLayer);
302
2.23k
      return newLayer;
303
2.23k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::AuthenticationHeaderLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
294
5.15k
    {
295
5.15k
      if (hasNextLayer())
296
0
      {
297
0
        throw std::runtime_error("Next layer already exists");
298
0
      }
299
300
5.15k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
301
5.15k
      setNextLayer(newLayer);
302
5.15k
      return newLayer;
303
5.15k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::ESPLayer>(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::VrrpV2Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
294
3.90k
    {
295
3.90k
      if (hasNextLayer())
296
0
      {
297
0
        throw std::runtime_error("Next layer already exists");
298
0
      }
299
300
3.90k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
301
3.90k
      setNextLayer(newLayer);
302
3.90k
      return newLayer;
303
3.90k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::VrrpV3Layer, pcpp::IPAddress::AddressType>(unsigned char*, unsigned long, pcpp::Packet*, pcpp::IPAddress::AddressType&&)
Line
Count
Source
294
8.26k
    {
295
8.26k
      if (hasNextLayer())
296
0
      {
297
0
        throw std::runtime_error("Next layer already exists");
298
0
      }
299
300
8.26k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
301
8.26k
      setNextLayer(newLayer);
302
8.26k
      return newLayer;
303
8.26k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::ArpLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
294
5.51k
    {
295
5.51k
      if (hasNextLayer())
296
0
      {
297
0
        throw std::runtime_error("Next layer already exists");
298
0
      }
299
300
5.51k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
301
5.51k
      setNextLayer(newLayer);
302
5.51k
      return newLayer;
303
5.51k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::PPPoESessionLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
294
47.3k
    {
295
47.3k
      if (hasNextLayer())
296
0
      {
297
0
        throw std::runtime_error("Next layer already exists");
298
0
      }
299
300
47.3k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
301
47.3k
      setNextLayer(newLayer);
302
47.3k
      return newLayer;
303
47.3k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::PPPoEDiscoveryLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
294
732
    {
295
732
      if (hasNextLayer())
296
0
      {
297
0
        throw std::runtime_error("Next layer already exists");
298
0
      }
299
300
732
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
301
732
      setNextLayer(newLayer);
302
732
      return newLayer;
303
732
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::LLCLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
294
6.56k
    {
295
6.56k
      if (hasNextLayer())
296
0
      {
297
0
        throw std::runtime_error("Next layer already exists");
298
0
      }
299
300
6.56k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
301
6.56k
      setNextLayer(newLayer);
302
6.56k
      return newLayer;
303
6.56k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::HttpRequestLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
294
6.85k
    {
295
6.85k
      if (hasNextLayer())
296
0
      {
297
0
        throw std::runtime_error("Next layer already exists");
298
0
      }
299
300
6.85k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
301
6.85k
      setNextLayer(newLayer);
302
6.85k
      return newLayer;
303
6.85k
    }
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
56.4k
    {
295
56.4k
      if (hasNextLayer())
296
0
      {
297
0
        throw std::runtime_error("Next layer already exists");
298
0
      }
299
300
56.4k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
301
56.4k
      setNextLayer(newLayer);
302
56.4k
      return newLayer;
303
56.4k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::FtpResponseLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
294
10.2k
    {
295
10.2k
      if (hasNextLayer())
296
0
      {
297
0
        throw std::runtime_error("Next layer already exists");
298
0
      }
299
300
10.2k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
301
10.2k
      setNextLayer(newLayer);
302
10.2k
      return newLayer;
303
10.2k
    }
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.42k
    {
295
3.42k
      if (hasNextLayer())
296
0
      {
297
0
        throw std::runtime_error("Next layer already exists");
298
0
      }
299
300
3.42k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
301
3.42k
      setNextLayer(newLayer);
302
3.42k
      return newLayer;
303
3.42k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::TpktLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
294
23.4k
    {
295
23.4k
      if (hasNextLayer())
296
0
      {
297
0
        throw std::runtime_error("Next layer already exists");
298
0
      }
299
300
23.4k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
301
23.4k
      setNextLayer(newLayer);
302
23.4k
      return newLayer;
303
23.4k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::SmtpResponseLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
294
126
    {
295
126
      if (hasNextLayer())
296
0
      {
297
0
        throw std::runtime_error("Next layer already exists");
298
0
      }
299
300
126
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
301
126
      setNextLayer(newLayer);
302
126
      return newLayer;
303
126
    }
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
21.1k
    {
295
21.1k
      if (hasNextLayer())
296
0
      {
297
0
        throw std::runtime_error("Next layer already exists");
298
0
      }
299
300
21.1k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
301
21.1k
      setNextLayer(newLayer);
302
21.1k
      return newLayer;
303
21.1k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::DhcpLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
294
15.7k
    {
295
15.7k
      if (hasNextLayer())
296
0
      {
297
0
        throw std::runtime_error("Next layer already exists");
298
0
      }
299
300
15.7k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
301
15.7k
      setNextLayer(newLayer);
302
15.7k
      return newLayer;
303
15.7k
    }
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.1k
    {
295
58.1k
      if (hasNextLayer())
296
0
      {
297
0
        throw std::runtime_error("Next layer already exists");
298
0
      }
299
300
58.1k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
301
58.1k
      setNextLayer(newLayer);
302
58.1k
      return newLayer;
303
58.1k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::RadiusLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
294
12.8k
    {
295
12.8k
      if (hasNextLayer())
296
0
      {
297
0
        throw std::runtime_error("Next layer already exists");
298
0
      }
299
300
12.8k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
301
12.8k
      setNextLayer(newLayer);
302
12.8k
      return newLayer;
303
12.8k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::GtpV1Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
294
34.5k
    {
295
34.5k
      if (hasNextLayer())
296
0
      {
297
0
        throw std::runtime_error("Next layer already exists");
298
0
      }
299
300
34.5k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
301
34.5k
      setNextLayer(newLayer);
302
34.5k
      return newLayer;
303
34.5k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::DhcpV6Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
294
20.8k
    {
295
20.8k
      if (hasNextLayer())
296
0
      {
297
0
        throw std::runtime_error("Next layer already exists");
298
0
      }
299
300
20.8k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
301
20.8k
      setNextLayer(newLayer);
302
20.8k
      return newLayer;
303
20.8k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::NtpLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
294
17.1k
    {
295
17.1k
      if (hasNextLayer())
296
0
      {
297
0
        throw std::runtime_error("Next layer already exists");
298
0
      }
299
300
17.1k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
301
17.1k
      setNextLayer(newLayer);
302
17.1k
      return newLayer;
303
17.1k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::WakeOnLanLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
294
495
    {
295
495
      if (hasNextLayer())
296
0
      {
297
0
        throw std::runtime_error("Next layer already exists");
298
0
      }
299
300
495
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
301
495
      setNextLayer(newLayer);
302
495
      return newLayer;
303
495
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::S7CommLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
294
15.1k
    {
295
15.1k
      if (hasNextLayer())
296
0
      {
297
0
        throw std::runtime_error("Next layer already exists");
298
0
      }
299
300
15.1k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
301
15.1k
      setNextLayer(newLayer);
302
15.1k
      return newLayer;
303
15.1k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::SdpLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
294
45.3k
    {
295
45.3k
      if (hasNextLayer())
296
0
      {
297
0
        throw std::runtime_error("Next layer already exists");
298
0
      }
299
300
45.3k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
301
45.3k
      setNextLayer(newLayer);
302
45.3k
      return newLayer;
303
45.3k
    }
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
472k
    {
325
472k
      return constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, getAttachedPacket(),
326
472k
                                                     std::forward<Args>(extraArgs)...);
327
472k
    }
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
145k
    {
325
145k
      return constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, getAttachedPacket(),
326
145k
                                                     std::forward<Args>(extraArgs)...);
327
145k
    }
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
58.9k
    {
325
58.9k
      return constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, getAttachedPacket(),
326
58.9k
                                                     std::forward<Args>(extraArgs)...);
327
58.9k
    }
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
225k
    {
325
225k
      return constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, getAttachedPacket(),
326
225k
                                                     std::forward<Args>(extraArgs)...);
327
225k
    }
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
18.3k
    {
325
18.3k
      return constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, getAttachedPacket(),
326
18.3k
                                                     std::forward<Args>(extraArgs)...);
327
18.3k
    }
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.4k
    {
325
24.4k
      return constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, getAttachedPacket(),
326
24.4k
                                                     std::forward<Args>(extraArgs)...);
327
24.4k
    }
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
747k
    {
349
747k
      if (hasNextLayer())
350
0
      {
351
0
        throw std::runtime_error("Next layer already exists");
352
0
      }
353
354
      // cppcheck-suppress redundantInitialization
355
747k
      Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
356
747k
      setNextLayer(newLayer);
357
747k
      return newLayer;
358
747k
    }
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
199k
    {
349
199k
      if (hasNextLayer())
350
0
      {
351
0
        throw std::runtime_error("Next layer already exists");
352
0
      }
353
354
      // cppcheck-suppress redundantInitialization
355
199k
      Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
356
199k
      setNextLayer(newLayer);
357
199k
      return newLayer;
358
199k
    }
pcpp::Layer* pcpp::Layer::constructNextLayerFromFactory<pcpp::Layer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*)>(pcpp::Layer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*), unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
348
58.9k
    {
349
58.9k
      if (hasNextLayer())
350
0
      {
351
0
        throw std::runtime_error("Next layer already exists");
352
0
      }
353
354
      // cppcheck-suppress redundantInitialization
355
58.9k
      Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
356
58.9k
      setNextLayer(newLayer);
357
58.9k
      return newLayer;
358
58.9k
    }
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
225k
    {
349
225k
      if (hasNextLayer())
350
0
      {
351
0
        throw std::runtime_error("Next layer already exists");
352
0
      }
353
354
      // cppcheck-suppress redundantInitialization
355
225k
      Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
356
225k
      setNextLayer(newLayer);
357
225k
      return newLayer;
358
225k
    }
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
18.3k
    {
349
18.3k
      if (hasNextLayer())
350
0
      {
351
0
        throw std::runtime_error("Next layer already exists");
352
0
      }
353
354
      // cppcheck-suppress redundantInitialization
355
18.3k
      Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
356
18.3k
      setNextLayer(newLayer);
357
18.3k
      return newLayer;
358
18.3k
    }
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.0k
    {
349
59.0k
      if (hasNextLayer())
350
0
      {
351
0
        throw std::runtime_error("Next layer already exists");
352
0
      }
353
354
      // cppcheck-suppress redundantInitialization
355
59.0k
      Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
356
59.0k
      setNextLayer(newLayer);
357
59.0k
      return newLayer;
358
59.0k
    }
pcpp::Layer* pcpp::Layer::constructNextLayerFromFactory<pcpp::LdapLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*)>(pcpp::LdapLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*), unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
348
65.6k
    {
349
65.6k
      if (hasNextLayer())
350
0
      {
351
0
        throw std::runtime_error("Next layer already exists");
352
0
      }
353
354
      // cppcheck-suppress redundantInitialization
355
65.6k
      Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
356
65.6k
      setNextLayer(newLayer);
357
65.6k
      return newLayer;
358
65.6k
    }
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
109
    {
349
109
      if (hasNextLayer())
350
0
      {
351
0
        throw std::runtime_error("Next layer already exists");
352
0
      }
353
354
      // cppcheck-suppress redundantInitialization
355
109
      Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
356
109
      setNextLayer(newLayer);
357
109
      return newLayer;
358
109
    }
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.21k
    {
349
1.21k
      if (hasNextLayer())
350
0
      {
351
0
        throw std::runtime_error("Next layer already exists");
352
0
      }
353
354
      // cppcheck-suppress redundantInitialization
355
1.21k
      Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
356
1.21k
      setNextLayer(newLayer);
357
1.21k
      return newLayer;
358
1.21k
    }
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
74.5k
    {
349
74.5k
      if (hasNextLayer())
350
0
      {
351
0
        throw std::runtime_error("Next layer already exists");
352
0
      }
353
354
      // cppcheck-suppress redundantInitialization
355
74.5k
      Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
356
74.5k
      setNextLayer(newLayer);
357
74.5k
      return newLayer;
358
74.5k
    }
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.08k
    {
349
2.08k
      if (hasNextLayer())
350
0
      {
351
0
        throw std::runtime_error("Next layer already exists");
352
0
      }
353
354
      // cppcheck-suppress redundantInitialization
355
2.08k
      Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
356
2.08k
      setNextLayer(newLayer);
357
2.08k
      return newLayer;
358
2.08k
    }
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.2k
    {
349
42.2k
      if (hasNextLayer())
350
0
      {
351
0
        throw std::runtime_error("Next layer already exists");
352
0
      }
353
354
      // cppcheck-suppress redundantInitialization
355
42.2k
      Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
356
42.2k
      setNextLayer(newLayer);
357
42.2k
      return newLayer;
358
42.2k
    }
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.58M
    {
394
2.58M
      if (T::isDataValid(data, dataLen))
395
2.54M
      {
396
2.54M
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
397
2.54M
      }
398
42.3k
      return nullptr;
399
2.58M
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::IPv4Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
393
969k
    {
394
969k
      if (T::isDataValid(data, dataLen))
395
953k
      {
396
953k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
397
953k
      }
398
16.8k
      return nullptr;
399
969k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::IPv6Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
393
173k
    {
394
173k
      if (T::isDataValid(data, dataLen))
395
169k
      {
396
169k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
397
169k
      }
398
4.33k
      return nullptr;
399
173k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::PPP_PPTPLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
393
72.1k
    {
394
72.1k
      if (T::isDataValid(data, dataLen))
395
72.1k
      {
396
72.1k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
397
72.1k
      }
398
0
      return nullptr;
399
72.1k
    }
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
362k
    {
394
362k
      if (T::isDataValid(data, dataLen))
395
360k
      {
396
360k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
397
360k
      }
398
2.53k
      return nullptr;
399
362k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::TcpLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
393
560k
    {
394
560k
      if (T::isDataValid(data, dataLen))
395
547k
      {
396
547k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
397
547k
      }
398
13.0k
      return nullptr;
399
560k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::IcmpLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
393
45.3k
    {
394
45.3k
      if (T::isDataValid(data, dataLen))
395
44.1k
      {
396
44.1k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
397
44.1k
      }
398
1.16k
      return nullptr;
399
45.3k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::GREv0Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
393
10.6k
    {
394
10.6k
      if (T::isDataValid(data, dataLen))
395
10.6k
      {
396
10.6k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
397
10.6k
      }
398
0
      return nullptr;
399
10.6k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::GREv1Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
393
79.9k
    {
394
79.9k
      if (T::isDataValid(data, dataLen))
395
79.9k
      {
396
79.9k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
397
79.9k
      }
398
60
      return nullptr;
399
79.9k
    }
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.96k
    {
394
7.96k
      if (T::isDataValid(data, dataLen))
395
7.96k
      {
396
7.96k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
397
7.96k
      }
398
0
      return nullptr;
399
7.96k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::IgmpV3QueryLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
393
1.87k
    {
394
1.87k
      if (T::isDataValid(data, dataLen))
395
1.87k
      {
396
1.87k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
397
1.87k
      }
398
0
      return nullptr;
399
1.87k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::IgmpV3ReportLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
393
2.23k
    {
394
2.23k
      if (T::isDataValid(data, dataLen))
395
2.23k
      {
396
2.23k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
397
2.23k
      }
398
0
      return nullptr;
399
2.23k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::AuthenticationHeaderLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
393
5.53k
    {
394
5.53k
      if (T::isDataValid(data, dataLen))
395
5.15k
      {
396
5.15k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
397
5.15k
      }
398
379
      return nullptr;
399
5.53k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::ESPLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
393
6.65k
    {
394
6.65k
      if (T::isDataValid(data, dataLen))
395
6.58k
      {
396
6.58k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
397
6.58k
      }
398
70
      return nullptr;
399
6.65k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::VrrpV2Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
393
3.90k
    {
394
3.90k
      if (T::isDataValid(data, dataLen))
395
3.90k
      {
396
3.90k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
397
3.90k
      }
398
0
      return nullptr;
399
3.90k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::VrrpV3Layer, pcpp::IPAddress::AddressType>(unsigned char*, unsigned long, pcpp::Packet*, pcpp::IPAddress::AddressType&&)
Line
Count
Source
393
3.70k
    {
394
3.70k
      if (T::isDataValid(data, dataLen))
395
3.70k
      {
396
3.70k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
397
3.70k
      }
398
0
      return nullptr;
399
3.70k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::PPPoESessionLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
393
47.3k
    {
394
47.3k
      if (T::isDataValid(data, dataLen))
395
47.3k
      {
396
47.3k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
397
47.3k
      }
398
14
      return nullptr;
399
47.3k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::PPPoEDiscoveryLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
393
735
    {
394
735
      if (T::isDataValid(data, dataLen))
395
732
      {
396
732
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
397
732
      }
398
3
      return nullptr;
399
735
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::LLCLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
393
6.94k
    {
394
6.94k
      if (T::isDataValid(data, dataLen))
395
6.56k
      {
396
6.56k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
397
6.56k
      }
398
383
      return nullptr;
399
6.94k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::CotpLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
393
23.4k
    {
394
23.4k
      if (T::isDataValid(data, dataLen))
395
21.1k
      {
396
21.1k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
397
21.1k
      }
398
2.30k
      return nullptr;
399
23.4k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::DhcpLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
393
15.9k
    {
394
15.9k
      if (T::isDataValid(data, dataLen))
395
15.7k
      {
396
15.7k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
397
15.7k
      }
398
208
      return nullptr;
399
15.9k
    }
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
15.8k
    {
394
15.8k
      if (T::isDataValid(data, dataLen))
395
15.1k
      {
396
15.1k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
397
15.1k
      }
398
716
      return nullptr;
399
15.8k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::ArpLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
393
3.65k
    {
394
3.65k
      if (T::isDataValid(data, dataLen))
395
3.60k
      {
396
3.60k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
397
3.60k
      }
398
57
      return nullptr;
399
3.65k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::VlanLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
393
161k
    {
394
161k
      if (T::isDataValid(data, dataLen))
395
160k
      {
396
160k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
397
160k
      }
398
198
      return nullptr;
399
161k
    }
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.64M
    {
420
1.64M
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
421
1.64M
                                                             std::forward<Args>(extraArgs)...);
422
1.64M
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::IPv4Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
419
968k
    {
420
968k
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
421
968k
                                                             std::forward<Args>(extraArgs)...);
422
968k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::IPv6Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
419
173k
    {
420
173k
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
421
173k
                                                             std::forward<Args>(extraArgs)...);
422
173k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::PPP_PPTPLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
419
72.1k
    {
420
72.1k
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
421
72.1k
                                                             std::forward<Args>(extraArgs)...);
422
72.1k
    }
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
36.7k
    {
420
36.7k
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
421
36.7k
                                                             std::forward<Args>(extraArgs)...);
422
36.7k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::TcpLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
419
102k
    {
420
102k
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
421
102k
                                                             std::forward<Args>(extraArgs)...);
422
102k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::GREv0Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
419
7.08k
    {
420
7.08k
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
421
7.08k
                                                             std::forward<Args>(extraArgs)...);
422
7.08k
    }
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.60k
    {
420
3.60k
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
421
3.60k
                                                             std::forward<Args>(extraArgs)...);
422
3.60k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::PPPoESessionLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
419
47.3k
    {
420
47.3k
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
421
47.3k
                                                             std::forward<Args>(extraArgs)...);
422
47.3k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::PPPoEDiscoveryLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
419
735
    {
420
735
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
421
735
                                                             std::forward<Args>(extraArgs)...);
422
735
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::LLCLayer, 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::CotpLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
419
23.4k
    {
420
23.4k
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
421
23.4k
                                                             std::forward<Args>(extraArgs)...);
422
23.4k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::DhcpLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
419
15.9k
    {
420
15.9k
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
421
15.9k
                                                             std::forward<Args>(extraArgs)...);
422
15.9k
    }
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
15.8k
    {
420
15.8k
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
421
15.8k
                                                             std::forward<Args>(extraArgs)...);
422
15.8k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::ArpLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
419
3.65k
    {
420
3.65k
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
421
3.65k
                                                             std::forward<Args>(extraArgs)...);
422
3.65k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::VlanLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
419
161k
    {
420
161k
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
421
161k
                                                             std::forward<Args>(extraArgs)...);
422
161k
    }
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.58M
    {
442
2.58M
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
443
2.54M
      {
444
2.54M
        return m_NextLayer;
445
2.54M
      }
446
447
42.3k
      return constructNextLayer<TFallback>(data, dataLen, packet);
448
2.58M
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::IPv4Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
441
969k
    {
442
969k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
443
953k
      {
444
953k
        return m_NextLayer;
445
953k
      }
446
447
16.8k
      return constructNextLayer<TFallback>(data, dataLen, packet);
448
969k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::IPv6Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
441
173k
    {
442
173k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
443
169k
      {
444
169k
        return m_NextLayer;
445
169k
      }
446
447
4.33k
      return constructNextLayer<TFallback>(data, dataLen, packet);
448
173k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::PPP_PPTPLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
441
72.1k
    {
442
72.1k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
443
72.1k
      {
444
72.1k
        return m_NextLayer;
445
72.1k
      }
446
447
0
      return constructNextLayer<TFallback>(data, dataLen, packet);
448
72.1k
    }
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
362k
    {
442
362k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
443
360k
      {
444
360k
        return m_NextLayer;
445
360k
      }
446
447
2.53k
      return constructNextLayer<TFallback>(data, dataLen, packet);
448
362k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::TcpLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
441
560k
    {
442
560k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
443
547k
      {
444
547k
        return m_NextLayer;
445
547k
      }
446
447
13.0k
      return constructNextLayer<TFallback>(data, dataLen, packet);
448
560k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::IcmpLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
441
45.3k
    {
442
45.3k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
443
44.1k
      {
444
44.1k
        return m_NextLayer;
445
44.1k
      }
446
447
1.16k
      return constructNextLayer<TFallback>(data, dataLen, packet);
448
45.3k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::GREv0Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
441
10.6k
    {
442
10.6k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
443
10.6k
      {
444
10.6k
        return m_NextLayer;
445
10.6k
      }
446
447
0
      return constructNextLayer<TFallback>(data, dataLen, packet);
448
10.6k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::GREv1Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
441
79.9k
    {
442
79.9k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
443
79.9k
      {
444
79.9k
        return m_NextLayer;
445
79.9k
      }
446
447
60
      return constructNextLayer<TFallback>(data, dataLen, packet);
448
79.9k
    }
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.96k
    {
442
7.96k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
443
7.96k
      {
444
7.96k
        return m_NextLayer;
445
7.96k
      }
446
447
0
      return constructNextLayer<TFallback>(data, dataLen, packet);
448
7.96k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::IgmpV3QueryLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
441
1.87k
    {
442
1.87k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
443
1.87k
      {
444
1.87k
        return m_NextLayer;
445
1.87k
      }
446
447
0
      return constructNextLayer<TFallback>(data, dataLen, packet);
448
1.87k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::IgmpV3ReportLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
441
2.23k
    {
442
2.23k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
443
2.23k
      {
444
2.23k
        return m_NextLayer;
445
2.23k
      }
446
447
0
      return constructNextLayer<TFallback>(data, dataLen, packet);
448
2.23k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::AuthenticationHeaderLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
441
5.53k
    {
442
5.53k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
443
5.15k
      {
444
5.15k
        return m_NextLayer;
445
5.15k
      }
446
447
379
      return constructNextLayer<TFallback>(data, dataLen, packet);
448
5.53k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::ESPLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
441
6.65k
    {
442
6.65k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
443
6.58k
      {
444
6.58k
        return m_NextLayer;
445
6.58k
      }
446
447
70
      return constructNextLayer<TFallback>(data, dataLen, packet);
448
6.65k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::VrrpV2Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
441
3.90k
    {
442
3.90k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
443
3.90k
      {
444
3.90k
        return m_NextLayer;
445
3.90k
      }
446
447
0
      return constructNextLayer<TFallback>(data, dataLen, packet);
448
3.90k
    }
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.70k
    {
442
3.70k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
443
3.70k
      {
444
3.70k
        return m_NextLayer;
445
3.70k
      }
446
447
0
      return constructNextLayer<TFallback>(data, dataLen, packet);
448
3.70k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::PPPoESessionLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
441
47.3k
    {
442
47.3k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
443
47.3k
      {
444
47.3k
        return m_NextLayer;
445
47.3k
      }
446
447
14
      return constructNextLayer<TFallback>(data, dataLen, packet);
448
47.3k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::PPPoEDiscoveryLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
441
735
    {
442
735
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
443
732
      {
444
732
        return m_NextLayer;
445
732
      }
446
447
3
      return constructNextLayer<TFallback>(data, dataLen, packet);
448
735
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::LLCLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
441
6.94k
    {
442
6.94k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
443
6.56k
      {
444
6.56k
        return m_NextLayer;
445
6.56k
      }
446
447
383
      return constructNextLayer<TFallback>(data, dataLen, packet);
448
6.94k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::CotpLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
441
23.4k
    {
442
23.4k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
443
21.1k
      {
444
21.1k
        return m_NextLayer;
445
21.1k
      }
446
447
2.30k
      return constructNextLayer<TFallback>(data, dataLen, packet);
448
23.4k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::DhcpLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
441
15.9k
    {
442
15.9k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
443
15.7k
      {
444
15.7k
        return m_NextLayer;
445
15.7k
      }
446
447
208
      return constructNextLayer<TFallback>(data, dataLen, packet);
448
15.9k
    }
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
15.8k
    {
442
15.8k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
443
15.1k
      {
444
15.1k
        return m_NextLayer;
445
15.1k
      }
446
447
716
      return constructNextLayer<TFallback>(data, dataLen, packet);
448
15.8k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::ArpLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
441
3.65k
    {
442
3.65k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
443
3.60k
      {
444
3.60k
        return m_NextLayer;
445
3.60k
      }
446
447
57
      return constructNextLayer<TFallback>(data, dataLen, packet);
448
3.65k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::VlanLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
441
161k
    {
442
161k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
443
160k
      {
444
160k
        return m_NextLayer;
445
160k
      }
446
447
198
      return constructNextLayer<TFallback>(data, dataLen, packet);
448
161k
    }
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
274k
    {
475
      // Note that the fallback is first to allow template argument deduction of the factory type.
476
274k
      return tryConstructNextLayerFromFactoryWithFallback<TFallback, TFactory>(
477
274k
          factoryFn, data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
478
274k
    }
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.1k
    {
475
      // Note that the fallback is first to allow template argument deduction of the factory type.
476
54.1k
      return tryConstructNextLayerFromFactoryWithFallback<TFallback, TFactory>(
477
54.1k
          factoryFn, data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
478
54.1k
    }
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.0k
    {
475
      // Note that the fallback is first to allow template argument deduction of the factory type.
476
59.0k
      return tryConstructNextLayerFromFactoryWithFallback<TFallback, TFactory>(
477
59.0k
          factoryFn, data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
478
59.0k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerFromFactoryWithFallback<pcpp::PayloadLayer, pcpp::LdapLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*)>(pcpp::LdapLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*), unsigned char*, unsigned long)
Line
Count
Source
474
41.2k
    {
475
      // Note that the fallback is first to allow template argument deduction of the factory type.
476
41.2k
      return tryConstructNextLayerFromFactoryWithFallback<TFallback, TFactory>(
477
41.2k
          factoryFn, data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
478
41.2k
    }
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
109
    {
475
      // Note that the fallback is first to allow template argument deduction of the factory type.
476
109
      return tryConstructNextLayerFromFactoryWithFallback<TFallback, TFactory>(
477
109
          factoryFn, data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
478
109
    }
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.21k
    {
475
      // Note that the fallback is first to allow template argument deduction of the factory type.
476
1.21k
      return tryConstructNextLayerFromFactoryWithFallback<TFallback, TFactory>(
477
1.21k
          factoryFn, data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
478
1.21k
    }
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
74.5k
    {
475
      // Note that the fallback is first to allow template argument deduction of the factory type.
476
74.5k
      return tryConstructNextLayerFromFactoryWithFallback<TFallback, TFactory>(
477
74.5k
          factoryFn, data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
478
74.5k
    }
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.08k
    {
475
      // Note that the fallback is first to allow template argument deduction of the factory type.
476
2.08k
      return tryConstructNextLayerFromFactoryWithFallback<TFallback, TFactory>(
477
2.08k
          factoryFn, data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
478
2.08k
    }
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.2k
    {
475
      // Note that the fallback is first to allow template argument deduction of the factory type.
476
42.2k
      return tryConstructNextLayerFromFactoryWithFallback<TFallback, TFactory>(
477
42.2k
          factoryFn, data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
478
42.2k
    }
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
274k
    {
504
274k
      auto nextLayer = constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, packet,
505
274k
                                                               std::forward<Args>(extraArgs)...);
506
274k
      if (nextLayer != nullptr)
507
215k
      {
508
215k
        return nextLayer;
509
215k
      }
510
511
      // factory failed, construct fallback layer
512
59.4k
      return constructNextLayer<TFallback>(data, dataLen, packet);
513
274k
    }
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.1k
    {
504
54.1k
      auto nextLayer = constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, packet,
505
54.1k
                                                               std::forward<Args>(extraArgs)...);
506
54.1k
      if (nextLayer != nullptr)
507
50.5k
      {
508
50.5k
        return nextLayer;
509
50.5k
      }
510
511
      // factory failed, construct fallback layer
512
3.62k
      return constructNextLayer<TFallback>(data, dataLen, packet);
513
54.1k
    }
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.0k
    {
504
59.0k
      auto nextLayer = constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, packet,
505
59.0k
                                                               std::forward<Args>(extraArgs)...);
506
59.0k
      if (nextLayer != nullptr)
507
58.4k
      {
508
58.4k
        return nextLayer;
509
58.4k
      }
510
511
      // factory failed, construct fallback layer
512
588
      return constructNextLayer<TFallback>(data, dataLen, packet);
513
59.0k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerFromFactoryWithFallback<pcpp::PayloadLayer, pcpp::LdapLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*)>(pcpp::LdapLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*), unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
503
41.2k
    {
504
41.2k
      auto nextLayer = constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, packet,
505
41.2k
                                                               std::forward<Args>(extraArgs)...);
506
41.2k
      if (nextLayer != nullptr)
507
32.0k
      {
508
32.0k
        return nextLayer;
509
32.0k
      }
510
511
      // factory failed, construct fallback layer
512
9.13k
      return constructNextLayer<TFallback>(data, dataLen, packet);
513
41.2k
    }
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
109
    {
504
109
      auto nextLayer = constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, packet,
505
109
                                                               std::forward<Args>(extraArgs)...);
506
109
      if (nextLayer != nullptr)
507
109
      {
508
109
        return nextLayer;
509
109
      }
510
511
      // factory failed, construct fallback layer
512
0
      return constructNextLayer<TFallback>(data, dataLen, packet);
513
109
    }
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.21k
    {
504
1.21k
      auto nextLayer = constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, packet,
505
1.21k
                                                               std::forward<Args>(extraArgs)...);
506
1.21k
      if (nextLayer != nullptr)
507
1.21k
      {
508
1.21k
        return nextLayer;
509
1.21k
      }
510
511
      // factory failed, construct fallback layer
512
0
      return constructNextLayer<TFallback>(data, dataLen, packet);
513
1.21k
    }
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
74.5k
    {
504
74.5k
      auto nextLayer = constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, packet,
505
74.5k
                                                               std::forward<Args>(extraArgs)...);
506
74.5k
      if (nextLayer != nullptr)
507
70.4k
      {
508
70.4k
        return nextLayer;
509
70.4k
      }
510
511
      // factory failed, construct fallback layer
512
4.12k
      return constructNextLayer<TFallback>(data, dataLen, packet);
513
74.5k
    }
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.08k
    {
504
2.08k
      auto nextLayer = constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, packet,
505
2.08k
                                                               std::forward<Args>(extraArgs)...);
506
2.08k
      if (nextLayer != nullptr)
507
2.08k
      {
508
2.08k
        return nextLayer;
509
2.08k
      }
510
511
      // factory failed, construct fallback layer
512
0
      return constructNextLayer<TFallback>(data, dataLen, packet);
513
2.08k
    }
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.2k
    {
504
42.2k
      auto nextLayer = constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, packet,
505
42.2k
                                                               std::forward<Args>(extraArgs)...);
506
42.2k
      if (nextLayer != nullptr)
507
325
      {
508
325
        return nextLayer;
509
325
      }
510
511
      // factory failed, construct fallback layer
512
41.9k
      return constructNextLayer<TFallback>(data, dataLen, packet);
513
42.2k
    }
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.71M
    {
525
1.71M
      return data != nullptr && dataLen >= sizeof(T);
526
1.71M
    }
bool pcpp::Layer::canReinterpretAs<pcpp::arphdr>(unsigned char const*, unsigned long)
Line
Count
Source
524
3.65k
    {
525
3.65k
      return data != nullptr && dataLen >= sizeof(T);
526
3.65k
    }
bool pcpp::Layer::canReinterpretAs<pcpp::iphdr>(unsigned char const*, unsigned long)
Line
Count
Source
524
970k
    {
525
970k
      return data != nullptr && dataLen >= sizeof(T);
526
970k
    }
bool pcpp::Layer::canReinterpretAs<pcpp::dhcp_header>(unsigned char const*, unsigned long)
Line
Count
Source
524
15.9k
    {
525
15.9k
      return data != nullptr && dataLen >= sizeof(T);
526
15.9k
    }
bool pcpp::Layer::canReinterpretAs<pcpp::vrrp_header>(unsigned char const*, unsigned long)
Line
Count
Source
524
7.60k
    {
525
7.60k
      return data != nullptr && dataLen >= sizeof(T);
526
7.60k
    }
bool pcpp::Layer::canReinterpretAs<pcpp::ip6_hdr>(unsigned char const*, unsigned long)
Line
Count
Source
524
174k
    {
525
174k
      return data != nullptr && dataLen >= sizeof(T);
526
174k
    }
bool pcpp::Layer::canReinterpretAs<pcpp::vlan_header>(unsigned char const*, unsigned long)
Line
Count
Source
524
161k
    {
525
161k
      return data != nullptr && dataLen >= sizeof(T);
526
161k
    }
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.1k
    {
525
11.1k
      return data != nullptr && dataLen >= sizeof(T);
526
11.1k
    }
bool pcpp::Layer::canReinterpretAs<pcpp::igmpv3_query_header>(unsigned char const*, unsigned long)
Line
Count
Source
524
1.87k
    {
525
1.87k
      return data != nullptr && dataLen >= sizeof(T);
526
1.87k
    }
bool pcpp::Layer::canReinterpretAs<pcpp::igmpv3_report_header>(unsigned char const*, unsigned long)
Line
Count
Source
524
2.23k
    {
525
2.23k
      return data != nullptr && dataLen >= sizeof(T);
526
2.23k
    }
bool pcpp::Layer::canReinterpretAs<pcpp::ssl_tls_record_layer>(unsigned char const*, unsigned long)
Line
Count
Source
524
225k
    {
525
225k
      return data != nullptr && dataLen >= sizeof(T);
526
225k
    }
bool pcpp::Layer::canReinterpretAs<pcpp::tpkthdr>(unsigned char const*, unsigned long)
Line
Count
Source
524
141k
    {
525
141k
      return data != nullptr && dataLen >= sizeof(T);
526
141k
    }
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