Coverage Report

Created: 2026-03-07 06:49

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
14.2M
    virtual ~IDataContainer() = default;
29
  };
30
31
  class Packet;
32
33
  namespace internal
34
  {
35
    /// @brief Holds information about a Layer's data and object ownership.
36
    struct LayerAllocationInfo
37
    {
38
      /// @brief Pointer to the Packet this layer is attached to (if any).
39
      ///
40
      /// If the layer is attached to a Packet, the layer's memory span (data) is considered managed by the
41
      /// Packet. The Packet is responsible for keeping the layer's memory span valid and updating it should it
42
      /// become necessary as long as the layer is attached to it.
43
      ///
44
      /// In an event the Packet is destroyed, all of its attached layers's memory views are considered invalid.
45
      /// Accessing layer data after the Packet is destroyed results in undefined behavior.
46
      ///
47
      /// If nullptr, the layer is not attached to any Packet and is considered unmanaged.
48
      /// It also means the layer's memory span is considered owned by the layer itself and will be freed when
49
      /// the layer is destroyed.
50
      Packet* attachedPacket = nullptr;
51
52
      /// @brief Controls if the layer object is considered owned by the attached Packet
53
      ///
54
      /// If 'true', the Layer object is considered owned by the attached Packet and will be freed by it on Packet
55
      /// destruction.
56
      ///
57
      /// If 'false', the Layer object is considered unmanaged and the user is responsible for freeing it.
58
      /// This is commonly the case for layers created on the stack and attached to a Packet.
59
      bool ownedByPacket = false;
60
61
      /// @brief Sets the state of attachment to a specified Packet
62
      /// @param packet Pointer to the Packet this layer is attached to (or nullptr if not attached to any Packet)
63
      /// @param managed True if the layer object's lifetime is to be managed by the Packet, false otherwise
64
      /// @param force If true, bypasses the check for existing attachment. Default is false.
65
      /// @throws std::runtime_error if the layer is already attached to a Packet and 'force' is false
66
      void attachPacket(Packet* packet, bool managed, bool force = false)
67
0
      {
68
0
        if (!force && attachedPacket != nullptr)
69
0
        {
70
0
          throw std::runtime_error("Layer is already attached to a Packet");
71
0
        }
72
0
73
0
        attachedPacket = packet;
74
0
        ownedByPacket = managed;
75
0
      }
76
77
      /// @brief Clears the attachment to any Packet, resetting to unmanaged state.
78
      void detach()
79
0
      {
80
0
        attachedPacket = nullptr;
81
0
        ownedByPacket = false;
82
0
      }
83
    };
84
  }  // namespace internal
85
86
  /// @class Layer
87
  /// Layer is the base class for all protocol layers. Each protocol supported in PcapPlusPlus has a class that
88
  /// inherits Layer.
89
  /// The protocol layer class expose all properties and methods relevant for viewing and editing protocol fields.
90
  /// For example: a pointer to a structured header (e.g tcphdr, iphdr, etc.), protocol header size, payload size,
91
  /// compute fields that can be automatically computed, print protocol data to string, etc.
92
  /// Each protocol instance is obviously part of a protocol stack (which construct a packet). This protocol stack is
93
  /// represented in PcapPlusPlus in a linked list, and each layer is an element in this list. That's why each layer
94
  /// has properties to the next and previous layer in the protocol stack. The Layer class, as a base class, is
95
  /// abstract and the user can't create an instance of it (it has a private constructor). Each layer holds a pointer
96
  /// to the relevant place in the packet. The layer sees all the data from this pointer forward until the end of the
97
  /// packet. Here is an example packet showing this concept:
98
  ///
99
  /// @code{.unparsed}
100
  /// ====================================================
101
  /// |Eth       |IPv4       |TCP       |Packet          |
102
  /// |Header    |Header     |Header    |Payload         |
103
  /// ====================================================
104
  ///
105
  /// |--------------------------------------------------|
106
  /// EthLayer data
107
  ///            |---------------------------------------|
108
  ///            IPv4Layer data
109
  ///                        |---------------------------|
110
  ///                        TcpLayer data
111
  ///                                   |----------------|
112
  ///                                   PayloadLayer data
113
  /// @endcode
114
  class Layer : public IDataContainer
115
  {
116
    friend class Packet;
117
118
  public:
119
    /// A destructor for this class. Frees the data if it was allocated by the layer constructor (see
120
    /// isAllocatedToPacket() for more info)
121
    ~Layer() override;
122
123
    /// @return A pointer to the next layer in the protocol stack or nullptr if the layer is the last one
124
    Layer* getNextLayer() const
125
282M
    {
126
282M
      return m_NextLayer;
127
282M
    }
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
3.92M
    {
132
3.92M
      return m_PrevLayer;
133
3.92M
    }
134
135
    /// @return The protocol enum
136
    ProtocolType getProtocol() const
137
204M
    {
138
204M
      return m_Protocol;
139
204M
    }
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
598k
    {
149
598k
      return m_Data;
150
598k
    }
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
6.35M
    {
155
6.35M
      return m_DataLen;
156
6.35M
    }
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
93.2k
    {
167
93.2k
      return m_DataLen - getHeaderLen();
168
93.2k
    }
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
14.2M
    {
181
14.2M
      return m_AllocationInfo.attachedPacket != nullptr;
182
14.2M
    }
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
272k
    {
192
272k
      return static_cast<uint8_t*>(m_Data + offset);
193
272k
    }
194
195
    // abstract methods
196
197
    /// Each layer is responsible for parsing the next layer
198
    virtual void parseNextLayer() = 0;
199
200
    /// @return The header length in bytes
201
    virtual size_t getHeaderLen() const = 0;
202
203
    /// Each layer can compute field values automatically using this method. This is an abstract method
204
    virtual void computeCalculateFields() = 0;
205
206
    /// @return A string representation of the layer most important data (should look like the layer description in
207
    /// Wireshark)
208
    virtual std::string toString() const = 0;
209
210
    /// @return The OSI Model layer this protocol belongs to
211
    virtual OsiModelLayer getOsiModelLayer() const = 0;
212
213
  protected:
214
    uint8_t* m_Data;
215
    size_t m_DataLen;
216
    ProtocolType m_Protocol;
217
    Layer* m_NextLayer;
218
    Layer* m_PrevLayer;
219
220
  private:
221
    internal::LayerAllocationInfo m_AllocationInfo;
222
223
  protected:
224
    Layer() : m_Data(nullptr), m_DataLen(0), m_Protocol(UnknownProtocol), m_NextLayer(nullptr), m_PrevLayer(nullptr)
225
0
    {}
226
227
    Layer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet, ProtocolType protocol = UnknownProtocol)
228
13.9M
        : m_Data(data), m_DataLen(dataLen), m_Protocol(protocol), m_NextLayer(nullptr), m_PrevLayer(prevLayer),
229
13.9M
          m_AllocationInfo{ packet, false }
230
13.9M
    {}
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
13.4M
    {
240
13.4M
      return m_AllocationInfo.attachedPacket;
241
13.4M
    }
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
5.01k
    {
247
5.01k
      return m_AllocationInfo.attachedPacket;
248
5.01k
    }
249
250
    void setNextLayer(Layer* nextLayer)
251
11.8M
    {
252
11.8M
      m_NextLayer = nextLayer;
253
11.8M
    }
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
18.3M
    {
264
18.3M
      return m_NextLayer != nullptr;
265
18.3M
    }
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
4.69M
    {
280
4.69M
      return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
281
4.69M
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::VlanLayer>(unsigned char*, unsigned long)
Line
Count
Source
279
69.3k
    {
280
69.3k
      return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
281
69.3k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::MplsLayer>(unsigned char*, unsigned long)
Line
Count
Source
279
4.04M
    {
280
4.04M
      return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
281
4.04M
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
279
189k
    {
280
189k
      return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
281
189k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::VrrpV3Layer, pcpp::IPAddress::AddressType>(unsigned char*, unsigned long, pcpp::IPAddress::AddressType&&)
Line
Count
Source
279
6.61k
    {
280
6.61k
      return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
281
6.61k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::ArpLayer>(unsigned char*, unsigned long)
Line
Count
Source
279
8.32k
    {
280
8.32k
      return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
281
8.32k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::DhcpLayer>(unsigned char*, unsigned long)
Line
Count
Source
279
34.3k
    {
280
34.3k
      return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
281
34.3k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::VxlanLayer>(unsigned char*, unsigned long)
Line
Count
Source
279
9.90k
    {
280
9.90k
      return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
281
9.90k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::DnsLayer>(unsigned char*, unsigned long)
Line
Count
Source
279
143k
    {
280
143k
      return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
281
143k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::RadiusLayer>(unsigned char*, unsigned long)
Line
Count
Source
279
32.9k
    {
280
32.9k
      return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
281
32.9k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::GtpV1Layer>(unsigned char*, unsigned long)
Line
Count
Source
279
42.9k
    {
280
42.9k
      return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
281
42.9k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::GtpV2Layer>(unsigned char*, unsigned long)
Line
Count
Source
279
1.06k
    {
280
1.06k
      return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
281
1.06k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::DhcpV6Layer>(unsigned char*, unsigned long)
Line
Count
Source
279
25.6k
    {
280
25.6k
      return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
281
25.6k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::NtpLayer>(unsigned char*, unsigned long)
Line
Count
Source
279
29.8k
    {
280
29.8k
      return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
281
29.8k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::WakeOnLanLayer>(unsigned char*, unsigned long)
Line
Count
Source
279
1.37k
    {
280
1.37k
      return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
281
1.37k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::EthLayer>(unsigned char*, unsigned long)
Line
Count
Source
279
9.51k
    {
280
9.51k
      return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
281
9.51k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::SdpLayer>(unsigned char*, unsigned long)
Line
Count
Source
279
44.3k
    {
280
44.3k
      return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
281
44.3k
    }
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
10.4M
    {
294
10.4M
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
10.4M
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
10.4M
      setNextLayer(newLayer);
301
10.4M
      return newLayer;
302
10.4M
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::IPv4Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
1.86M
    {
294
1.86M
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
1.86M
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
1.86M
      setNextLayer(newLayer);
301
1.86M
      return newLayer;
302
1.86M
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
746k
    {
294
746k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
746k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
746k
      setNextLayer(newLayer);
301
746k
      return newLayer;
302
746k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::IPv6Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
399k
    {
294
399k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
399k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
399k
      setNextLayer(newLayer);
301
399k
      return newLayer;
302
399k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::VlanLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
265k
    {
294
265k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
265k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
265k
      setNextLayer(newLayer);
301
265k
      return newLayer;
302
265k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::MplsLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
4.09M
    {
294
4.09M
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
4.09M
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
4.09M
      setNextLayer(newLayer);
301
4.09M
      return newLayer;
302
4.09M
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::PPP_PPTPLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
79.7k
    {
294
79.7k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
79.7k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
79.7k
      setNextLayer(newLayer);
301
79.7k
      return newLayer;
302
79.7k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::EthLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
9.51k
    {
294
9.51k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
9.51k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
9.51k
      setNextLayer(newLayer);
301
9.51k
      return newLayer;
302
9.51k
    }
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.68k
    {
294
1.68k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
1.68k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
1.68k
      setNextLayer(newLayer);
301
1.68k
      return newLayer;
302
1.68k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::UdpLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
712k
    {
294
712k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
712k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
712k
      setNextLayer(newLayer);
301
712k
      return newLayer;
302
712k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::TcpLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
1.25M
    {
294
1.25M
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
1.25M
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
1.25M
      setNextLayer(newLayer);
301
1.25M
      return newLayer;
302
1.25M
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::IcmpLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
65.1k
    {
294
65.1k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
65.1k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
65.1k
      setNextLayer(newLayer);
301
65.1k
      return newLayer;
302
65.1k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::GREv0Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
18.2k
    {
294
18.2k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
18.2k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
18.2k
      setNextLayer(newLayer);
301
18.2k
      return newLayer;
302
18.2k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::GREv1Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
89.9k
    {
294
89.9k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
89.9k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
89.9k
      setNextLayer(newLayer);
301
89.9k
      return newLayer;
302
89.9k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::IgmpV1Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
6.25k
    {
294
6.25k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
6.25k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
6.25k
      setNextLayer(newLayer);
301
6.25k
      return newLayer;
302
6.25k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::IgmpV2Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
11.0k
    {
294
11.0k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
11.0k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
11.0k
      setNextLayer(newLayer);
301
11.0k
      return newLayer;
302
11.0k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::IgmpV3QueryLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
1.97k
    {
294
1.97k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
1.97k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
1.97k
      setNextLayer(newLayer);
301
1.97k
      return newLayer;
302
1.97k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::IgmpV3ReportLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
3.90k
    {
294
3.90k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
3.90k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
3.90k
      setNextLayer(newLayer);
301
3.90k
      return newLayer;
302
3.90k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::AuthenticationHeaderLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
6.63k
    {
294
6.63k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
6.63k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
6.63k
      setNextLayer(newLayer);
301
6.63k
      return newLayer;
302
6.63k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::ESPLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
6.30k
    {
294
6.30k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
6.30k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
6.30k
      setNextLayer(newLayer);
301
6.30k
      return newLayer;
302
6.30k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::VrrpV2Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
9.60k
    {
294
9.60k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
9.60k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
9.60k
      setNextLayer(newLayer);
301
9.60k
      return newLayer;
302
9.60k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::VrrpV3Layer, pcpp::IPAddress::AddressType>(unsigned char*, unsigned long, pcpp::Packet*, pcpp::IPAddress::AddressType&&)
Line
Count
Source
293
11.7k
    {
294
11.7k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
11.7k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
11.7k
      setNextLayer(newLayer);
301
11.7k
      return newLayer;
302
11.7k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::ArpLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
31.0k
    {
294
31.0k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
31.0k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
31.0k
      setNextLayer(newLayer);
301
31.0k
      return newLayer;
302
31.0k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::PPPoESessionLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
58.0k
    {
294
58.0k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
58.0k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
58.0k
      setNextLayer(newLayer);
301
58.0k
      return newLayer;
302
58.0k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::PPPoEDiscoveryLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
1.21k
    {
294
1.21k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
1.21k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
1.21k
      setNextLayer(newLayer);
301
1.21k
      return newLayer;
302
1.21k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::HttpRequestLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
98.1k
    {
294
98.1k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
98.1k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
98.1k
      setNextLayer(newLayer);
301
98.1k
      return newLayer;
302
98.1k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::HttpResponseLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
26.4k
    {
294
26.4k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
26.4k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
26.4k
      setNextLayer(newLayer);
301
26.4k
      return newLayer;
302
26.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
119
    {
294
119
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
119
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
119
      setNextLayer(newLayer);
301
119
      return newLayer;
302
119
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::DnsOverTcpLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
30.2k
    {
294
30.2k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
30.2k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
30.2k
      setNextLayer(newLayer);
301
30.2k
      return newLayer;
302
30.2k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::TelnetLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
52.7k
    {
294
52.7k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
52.7k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
52.7k
      setNextLayer(newLayer);
301
52.7k
      return newLayer;
302
52.7k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::FtpResponseLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
18.5k
    {
294
18.5k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
18.5k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
18.5k
      setNextLayer(newLayer);
301
18.5k
      return newLayer;
302
18.5k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::FtpRequestLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
4.38k
    {
294
4.38k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
4.38k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
4.38k
      setNextLayer(newLayer);
301
4.38k
      return newLayer;
302
4.38k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::FtpDataLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
4.61k
    {
294
4.61k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
4.61k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
4.61k
      setNextLayer(newLayer);
301
4.61k
      return newLayer;
302
4.61k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::TpktLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
16.0k
    {
294
16.0k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
16.0k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
16.0k
      setNextLayer(newLayer);
301
16.0k
      return newLayer;
302
16.0k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::SmtpResponseLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
6.39k
    {
294
6.39k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
6.39k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
6.39k
      setNextLayer(newLayer);
301
6.39k
      return newLayer;
302
6.39k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::SmtpRequestLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
8.05k
    {
294
8.05k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
8.05k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
8.05k
      setNextLayer(newLayer);
301
8.05k
      return newLayer;
302
8.05k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::ModbusLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
1.66k
    {
294
1.66k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
1.66k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
1.66k
      setNextLayer(newLayer);
301
1.66k
      return newLayer;
302
1.66k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::CotpLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
9.59k
    {
294
9.59k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
9.59k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
9.59k
      setNextLayer(newLayer);
301
9.59k
      return newLayer;
302
9.59k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::DhcpLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
34.3k
    {
294
34.3k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
34.3k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
34.3k
      setNextLayer(newLayer);
301
34.3k
      return newLayer;
302
34.3k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::VxlanLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
9.90k
    {
294
9.90k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
9.90k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
9.90k
      setNextLayer(newLayer);
301
9.90k
      return newLayer;
302
9.90k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::DnsLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
143k
    {
294
143k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
143k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
143k
      setNextLayer(newLayer);
301
143k
      return newLayer;
302
143k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::RadiusLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
32.9k
    {
294
32.9k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
32.9k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
32.9k
      setNextLayer(newLayer);
301
32.9k
      return newLayer;
302
32.9k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::GtpV1Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
42.9k
    {
294
42.9k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
42.9k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
42.9k
      setNextLayer(newLayer);
301
42.9k
      return newLayer;
302
42.9k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::DhcpV6Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
25.6k
    {
294
25.6k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
25.6k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
25.6k
      setNextLayer(newLayer);
301
25.6k
      return newLayer;
302
25.6k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::NtpLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
29.8k
    {
294
29.8k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
29.8k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
29.8k
      setNextLayer(newLayer);
301
29.8k
      return newLayer;
302
29.8k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::WakeOnLanLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
1.39k
    {
294
1.39k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
1.39k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
1.39k
      setNextLayer(newLayer);
301
1.39k
      return newLayer;
302
1.39k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::LLCLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
20.1k
    {
294
20.1k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
20.1k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
20.1k
      setNextLayer(newLayer);
301
20.1k
      return newLayer;
302
20.1k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::S7CommLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
6.28k
    {
294
6.28k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
6.28k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
6.28k
      setNextLayer(newLayer);
301
6.28k
      return newLayer;
302
6.28k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::SdpLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
44.3k
    {
294
44.3k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
44.3k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
44.3k
      setNextLayer(newLayer);
301
44.3k
      return newLayer;
302
44.3k
    }
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
929k
    {
324
929k
      return constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, getAttachedPacket(),
325
929k
                                                     std::forward<Args>(extraArgs)...);
326
929k
    }
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
170k
    {
324
170k
      return constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, getAttachedPacket(),
325
170k
                                                     std::forward<Args>(extraArgs)...);
326
170k
    }
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
133k
    {
324
133k
      return constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, getAttachedPacket(),
325
133k
                                                     std::forward<Args>(extraArgs)...);
326
133k
    }
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
561k
    {
324
561k
      return constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, getAttachedPacket(),
325
561k
                                                     std::forward<Args>(extraArgs)...);
326
561k
    }
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
28.9k
    {
324
28.9k
      return constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, getAttachedPacket(),
325
28.9k
                                                     std::forward<Args>(extraArgs)...);
326
28.9k
    }
pcpp::Layer* pcpp::Layer::constructNextLayerFromFactory<pcpp::LdapLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*)>(pcpp::LdapLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*), unsigned char*, unsigned long)
Line
Count
Source
323
27.3k
    {
324
27.3k
      return constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, getAttachedPacket(),
325
27.3k
                                                     std::forward<Args>(extraArgs)...);
326
27.3k
    }
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.01k
    {
324
7.01k
      return constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, getAttachedPacket(),
325
7.01k
                                                     std::forward<Args>(extraArgs)...);
326
7.01k
    }
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
1.37M
    {
348
1.37M
      if (hasNextLayer())
349
0
      {
350
0
        throw std::runtime_error("Next layer already exists");
351
0
      }
352
353
      // cppcheck-suppress redundantInitialization
354
1.37M
      Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
355
1.37M
      setNextLayer(newLayer);
356
1.37M
      return newLayer;
357
1.37M
    }
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
255k
    {
348
255k
      if (hasNextLayer())
349
0
      {
350
0
        throw std::runtime_error("Next layer already exists");
351
0
      }
352
353
      // cppcheck-suppress redundantInitialization
354
255k
      Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
355
255k
      setNextLayer(newLayer);
356
255k
      return newLayer;
357
255k
    }
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
133k
    {
348
133k
      if (hasNextLayer())
349
0
      {
350
0
        throw std::runtime_error("Next layer already exists");
351
0
      }
352
353
      // cppcheck-suppress redundantInitialization
354
133k
      Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
355
133k
      setNextLayer(newLayer);
356
133k
      return newLayer;
357
133k
    }
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
561k
    {
348
561k
      if (hasNextLayer())
349
0
      {
350
0
        throw std::runtime_error("Next layer already exists");
351
0
      }
352
353
      // cppcheck-suppress redundantInitialization
354
561k
      Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
355
561k
      setNextLayer(newLayer);
356
561k
      return newLayer;
357
561k
    }
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
28.9k
    {
348
28.9k
      if (hasNextLayer())
349
0
      {
350
0
        throw std::runtime_error("Next layer already exists");
351
0
      }
352
353
      // cppcheck-suppress redundantInitialization
354
28.9k
      Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
355
28.9k
      setNextLayer(newLayer);
356
28.9k
      return newLayer;
357
28.9k
    }
pcpp::Layer* pcpp::Layer::constructNextLayerFromFactory<pcpp::DoIpLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*)>(pcpp::DoIpLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*), unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
347
64.3k
    {
348
64.3k
      if (hasNextLayer())
349
0
      {
350
0
        throw std::runtime_error("Next layer already exists");
351
0
      }
352
353
      // cppcheck-suppress redundantInitialization
354
64.3k
      Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
355
64.3k
      setNextLayer(newLayer);
356
64.3k
      return newLayer;
357
64.3k
    }
pcpp::Layer* pcpp::Layer::constructNextLayerFromFactory<pcpp::LdapLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*)>(pcpp::LdapLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*), unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
347
74.4k
    {
348
74.4k
      if (hasNextLayer())
349
0
      {
350
0
        throw std::runtime_error("Next layer already exists");
351
0
      }
352
353
      // cppcheck-suppress redundantInitialization
354
74.4k
      Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
355
74.4k
      setNextLayer(newLayer);
356
74.4k
      return newLayer;
357
74.4k
    }
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
104k
    {
348
104k
      if (hasNextLayer())
349
0
      {
350
0
        throw std::runtime_error("Next layer already exists");
351
0
      }
352
353
      // cppcheck-suppress redundantInitialization
354
104k
      Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
355
104k
      setNextLayer(newLayer);
356
104k
      return newLayer;
357
104k
    }
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
4.28k
    {
348
4.28k
      if (hasNextLayer())
349
0
      {
350
0
        throw std::runtime_error("Next layer already exists");
351
0
      }
352
353
      // cppcheck-suppress redundantInitialization
354
4.28k
      Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
355
4.28k
      setNextLayer(newLayer);
356
4.28k
      return newLayer;
357
4.28k
    }
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
137k
    {
348
137k
      if (hasNextLayer())
349
0
      {
350
0
        throw std::runtime_error("Next layer already exists");
351
0
      }
352
353
      // cppcheck-suppress redundantInitialization
354
137k
      Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
355
137k
      setNextLayer(newLayer);
356
137k
      return newLayer;
357
137k
    }
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.01k
    {
348
7.01k
      if (hasNextLayer())
349
0
      {
350
0
        throw std::runtime_error("Next layer already exists");
351
0
      }
352
353
      // cppcheck-suppress redundantInitialization
354
7.01k
      Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
355
7.01k
      setNextLayer(newLayer);
356
7.01k
      return newLayer;
357
7.01k
    }
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
4.95M
    {
393
4.95M
      if (T::isDataValid(data, dataLen))
394
4.89M
      {
395
4.89M
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
4.89M
      }
397
64.2k
      return nullptr;
398
4.95M
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::IPv4Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
392
1.88M
    {
393
1.88M
      if (T::isDataValid(data, dataLen))
394
1.86M
      {
395
1.86M
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
1.86M
      }
397
21.1k
      return nullptr;
398
1.88M
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::IPv6Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
392
404k
    {
393
404k
      if (T::isDataValid(data, dataLen))
394
399k
      {
395
399k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
399k
      }
397
5.21k
      return nullptr;
398
404k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::PPP_PPTPLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
392
80.4k
    {
393
80.4k
      if (T::isDataValid(data, dataLen))
394
79.7k
      {
395
79.7k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
79.7k
      }
397
717
      return nullptr;
398
80.4k
    }
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
856
    {
393
856
      if (T::isDataValid(data, dataLen))
394
576
      {
395
576
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
576
      }
397
280
      return nullptr;
398
856
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::UdpLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
392
715k
    {
393
715k
      if (T::isDataValid(data, dataLen))
394
712k
      {
395
712k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
712k
      }
397
3.18k
      return nullptr;
398
715k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::TcpLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
392
1.27M
    {
393
1.27M
      if (T::isDataValid(data, dataLen))
394
1.25M
      {
395
1.25M
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
1.25M
      }
397
18.9k
      return nullptr;
398
1.27M
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::IcmpLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
392
67.9k
    {
393
67.9k
      if (T::isDataValid(data, dataLen))
394
65.1k
      {
395
65.1k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
65.1k
      }
397
2.78k
      return nullptr;
398
67.9k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::GREv0Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
392
18.2k
    {
393
18.2k
      if (T::isDataValid(data, dataLen))
394
18.2k
      {
395
18.2k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
18.2k
      }
397
0
      return nullptr;
398
18.2k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::GREv1Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
392
90.2k
    {
393
90.2k
      if (T::isDataValid(data, dataLen))
394
89.9k
      {
395
89.9k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
89.9k
      }
397
274
      return nullptr;
398
90.2k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::IgmpV1Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
392
6.25k
    {
393
6.25k
      if (T::isDataValid(data, dataLen))
394
6.25k
      {
395
6.25k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
6.25k
      }
397
0
      return nullptr;
398
6.25k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::IgmpV2Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
392
11.0k
    {
393
11.0k
      if (T::isDataValid(data, dataLen))
394
11.0k
      {
395
11.0k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
11.0k
      }
397
0
      return nullptr;
398
11.0k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::IgmpV3QueryLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
392
1.97k
    {
393
1.97k
      if (T::isDataValid(data, dataLen))
394
1.97k
      {
395
1.97k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
1.97k
      }
397
0
      return nullptr;
398
1.97k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::IgmpV3ReportLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
392
3.90k
    {
393
3.90k
      if (T::isDataValid(data, dataLen))
394
3.90k
      {
395
3.90k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
3.90k
      }
397
0
      return nullptr;
398
3.90k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::AuthenticationHeaderLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
392
7.63k
    {
393
7.63k
      if (T::isDataValid(data, dataLen))
394
6.63k
      {
395
6.63k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
6.63k
      }
397
994
      return nullptr;
398
7.63k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::ESPLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
392
6.60k
    {
393
6.60k
      if (T::isDataValid(data, dataLen))
394
6.30k
      {
395
6.30k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
6.30k
      }
397
301
      return nullptr;
398
6.60k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::VrrpV2Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
392
9.60k
    {
393
9.60k
      if (T::isDataValid(data, dataLen))
394
9.60k
      {
395
9.60k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
9.60k
      }
397
0
      return nullptr;
398
9.60k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::VrrpV3Layer, pcpp::IPAddress::AddressType>(unsigned char*, unsigned long, pcpp::Packet*, pcpp::IPAddress::AddressType&&)
Line
Count
Source
392
5.17k
    {
393
5.17k
      if (T::isDataValid(data, dataLen))
394
5.17k
      {
395
5.17k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
5.17k
      }
397
0
      return nullptr;
398
5.17k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::PPPoESessionLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
392
58.2k
    {
393
58.2k
      if (T::isDataValid(data, dataLen))
394
58.0k
      {
395
58.0k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
58.0k
      }
397
202
      return nullptr;
398
58.2k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::PPPoEDiscoveryLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
392
1.28k
    {
393
1.28k
      if (T::isDataValid(data, dataLen))
394
1.21k
      {
395
1.21k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
1.21k
      }
397
69
      return nullptr;
398
1.28k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::CotpLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
392
16.0k
    {
393
16.0k
      if (T::isDataValid(data, dataLen))
394
9.59k
      {
395
9.59k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
9.59k
      }
397
6.45k
      return nullptr;
398
16.0k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::LLCLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
392
21.6k
    {
393
21.6k
      if (T::isDataValid(data, dataLen))
394
20.1k
      {
395
20.1k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
20.1k
      }
397
1.48k
      return nullptr;
398
21.6k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::S7CommLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
392
7.64k
    {
393
7.64k
      if (T::isDataValid(data, dataLen))
394
6.28k
      {
395
6.28k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
6.28k
      }
397
1.36k
      return nullptr;
398
7.64k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::ArpLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
392
22.8k
    {
393
22.8k
      if (T::isDataValid(data, dataLen))
394
22.7k
      {
395
22.7k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
22.7k
      }
397
108
      return nullptr;
398
22.8k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::VlanLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
392
196k
    {
393
196k
      if (T::isDataValid(data, dataLen))
394
195k
      {
395
195k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
195k
      }
397
141
      return nullptr;
398
196k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::MplsLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
392
44.3k
    {
393
44.3k
      if (T::isDataValid(data, dataLen))
394
44.2k
      {
395
44.2k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
44.2k
      }
397
3
      return nullptr;
398
44.3k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::WakeOnLanLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
392
672
    {
393
672
      if (T::isDataValid(data, dataLen))
394
21
      {
395
21
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
21
      }
397
651
      return nullptr;
398
672
    }
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
3.10M
    {
419
3.10M
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
420
3.10M
                                                             std::forward<Args>(extraArgs)...);
421
3.10M
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::IPv4Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
418
1.88M
    {
419
1.88M
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
420
1.88M
                                                             std::forward<Args>(extraArgs)...);
421
1.88M
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::IPv6Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
418
398k
    {
419
398k
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
420
398k
                                                             std::forward<Args>(extraArgs)...);
421
398k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::PPP_PPTPLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
418
80.4k
    {
419
80.4k
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
420
80.4k
                                                             std::forward<Args>(extraArgs)...);
421
80.4k
    }
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
856
    {
419
856
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
420
856
                                                             std::forward<Args>(extraArgs)...);
421
856
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::UdpLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
418
48.5k
    {
419
48.5k
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
420
48.5k
                                                             std::forward<Args>(extraArgs)...);
421
48.5k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::TcpLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
418
303k
    {
419
303k
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
420
303k
                                                             std::forward<Args>(extraArgs)...);
421
303k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::GREv0Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
418
8.91k
    {
419
8.91k
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
420
8.91k
                                                             std::forward<Args>(extraArgs)...);
421
8.91k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::GREv1Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
418
6.89k
    {
419
6.89k
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
420
6.89k
                                                             std::forward<Args>(extraArgs)...);
421
6.89k
    }
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
4.60k
    {
419
4.60k
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
420
4.60k
                                                             std::forward<Args>(extraArgs)...);
421
4.60k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::PPPoESessionLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
418
58.2k
    {
419
58.2k
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
420
58.2k
                                                             std::forward<Args>(extraArgs)...);
421
58.2k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::PPPoEDiscoveryLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
418
1.28k
    {
419
1.28k
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
420
1.28k
                                                             std::forward<Args>(extraArgs)...);
421
1.28k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::CotpLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
418
16.0k
    {
419
16.0k
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
420
16.0k
                                                             std::forward<Args>(extraArgs)...);
421
16.0k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::LLCLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
418
21.6k
    {
419
21.6k
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
420
21.6k
                                                             std::forward<Args>(extraArgs)...);
421
21.6k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::S7CommLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
418
7.64k
    {
419
7.64k
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
420
7.64k
                                                             std::forward<Args>(extraArgs)...);
421
7.64k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::ArpLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
418
22.8k
    {
419
22.8k
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
420
22.8k
                                                             std::forward<Args>(extraArgs)...);
421
22.8k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::VlanLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
418
196k
    {
419
196k
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
420
196k
                                                             std::forward<Args>(extraArgs)...);
421
196k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::MplsLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
418
44.3k
    {
419
44.3k
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
420
44.3k
                                                             std::forward<Args>(extraArgs)...);
421
44.3k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::WakeOnLanLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
418
672
    {
419
672
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
420
672
                                                             std::forward<Args>(extraArgs)...);
421
672
    }
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
4.95M
    {
441
4.95M
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
4.89M
      {
443
4.89M
        return m_NextLayer;
444
4.89M
      }
445
446
64.2k
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
4.95M
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::IPv4Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
440
1.88M
    {
441
1.88M
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
1.86M
      {
443
1.86M
        return m_NextLayer;
444
1.86M
      }
445
446
21.1k
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
1.88M
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::IPv6Layer, 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
399k
      {
443
399k
        return m_NextLayer;
444
399k
      }
445
446
5.21k
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
404k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::PPP_PPTPLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
440
80.4k
    {
441
80.4k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
79.7k
      {
443
79.7k
        return m_NextLayer;
444
79.7k
      }
445
446
717
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
80.4k
    }
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
856
    {
441
856
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
576
      {
443
576
        return m_NextLayer;
444
576
      }
445
446
280
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
856
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::UdpLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
440
715k
    {
441
715k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
712k
      {
443
712k
        return m_NextLayer;
444
712k
      }
445
446
3.18k
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
715k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::TcpLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
440
1.27M
    {
441
1.27M
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
1.25M
      {
443
1.25M
        return m_NextLayer;
444
1.25M
      }
445
446
18.9k
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
1.27M
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::IcmpLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
440
67.9k
    {
441
67.9k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
65.1k
      {
443
65.1k
        return m_NextLayer;
444
65.1k
      }
445
446
2.78k
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
67.9k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::GREv0Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
440
18.2k
    {
441
18.2k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
18.2k
      {
443
18.2k
        return m_NextLayer;
444
18.2k
      }
445
446
0
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
18.2k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::GREv1Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
440
90.2k
    {
441
90.2k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
89.9k
      {
443
89.9k
        return m_NextLayer;
444
89.9k
      }
445
446
274
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
90.2k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::IgmpV1Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
440
6.25k
    {
441
6.25k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
6.25k
      {
443
6.25k
        return m_NextLayer;
444
6.25k
      }
445
446
0
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
6.25k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::IgmpV2Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
440
11.0k
    {
441
11.0k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
11.0k
      {
443
11.0k
        return m_NextLayer;
444
11.0k
      }
445
446
0
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
11.0k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::IgmpV3QueryLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
440
1.97k
    {
441
1.97k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
1.97k
      {
443
1.97k
        return m_NextLayer;
444
1.97k
      }
445
446
0
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
1.97k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::IgmpV3ReportLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
440
3.90k
    {
441
3.90k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
3.90k
      {
443
3.90k
        return m_NextLayer;
444
3.90k
      }
445
446
0
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
3.90k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::AuthenticationHeaderLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
440
7.63k
    {
441
7.63k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
6.63k
      {
443
6.63k
        return m_NextLayer;
444
6.63k
      }
445
446
994
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
7.63k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::ESPLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
440
6.60k
    {
441
6.60k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
6.30k
      {
443
6.30k
        return m_NextLayer;
444
6.30k
      }
445
446
301
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
6.60k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::VrrpV2Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
440
9.60k
    {
441
9.60k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
9.60k
      {
443
9.60k
        return m_NextLayer;
444
9.60k
      }
445
446
0
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
9.60k
    }
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
5.17k
    {
441
5.17k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
5.17k
      {
443
5.17k
        return m_NextLayer;
444
5.17k
      }
445
446
0
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
5.17k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::PPPoESessionLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
440
58.2k
    {
441
58.2k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
58.0k
      {
443
58.0k
        return m_NextLayer;
444
58.0k
      }
445
446
202
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
58.2k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::PPPoEDiscoveryLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
440
1.28k
    {
441
1.28k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
1.21k
      {
443
1.21k
        return m_NextLayer;
444
1.21k
      }
445
446
69
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
1.28k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::CotpLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
440
16.0k
    {
441
16.0k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
9.59k
      {
443
9.59k
        return m_NextLayer;
444
9.59k
      }
445
446
6.45k
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
16.0k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::LLCLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
440
21.6k
    {
441
21.6k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
20.1k
      {
443
20.1k
        return m_NextLayer;
444
20.1k
      }
445
446
1.48k
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
21.6k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::S7CommLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
440
7.64k
    {
441
7.64k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
6.28k
      {
443
6.28k
        return m_NextLayer;
444
6.28k
      }
445
446
1.36k
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
7.64k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::ArpLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
440
22.8k
    {
441
22.8k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
22.7k
      {
443
22.7k
        return m_NextLayer;
444
22.7k
      }
445
446
108
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
22.8k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::VlanLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
440
196k
    {
441
196k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
195k
      {
443
195k
        return m_NextLayer;
444
195k
      }
445
446
141
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
196k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::MplsLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
440
44.3k
    {
441
44.3k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
44.2k
      {
443
44.2k
        return m_NextLayer;
444
44.2k
      }
445
446
3
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
44.3k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::WakeOnLanLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
440
672
    {
441
672
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
21
      {
443
21
        return m_NextLayer;
444
21
      }
445
446
651
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
672
    }
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
442k
    {
474
      // Note that the fallback is first to allow template argument deduction of the factory type.
475
442k
      return tryConstructNextLayerFromFactoryWithFallback<TFallback, TFactory>(
476
442k
          factoryFn, data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
477
442k
    }
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
84.9k
    {
474
      // Note that the fallback is first to allow template argument deduction of the factory type.
475
84.9k
      return tryConstructNextLayerFromFactoryWithFallback<TFallback, TFactory>(
476
84.9k
          factoryFn, data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
477
84.9k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerFromFactoryWithFallback<pcpp::PayloadLayer, pcpp::DoIpLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*)>(pcpp::DoIpLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*), unsigned char*, unsigned long)
Line
Count
Source
473
64.3k
    {
474
      // Note that the fallback is first to allow template argument deduction of the factory type.
475
64.3k
      return tryConstructNextLayerFromFactoryWithFallback<TFallback, TFactory>(
476
64.3k
          factoryFn, data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
477
64.3k
    }
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
47.1k
    {
474
      // Note that the fallback is first to allow template argument deduction of the factory type.
475
47.1k
      return tryConstructNextLayerFromFactoryWithFallback<TFallback, TFactory>(
476
47.1k
          factoryFn, data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
477
47.1k
    }
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
104k
    {
474
      // Note that the fallback is first to allow template argument deduction of the factory type.
475
104k
      return tryConstructNextLayerFromFactoryWithFallback<TFallback, TFactory>(
476
104k
          factoryFn, data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
477
104k
    }
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
4.28k
    {
474
      // Note that the fallback is first to allow template argument deduction of the factory type.
475
4.28k
      return tryConstructNextLayerFromFactoryWithFallback<TFallback, TFactory>(
476
4.28k
          factoryFn, data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
477
4.28k
    }
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
137k
    {
474
      // Note that the fallback is first to allow template argument deduction of the factory type.
475
137k
      return tryConstructNextLayerFromFactoryWithFallback<TFallback, TFactory>(
476
137k
          factoryFn, data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
477
137k
    }
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
442k
    {
503
442k
      auto nextLayer = constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, packet,
504
442k
                                                               std::forward<Args>(extraArgs)...);
505
442k
      if (nextLayer != nullptr)
506
271k
      {
507
271k
        return nextLayer;
508
271k
      }
509
510
      // factory failed, construct fallback layer
511
170k
      return constructNextLayer<TFallback>(data, dataLen, packet);
512
442k
    }
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
84.9k
    {
503
84.9k
      auto nextLayer = constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, packet,
504
84.9k
                                                               std::forward<Args>(extraArgs)...);
505
84.9k
      if (nextLayer != nullptr)
506
79.9k
      {
507
79.9k
        return nextLayer;
508
79.9k
      }
509
510
      // factory failed, construct fallback layer
511
4.98k
      return constructNextLayer<TFallback>(data, dataLen, packet);
512
84.9k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerFromFactoryWithFallback<pcpp::PayloadLayer, pcpp::DoIpLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*)>(pcpp::DoIpLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*), unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
502
64.3k
    {
503
64.3k
      auto nextLayer = constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, packet,
504
64.3k
                                                               std::forward<Args>(extraArgs)...);
505
64.3k
      if (nextLayer != nullptr)
506
63.9k
      {
507
63.9k
        return nextLayer;
508
63.9k
      }
509
510
      // factory failed, construct fallback layer
511
409
      return constructNextLayer<TFallback>(data, dataLen, packet);
512
64.3k
    }
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
47.1k
    {
503
47.1k
      auto nextLayer = constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, packet,
504
47.1k
                                                               std::forward<Args>(extraArgs)...);
505
47.1k
      if (nextLayer != nullptr)
506
30.5k
      {
507
30.5k
        return nextLayer;
508
30.5k
      }
509
510
      // factory failed, construct fallback layer
511
16.6k
      return constructNextLayer<TFallback>(data, dataLen, packet);
512
47.1k
    }
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
104k
    {
503
104k
      auto nextLayer = constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, packet,
504
104k
                                                               std::forward<Args>(extraArgs)...);
505
104k
      if (nextLayer != nullptr)
506
87.5k
      {
507
87.5k
        return nextLayer;
508
87.5k
      }
509
510
      // factory failed, construct fallback layer
511
16.9k
      return constructNextLayer<TFallback>(data, dataLen, packet);
512
104k
    }
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
4.28k
    {
503
4.28k
      auto nextLayer = constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, packet,
504
4.28k
                                                               std::forward<Args>(extraArgs)...);
505
4.28k
      if (nextLayer != nullptr)
506
4.28k
      {
507
4.28k
        return nextLayer;
508
4.28k
      }
509
510
      // factory failed, construct fallback layer
511
0
      return constructNextLayer<TFallback>(data, dataLen, packet);
512
4.28k
    }
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
137k
    {
503
137k
      auto nextLayer = constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, packet,
504
137k
                                                               std::forward<Args>(extraArgs)...);
505
137k
      if (nextLayer != nullptr)
506
5.61k
      {
507
5.61k
        return nextLayer;
508
5.61k
      }
509
510
      // factory failed, construct fallback layer
511
131k
      return constructNextLayer<TFallback>(data, dataLen, packet);
512
137k
    }
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
2.98M
    {
524
2.98M
      return data != nullptr && dataLen >= sizeof(T);
525
2.98M
    }
bool pcpp::Layer::canReinterpretAs<pcpp::arphdr>(unsigned char const*, unsigned long)
Line
Count
Source
523
22.8k
    {
524
22.8k
      return data != nullptr && dataLen >= sizeof(T);
525
22.8k
    }
bool pcpp::Layer::canReinterpretAs<pcpp::iphdr>(unsigned char const*, unsigned long)
Line
Count
Source
523
1.90M
    {
524
1.90M
      return data != nullptr && dataLen >= sizeof(T);
525
1.90M
    }
bool pcpp::Layer::canReinterpretAs<pcpp::vrrp_header>(unsigned char const*, unsigned long)
Line
Count
Source
523
14.7k
    {
524
14.7k
      return data != nullptr && dataLen >= sizeof(T);
525
14.7k
    }
bool pcpp::Layer::canReinterpretAs<pcpp::ip6_hdr>(unsigned char const*, unsigned long)
Line
Count
Source
523
409k
    {
524
409k
      return data != nullptr && dataLen >= sizeof(T);
525
409k
    }
bool pcpp::Layer::canReinterpretAs<pcpp::vlan_header>(unsigned char const*, unsigned long)
Line
Count
Source
523
196k
    {
524
196k
      return data != nullptr && dataLen >= sizeof(T);
525
196k
    }
bool pcpp::Layer::canReinterpretAs<pcpp::MplsLayer::mpls_header>(unsigned char const*, unsigned long)
Line
Count
Source
523
44.3k
    {
524
44.3k
      return data != nullptr && dataLen >= sizeof(T);
525
44.3k
    }
bool pcpp::Layer::canReinterpretAs<pcpp::igmp_header>(unsigned char const*, unsigned long)
Line
Count
Source
523
17.2k
    {
524
17.2k
      return data != nullptr && dataLen >= sizeof(T);
525
17.2k
    }
bool pcpp::Layer::canReinterpretAs<pcpp::igmpv3_query_header>(unsigned char const*, unsigned long)
Line
Count
Source
523
1.97k
    {
524
1.97k
      return data != nullptr && dataLen >= sizeof(T);
525
1.97k
    }
bool pcpp::Layer::canReinterpretAs<pcpp::igmpv3_report_header>(unsigned char const*, unsigned long)
Line
Count
Source
523
3.90k
    {
524
3.90k
      return data != nullptr && dataLen >= sizeof(T);
525
3.90k
    }
bool pcpp::Layer::canReinterpretAs<pcpp::tpkthdr>(unsigned char const*, unsigned long)
Line
Count
Source
523
361k
    {
524
361k
      return data != nullptr && dataLen >= sizeof(T);
525
361k
    }
bool pcpp::Layer::canReinterpretAs<pcpp::stp_tcn_bpdu>(unsigned char const*, unsigned long)
Line
Count
Source
523
2.35k
    {
524
2.35k
      return data != nullptr && dataLen >= sizeof(T);
525
2.35k
    }
bool pcpp::Layer::canReinterpretAs<pcpp::stp_conf_bpdu>(unsigned char const*, unsigned long)
Line
Count
Source
523
2.65k
    {
524
2.65k
      return data != nullptr && dataLen >= sizeof(T);
525
2.65k
    }
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
192
    {
524
192
      return data != nullptr && dataLen >= sizeof(T);
525
192
    }
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