Coverage Report

Created: 2026-02-26 06:41

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