Coverage Report

Created: 2026-02-26 06:41

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/PcapPlusPlus/Packet++/header/Layer.h
Line
Count
Source
1
#pragma once
2
3
#include <stdint.h>
4
#include <stdio.h>
5
#include "ProtocolType.h"
6
#include <string>
7
#include <stdexcept>
8
#include <utility>
9
10
/// @file
11
12
/// @namespace pcpp
13
/// @brief The main namespace for the PcapPlusPlus lib
14
namespace pcpp
15
{
16
17
  /// @class IDataContainer
18
  /// An interface (virtual abstract class) that indicates an object that holds a pointer to a buffer data. The Layer
19
  /// class is an example of such object, hence it inherits this interface
20
  class IDataContainer
21
  {
22
  public:
23
    /// Get a pointer to the data
24
    /// @param[in] offset Get a pointer in a certain offset. Default is 0 - get a pointer to start of data
25
    /// @return A pointer to the data
26
    virtual uint8_t* getDataPtr(size_t offset = 0) const = 0;
27
28
13.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
260M
    {
126
260M
      return m_NextLayer;
127
260M
    }
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
188M
    {
138
188M
      return m_Protocol;
139
188M
    }
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
594k
    {
149
594k
      return m_Data;
150
594k
    }
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.54M
    {
155
6.54M
      return m_DataLen;
156
6.54M
    }
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
92.9k
    {
167
92.9k
      return m_DataLen - getHeaderLen();
168
92.9k
    }
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
13.2M
    {
181
13.2M
      return m_AllocationInfo.attachedPacket != nullptr;
182
13.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
286k
    {
192
286k
      return static_cast<uint8_t*>(m_Data + offset);
193
286k
    }
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
12.9M
        : m_Data(data), m_DataLen(dataLen), m_Protocol(protocol), m_NextLayer(nullptr), m_PrevLayer(prevLayer),
229
12.9M
          m_AllocationInfo{ packet, false }
230
12.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
12.4M
    {
240
12.4M
      return m_AllocationInfo.attachedPacket;
241
12.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.18k
    {
247
5.18k
      return m_AllocationInfo.attachedPacket;
248
5.18k
    }
249
250
    void setNextLayer(Layer* nextLayer)
251
10.9M
    {
252
10.9M
      m_NextLayer = nextLayer;
253
10.9M
    }
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
17.4M
    {
264
17.4M
      return m_NextLayer != nullptr;
265
17.4M
    }
266
267
    /// @brief Construct the next layer in the protocol stack. No validation is performed on the data.
268
    ///
269
    /// This overload infers the Packet from the current layer.
270
    ///
271
    /// @tparam T The type of the layer to construct
272
    /// @tparam Args The types of the arguments to pass to the layer constructor
273
    /// @param data The data to construct the layer from
274
    /// @param dataLen The length of the data
275
    /// @param extraArgs Extra arguments to be forwarded to the layer constructor
276
    /// @return The constructed layer
277
    template <typename T, typename... Args>
278
    Layer* constructNextLayer(uint8_t* data, size_t dataLen, Args&&... extraArgs)
279
3.74M
    {
280
3.74M
      return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
281
3.74M
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::VlanLayer>(unsigned char*, unsigned long)
Line
Count
Source
279
68.4k
    {
280
68.4k
      return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
281
68.4k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::MplsLayer>(unsigned char*, unsigned long)
Line
Count
Source
279
3.09M
    {
280
3.09M
      return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
281
3.09M
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
279
187k
    {
280
187k
      return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
281
187k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::VrrpV3Layer, pcpp::IPAddress::AddressType>(unsigned char*, unsigned long, pcpp::IPAddress::AddressType&&)
Line
Count
Source
279
7.14k
    {
280
7.14k
      return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
281
7.14k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::ArpLayer>(unsigned char*, unsigned long)
Line
Count
Source
279
8.97k
    {
280
8.97k
      return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
281
8.97k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::DhcpLayer>(unsigned char*, unsigned long)
Line
Count
Source
279
33.4k
    {
280
33.4k
      return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
281
33.4k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::VxlanLayer>(unsigned char*, unsigned long)
Line
Count
Source
279
11.2k
    {
280
11.2k
      return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
281
11.2k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::DnsLayer>(unsigned char*, unsigned long)
Line
Count
Source
279
150k
    {
280
150k
      return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
281
150k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::RadiusLayer>(unsigned char*, unsigned long)
Line
Count
Source
279
32.5k
    {
280
32.5k
      return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
281
32.5k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::GtpV1Layer>(unsigned char*, unsigned long)
Line
Count
Source
279
43.2k
    {
280
43.2k
      return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
281
43.2k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::GtpV2Layer>(unsigned char*, unsigned long)
Line
Count
Source
279
931
    {
280
931
      return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
281
931
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::DhcpV6Layer>(unsigned char*, unsigned long)
Line
Count
Source
279
24.7k
    {
280
24.7k
      return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
281
24.7k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::NtpLayer>(unsigned char*, unsigned long)
Line
Count
Source
279
29.2k
    {
280
29.2k
      return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
281
29.2k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::WakeOnLanLayer>(unsigned char*, unsigned long)
Line
Count
Source
279
1.41k
    {
280
1.41k
      return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
281
1.41k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::EthLayer>(unsigned char*, unsigned long)
Line
Count
Source
279
10.9k
    {
280
10.9k
      return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
281
10.9k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::SdpLayer>(unsigned char*, unsigned long)
Line
Count
Source
279
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
9.47M
    {
294
9.47M
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
9.47M
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
9.47M
      setNextLayer(newLayer);
301
9.47M
      return newLayer;
302
9.47M
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::IPv4Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
1.87M
    {
294
1.87M
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
1.87M
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
1.87M
      setNextLayer(newLayer);
301
1.87M
      return newLayer;
302
1.87M
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
745k
    {
294
745k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
745k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
745k
      setNextLayer(newLayer);
301
745k
      return newLayer;
302
745k
    }
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
266k
    {
294
266k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
266k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
266k
      setNextLayer(newLayer);
301
266k
      return newLayer;
302
266k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::MplsLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
3.13M
    {
294
3.13M
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
3.13M
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
3.13M
      setNextLayer(newLayer);
301
3.13M
      return newLayer;
302
3.13M
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::PPP_PPTPLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
82.9k
    {
294
82.9k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
82.9k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
82.9k
      setNextLayer(newLayer);
301
82.9k
      return newLayer;
302
82.9k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::EthLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
10.9k
    {
294
10.9k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
10.9k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
10.9k
      setNextLayer(newLayer);
301
10.9k
      return newLayer;
302
10.9k
    }
Unexecuted instantiation: pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::EthDot3Layer>(unsigned char*, unsigned long, pcpp::Packet*)
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::GtpV2Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
1.47k
    {
294
1.47k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
1.47k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
1.47k
      setNextLayer(newLayer);
301
1.47k
      return newLayer;
302
1.47k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::UdpLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
732k
    {
294
732k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
732k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
732k
      setNextLayer(newLayer);
301
732k
      return newLayer;
302
732k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::TcpLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
1.23M
    {
294
1.23M
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
1.23M
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
1.23M
      setNextLayer(newLayer);
301
1.23M
      return newLayer;
302
1.23M
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::IcmpLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
63.3k
    {
294
63.3k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
63.3k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
63.3k
      setNextLayer(newLayer);
301
63.3k
      return newLayer;
302
63.3k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::GREv0Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
17.2k
    {
294
17.2k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
17.2k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
17.2k
      setNextLayer(newLayer);
301
17.2k
      return newLayer;
302
17.2k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::GREv1Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
92.2k
    {
294
92.2k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
92.2k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
92.2k
      setNextLayer(newLayer);
301
92.2k
      return newLayer;
302
92.2k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::IgmpV1Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
6.23k
    {
294
6.23k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
6.23k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
6.23k
      setNextLayer(newLayer);
301
6.23k
      return newLayer;
302
6.23k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::IgmpV2Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
10.9k
    {
294
10.9k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
10.9k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
10.9k
      setNextLayer(newLayer);
301
10.9k
      return newLayer;
302
10.9k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::IgmpV3QueryLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
1.96k
    {
294
1.96k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
1.96k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
1.96k
      setNextLayer(newLayer);
301
1.96k
      return newLayer;
302
1.96k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::IgmpV3ReportLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
3.76k
    {
294
3.76k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
3.76k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
3.76k
      setNextLayer(newLayer);
301
3.76k
      return newLayer;
302
3.76k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::AuthenticationHeaderLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
6.44k
    {
294
6.44k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
6.44k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
6.44k
      setNextLayer(newLayer);
301
6.44k
      return newLayer;
302
6.44k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::ESPLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
5.65k
    {
294
5.65k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
5.65k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
5.65k
      setNextLayer(newLayer);
301
5.65k
      return newLayer;
302
5.65k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::VrrpV2Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
9.37k
    {
294
9.37k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
9.37k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
9.37k
      setNextLayer(newLayer);
301
9.37k
      return newLayer;
302
9.37k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::VrrpV3Layer, pcpp::IPAddress::AddressType>(unsigned char*, unsigned long, pcpp::Packet*, pcpp::IPAddress::AddressType&&)
Line
Count
Source
293
12.1k
    {
294
12.1k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
12.1k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
12.1k
      setNextLayer(newLayer);
301
12.1k
      return newLayer;
302
12.1k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::ArpLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
31.4k
    {
294
31.4k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
31.4k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
31.4k
      setNextLayer(newLayer);
301
31.4k
      return newLayer;
302
31.4k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::PPPoESessionLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
57.4k
    {
294
57.4k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
57.4k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
57.4k
      setNextLayer(newLayer);
301
57.4k
      return newLayer;
302
57.4k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::PPPoEDiscoveryLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
1.04k
    {
294
1.04k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
1.04k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
1.04k
      setNextLayer(newLayer);
301
1.04k
      return newLayer;
302
1.04k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::HttpRequestLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
100k
    {
294
100k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
100k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
100k
      setNextLayer(newLayer);
301
100k
      return newLayer;
302
100k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::HttpResponseLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
27.3k
    {
294
27.3k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
27.3k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
27.3k
      setNextLayer(newLayer);
301
27.3k
      return newLayer;
302
27.3k
    }
Unexecuted instantiation: pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::SipRequestLayer>(unsigned char*, unsigned long, pcpp::Packet*)
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::SipResponseLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
107
    {
294
107
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
107
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
107
      setNextLayer(newLayer);
301
107
      return newLayer;
302
107
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::DnsOverTcpLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
26.3k
    {
294
26.3k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
26.3k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
26.3k
      setNextLayer(newLayer);
301
26.3k
      return newLayer;
302
26.3k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::TelnetLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
52.4k
    {
294
52.4k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
52.4k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
52.4k
      setNextLayer(newLayer);
301
52.4k
      return newLayer;
302
52.4k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::FtpResponseLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
17.4k
    {
294
17.4k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
17.4k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
17.4k
      setNextLayer(newLayer);
301
17.4k
      return newLayer;
302
17.4k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::FtpRequestLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
4.36k
    {
294
4.36k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
4.36k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
4.36k
      setNextLayer(newLayer);
301
4.36k
      return newLayer;
302
4.36k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::FtpDataLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
4.62k
    {
294
4.62k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
4.62k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
4.62k
      setNextLayer(newLayer);
301
4.62k
      return newLayer;
302
4.62k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::TpktLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
15.6k
    {
294
15.6k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
15.6k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
15.6k
      setNextLayer(newLayer);
301
15.6k
      return newLayer;
302
15.6k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::SmtpResponseLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
6.59k
    {
294
6.59k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
6.59k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
6.59k
      setNextLayer(newLayer);
301
6.59k
      return newLayer;
302
6.59k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::SmtpRequestLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
8.32k
    {
294
8.32k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
8.32k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
8.32k
      setNextLayer(newLayer);
301
8.32k
      return newLayer;
302
8.32k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::ModbusLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
1.61k
    {
294
1.61k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
1.61k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
1.61k
      setNextLayer(newLayer);
301
1.61k
      return newLayer;
302
1.61k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::CotpLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
9.58k
    {
294
9.58k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
9.58k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
9.58k
      setNextLayer(newLayer);
301
9.58k
      return newLayer;
302
9.58k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::DhcpLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
33.4k
    {
294
33.4k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
33.4k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
33.4k
      setNextLayer(newLayer);
301
33.4k
      return newLayer;
302
33.4k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::VxlanLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
11.2k
    {
294
11.2k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
11.2k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
11.2k
      setNextLayer(newLayer);
301
11.2k
      return newLayer;
302
11.2k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::DnsLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
150k
    {
294
150k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
150k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
150k
      setNextLayer(newLayer);
301
150k
      return newLayer;
302
150k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::RadiusLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
32.5k
    {
294
32.5k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
32.5k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
32.5k
      setNextLayer(newLayer);
301
32.5k
      return newLayer;
302
32.5k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::GtpV1Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
43.2k
    {
294
43.2k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
43.2k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
43.2k
      setNextLayer(newLayer);
301
43.2k
      return newLayer;
302
43.2k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::DhcpV6Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
24.7k
    {
294
24.7k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
24.7k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
24.7k
      setNextLayer(newLayer);
301
24.7k
      return newLayer;
302
24.7k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::NtpLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
29.2k
    {
294
29.2k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
29.2k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
29.2k
      setNextLayer(newLayer);
301
29.2k
      return newLayer;
302
29.2k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::WakeOnLanLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
1.43k
    {
294
1.43k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
1.43k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
1.43k
      setNextLayer(newLayer);
301
1.43k
      return newLayer;
302
1.43k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::LLCLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
22.2k
    {
294
22.2k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
22.2k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
22.2k
      setNextLayer(newLayer);
301
22.2k
      return newLayer;
302
22.2k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::S7CommLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
6.42k
    {
294
6.42k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
6.42k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
6.42k
      setNextLayer(newLayer);
301
6.42k
      return newLayer;
302
6.42k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::SdpLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
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
922k
    {
324
922k
      return constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, getAttachedPacket(),
325
922k
                                                     std::forward<Args>(extraArgs)...);
326
922k
    }
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
167k
    {
324
167k
      return constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, getAttachedPacket(),
325
167k
                                                     std::forward<Args>(extraArgs)...);
326
167k
    }
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
137k
    {
324
137k
      return constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, getAttachedPacket(),
325
137k
                                                     std::forward<Args>(extraArgs)...);
326
137k
    }
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
556k
    {
324
556k
      return constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, getAttachedPacket(),
325
556k
                                                     std::forward<Args>(extraArgs)...);
326
556k
    }
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
26.3k
    {
324
26.3k
      return constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, getAttachedPacket(),
325
26.3k
                                                     std::forward<Args>(extraArgs)...);
326
26.3k
    }
pcpp::Layer* pcpp::Layer::constructNextLayerFromFactory<pcpp::LdapLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*)>(pcpp::LdapLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*), unsigned char*, unsigned long)
Line
Count
Source
323
27.1k
    {
324
27.1k
      return constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, getAttachedPacket(),
325
27.1k
                                                     std::forward<Args>(extraArgs)...);
326
27.1k
    }
pcpp::Layer* pcpp::Layer::constructNextLayerFromFactory<pcpp::StpLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*)>(pcpp::StpLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*), unsigned char*, unsigned long)
Line
Count
Source
323
7.87k
    {
324
7.87k
      return constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, getAttachedPacket(),
325
7.87k
                                                     std::forward<Args>(extraArgs)...);
326
7.87k
    }
327
328
    /// @brief Construct the next layer in the protocol stack using a factory functor.
329
    ///
330
    /// No validation is performed on the data, outside of what the factory functor may perform.
331
    /// If the factory returns a nullptr, no next layer is set.
332
    ///
333
    /// The factory functor is expected to have the following signature:
334
    /// Layer* factoryFn(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet, ...);
335
    ///
336
    /// @tparam TFactory The factory functor type.
337
    /// @tparam ...Args Parameter pack for extra arguments to pass to the factory functor.
338
    /// @param[in] factoryFn The factory functor to create the layer.
339
    /// @param[in] data The data to construct the layer from
340
    /// @param[in] dataLen The length of the data
341
    /// @param[in] packet The packet the layer belongs to
342
    /// @param[in] extraArgs Extra arguments to be forwarded to the factory.
343
    /// @return The return value of the factory functor.
344
    template <typename TFactory, typename... Args>
345
    Layer* constructNextLayerFromFactory(TFactory factoryFn, uint8_t* data, size_t dataLen, Packet* packet,
346
                                         Args&&... extraArgs)
347
1.36M
    {
348
1.36M
      if (hasNextLayer())
349
0
      {
350
0
        throw std::runtime_error("Next layer already exists");
351
0
      }
352
353
      // cppcheck-suppress redundantInitialization
354
1.36M
      Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
355
1.36M
      setNextLayer(newLayer);
356
1.36M
      return newLayer;
357
1.36M
    }
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
251k
    {
348
251k
      if (hasNextLayer())
349
0
      {
350
0
        throw std::runtime_error("Next layer already exists");
351
0
      }
352
353
      // cppcheck-suppress redundantInitialization
354
251k
      Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
355
251k
      setNextLayer(newLayer);
356
251k
      return newLayer;
357
251k
    }
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
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::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
556k
    {
348
556k
      if (hasNextLayer())
349
0
      {
350
0
        throw std::runtime_error("Next layer already exists");
351
0
      }
352
353
      // cppcheck-suppress redundantInitialization
354
556k
      Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
355
556k
      setNextLayer(newLayer);
356
556k
      return newLayer;
357
556k
    }
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
26.3k
    {
348
26.3k
      if (hasNextLayer())
349
0
      {
350
0
        throw std::runtime_error("Next layer already exists");
351
0
      }
352
353
      // cppcheck-suppress redundantInitialization
354
26.3k
      Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
355
26.3k
      setNextLayer(newLayer);
356
26.3k
      return newLayer;
357
26.3k
    }
pcpp::Layer* pcpp::Layer::constructNextLayerFromFactory<pcpp::DoIpLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*)>(pcpp::DoIpLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*), unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
347
63.4k
    {
348
63.4k
      if (hasNextLayer())
349
0
      {
350
0
        throw std::runtime_error("Next layer already exists");
351
0
      }
352
353
      // cppcheck-suppress redundantInitialization
354
63.4k
      Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
355
63.4k
      setNextLayer(newLayer);
356
63.4k
      return newLayer;
357
63.4k
    }
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
72.0k
    {
348
72.0k
      if (hasNextLayer())
349
0
      {
350
0
        throw std::runtime_error("Next layer already exists");
351
0
      }
352
353
      // cppcheck-suppress redundantInitialization
354
72.0k
      Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
355
72.0k
      setNextLayer(newLayer);
356
72.0k
      return newLayer;
357
72.0k
    }
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.33k
    {
348
4.33k
      if (hasNextLayer())
349
0
      {
350
0
        throw std::runtime_error("Next layer already exists");
351
0
      }
352
353
      // cppcheck-suppress redundantInitialization
354
4.33k
      Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
355
4.33k
      setNextLayer(newLayer);
356
4.33k
      return newLayer;
357
4.33k
    }
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
145k
    {
348
145k
      if (hasNextLayer())
349
0
      {
350
0
        throw std::runtime_error("Next layer already exists");
351
0
      }
352
353
      // cppcheck-suppress redundantInitialization
354
145k
      Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
355
145k
      setNextLayer(newLayer);
356
145k
      return newLayer;
357
145k
    }
pcpp::Layer* pcpp::Layer::constructNextLayerFromFactory<pcpp::StpLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*)>(pcpp::StpLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*), unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
347
7.87k
    {
348
7.87k
      if (hasNextLayer())
349
0
      {
350
0
        throw std::runtime_error("Next layer already exists");
351
0
      }
352
353
      // cppcheck-suppress redundantInitialization
354
7.87k
      Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
355
7.87k
      setNextLayer(newLayer);
356
7.87k
      return newLayer;
357
7.87k
    }
358
359
    /// Try to construct the next layer in the protocol stack.
360
    ///
361
    /// This overload infers the Packet from the current layer.
362
    ///
363
    /// The method checks if the data is valid for the layer type T before constructing it by calling
364
    /// T::isDataValid(data, dataLen). If the data is invalid, no layer is constructed and a nullptr is returned.
365
    ///
366
    /// @tparam T The type of the layer to construct
367
    /// @tparam Args The types of the extra arguments to pass to the layer constructor
368
    /// @param[in] data The data to construct the layer from
369
    /// @param[in] dataLen The length of the data
370
    /// @param[in] extraArgs Extra arguments to be forwarded to the layer constructor
371
    /// @return The constructed layer or nullptr if the data is invalid
372
    template <typename T, typename... Args>
373
    Layer* tryConstructNextLayer(uint8_t* data, size_t dataLen, Args&&... extraArgs)
374
0
    {
375
0
      return tryConstructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
376
0
    }
377
378
    /// Try to construct the next layer in the protocol stack.
379
    ///
380
    /// The method checks if the data is valid for the layer type T before constructing it by calling
381
    /// T::isDataValid(data, dataLen). If the data is invalid, no layer is constructed and a nullptr is returned.
382
    ///
383
    /// @tparam T The type of the layer to construct
384
    /// @tparam Args The types of the extra arguments to pass to the layer constructor
385
    /// @param[in] data The data to construct the layer from
386
    /// @param[in] dataLen The length of the data
387
    /// @param[in] packet The packet the layer belongs to
388
    /// @param[in] extraArgs Extra arguments to be forwarded to the layer constructor
389
    /// @return The constructed layer or nullptr if the data is invalid
390
    template <typename T, typename... Args>
391
    Layer* tryConstructNextLayer(uint8_t* data, size_t dataLen, Packet* packet, Args&&... extraArgs)
392
4.96M
    {
393
4.96M
      if (T::isDataValid(data, dataLen))
394
4.90M
      {
395
4.90M
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
4.90M
      }
397
59.1k
      return nullptr;
398
4.96M
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::IPv4Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
392
1.89M
    {
393
1.89M
      if (T::isDataValid(data, dataLen))
394
1.87M
      {
395
1.87M
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
1.87M
      }
397
19.1k
      return nullptr;
398
1.89M
    }
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.06k
      return nullptr;
398
404k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::PPP_PPTPLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
392
83.8k
    {
393
83.8k
      if (T::isDataValid(data, dataLen))
394
82.9k
      {
395
82.9k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
82.9k
      }
397
840
      return nullptr;
398
83.8k
    }
Unexecuted instantiation: pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::EthLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Unexecuted instantiation: pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::EthDot3Layer>(unsigned char*, unsigned long, pcpp::Packet*)
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::GtpV2Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
392
801
    {
393
801
      if (T::isDataValid(data, dataLen))
394
518
      {
395
518
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
518
      }
397
283
      return nullptr;
398
801
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::UdpLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
392
735k
    {
393
735k
      if (T::isDataValid(data, dataLen))
394
732k
      {
395
732k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
732k
      }
397
3.05k
      return nullptr;
398
735k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::TcpLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
392
1.25M
    {
393
1.25M
      if (T::isDataValid(data, dataLen))
394
1.23M
      {
395
1.23M
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
1.23M
      }
397
18.2k
      return nullptr;
398
1.25M
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::IcmpLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
392
65.9k
    {
393
65.9k
      if (T::isDataValid(data, dataLen))
394
63.3k
      {
395
63.3k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
63.3k
      }
397
2.60k
      return nullptr;
398
65.9k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::GREv0Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
392
17.2k
    {
393
17.2k
      if (T::isDataValid(data, dataLen))
394
17.2k
      {
395
17.2k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
17.2k
      }
397
0
      return nullptr;
398
17.2k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::GREv1Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
392
92.5k
    {
393
92.5k
      if (T::isDataValid(data, dataLen))
394
92.2k
      {
395
92.2k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
92.2k
      }
397
272
      return nullptr;
398
92.5k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::IgmpV1Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
392
6.23k
    {
393
6.23k
      if (T::isDataValid(data, dataLen))
394
6.23k
      {
395
6.23k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
6.23k
      }
397
0
      return nullptr;
398
6.23k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::IgmpV2Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
392
10.9k
    {
393
10.9k
      if (T::isDataValid(data, dataLen))
394
10.9k
      {
395
10.9k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
10.9k
      }
397
0
      return nullptr;
398
10.9k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::IgmpV3QueryLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
392
1.96k
    {
393
1.96k
      if (T::isDataValid(data, dataLen))
394
1.96k
      {
395
1.96k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
1.96k
      }
397
0
      return nullptr;
398
1.96k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::IgmpV3ReportLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
392
3.76k
    {
393
3.76k
      if (T::isDataValid(data, dataLen))
394
3.76k
      {
395
3.76k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
3.76k
      }
397
0
      return nullptr;
398
3.76k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::AuthenticationHeaderLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
392
7.05k
    {
393
7.05k
      if (T::isDataValid(data, dataLen))
394
6.44k
      {
395
6.44k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
6.44k
      }
397
613
      return nullptr;
398
7.05k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::ESPLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
392
5.93k
    {
393
5.93k
      if (T::isDataValid(data, dataLen))
394
5.65k
      {
395
5.65k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
5.65k
      }
397
275
      return nullptr;
398
5.93k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::VrrpV2Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
392
9.37k
    {
393
9.37k
      if (T::isDataValid(data, dataLen))
394
9.37k
      {
395
9.37k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
9.37k
      }
397
0
      return nullptr;
398
9.37k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::VrrpV3Layer, pcpp::IPAddress::AddressType>(unsigned char*, unsigned long, pcpp::Packet*, pcpp::IPAddress::AddressType&&)
Line
Count
Source
392
5.01k
    {
393
5.01k
      if (T::isDataValid(data, dataLen))
394
5.01k
      {
395
5.01k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
5.01k
      }
397
0
      return nullptr;
398
5.01k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::PPPoESessionLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
392
57.6k
    {
393
57.6k
      if (T::isDataValid(data, dataLen))
394
57.4k
      {
395
57.4k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
57.4k
      }
397
202
      return nullptr;
398
57.6k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::PPPoEDiscoveryLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
392
1.11k
    {
393
1.11k
      if (T::isDataValid(data, dataLen))
394
1.04k
      {
395
1.04k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
1.04k
      }
397
69
      return nullptr;
398
1.11k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::CotpLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
392
15.6k
    {
393
15.6k
      if (T::isDataValid(data, dataLen))
394
9.58k
      {
395
9.58k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
9.58k
      }
397
6.07k
      return nullptr;
398
15.6k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::LLCLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
392
22.7k
    {
393
22.7k
      if (T::isDataValid(data, dataLen))
394
22.2k
      {
395
22.2k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
22.2k
      }
397
494
      return nullptr;
398
22.7k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::S7CommLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
392
7.50k
    {
393
7.50k
      if (T::isDataValid(data, dataLen))
394
6.42k
      {
395
6.42k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
6.42k
      }
397
1.08k
      return nullptr;
398
7.50k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::ArpLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
392
22.6k
    {
393
22.6k
      if (T::isDataValid(data, dataLen))
394
22.5k
      {
395
22.5k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
22.5k
      }
397
108
      return nullptr;
398
22.6k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::VlanLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
392
198k
    {
393
198k
      if (T::isDataValid(data, dataLen))
394
198k
      {
395
198k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
198k
      }
397
144
      return nullptr;
398
198k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::MplsLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
392
36.9k
    {
393
36.9k
      if (T::isDataValid(data, dataLen))
394
36.9k
      {
395
36.9k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
36.9k
      }
397
3
      return nullptr;
398
36.9k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::WakeOnLanLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
392
678
    {
393
678
      if (T::isDataValid(data, dataLen))
394
18
      {
395
18
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
18
      }
397
660
      return nullptr;
398
678
    }
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.11M
    {
419
3.11M
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
420
3.11M
                                                             std::forward<Args>(extraArgs)...);
421
3.11M
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::IPv4Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
418
1.89M
    {
419
1.89M
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
420
1.89M
                                                             std::forward<Args>(extraArgs)...);
421
1.89M
    }
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
83.8k
    {
419
83.8k
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
420
83.8k
                                                             std::forward<Args>(extraArgs)...);
421
83.8k
    }
Unexecuted instantiation: pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::EthDot3Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::GtpV2Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
418
801
    {
419
801
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
420
801
                                                             std::forward<Args>(extraArgs)...);
421
801
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::UdpLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
418
48.7k
    {
419
48.7k
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
420
48.7k
                                                             std::forward<Args>(extraArgs)...);
421
48.7k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::TcpLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
418
306k
    {
419
306k
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
420
306k
                                                             std::forward<Args>(extraArgs)...);
421
306k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::GREv0Layer, 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::GREv1Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
418
6.16k
    {
419
6.16k
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
420
6.16k
                                                             std::forward<Args>(extraArgs)...);
421
6.16k
    }
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.43k
    {
419
4.43k
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
420
4.43k
                                                             std::forward<Args>(extraArgs)...);
421
4.43k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::PPPoESessionLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
418
57.6k
    {
419
57.6k
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
420
57.6k
                                                             std::forward<Args>(extraArgs)...);
421
57.6k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::PPPoEDiscoveryLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
418
1.11k
    {
419
1.11k
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
420
1.11k
                                                             std::forward<Args>(extraArgs)...);
421
1.11k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::CotpLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
418
15.6k
    {
419
15.6k
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
420
15.6k
                                                             std::forward<Args>(extraArgs)...);
421
15.6k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::LLCLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
418
22.7k
    {
419
22.7k
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
420
22.7k
                                                             std::forward<Args>(extraArgs)...);
421
22.7k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::S7CommLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
418
7.50k
    {
419
7.50k
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
420
7.50k
                                                             std::forward<Args>(extraArgs)...);
421
7.50k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::ArpLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
418
22.6k
    {
419
22.6k
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
420
22.6k
                                                             std::forward<Args>(extraArgs)...);
421
22.6k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::VlanLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
418
198k
    {
419
198k
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
420
198k
                                                             std::forward<Args>(extraArgs)...);
421
198k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::MplsLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
418
36.9k
    {
419
36.9k
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
420
36.9k
                                                             std::forward<Args>(extraArgs)...);
421
36.9k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::WakeOnLanLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
418
678
    {
419
678
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
420
678
                                                             std::forward<Args>(extraArgs)...);
421
678
    }
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.96M
    {
441
4.96M
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
4.90M
      {
443
4.90M
        return m_NextLayer;
444
4.90M
      }
445
446
59.1k
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
4.96M
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::IPv4Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
440
1.89M
    {
441
1.89M
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
1.87M
      {
443
1.87M
        return m_NextLayer;
444
1.87M
      }
445
446
19.1k
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
1.89M
    }
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.06k
      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
83.8k
    {
441
83.8k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
82.9k
      {
443
82.9k
        return m_NextLayer;
444
82.9k
      }
445
446
840
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
83.8k
    }
Unexecuted instantiation: pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::EthDot3Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::GtpV2Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
440
801
    {
441
801
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
518
      {
443
518
        return m_NextLayer;
444
518
      }
445
446
283
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
801
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::UdpLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
440
735k
    {
441
735k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
732k
      {
443
732k
        return m_NextLayer;
444
732k
      }
445
446
3.05k
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
735k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::TcpLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
440
1.25M
    {
441
1.25M
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
1.23M
      {
443
1.23M
        return m_NextLayer;
444
1.23M
      }
445
446
18.2k
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
1.25M
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::IcmpLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
440
65.9k
    {
441
65.9k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
63.3k
      {
443
63.3k
        return m_NextLayer;
444
63.3k
      }
445
446
2.60k
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
65.9k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::GREv0Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
440
17.2k
    {
441
17.2k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
17.2k
      {
443
17.2k
        return m_NextLayer;
444
17.2k
      }
445
446
0
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
17.2k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::GREv1Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
440
92.5k
    {
441
92.5k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
92.2k
      {
443
92.2k
        return m_NextLayer;
444
92.2k
      }
445
446
272
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
92.5k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::IgmpV1Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
440
6.23k
    {
441
6.23k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
6.23k
      {
443
6.23k
        return m_NextLayer;
444
6.23k
      }
445
446
0
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
6.23k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::IgmpV2Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
440
10.9k
    {
441
10.9k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
10.9k
      {
443
10.9k
        return m_NextLayer;
444
10.9k
      }
445
446
0
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
10.9k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::IgmpV3QueryLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
440
1.96k
    {
441
1.96k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
1.96k
      {
443
1.96k
        return m_NextLayer;
444
1.96k
      }
445
446
0
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
1.96k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::IgmpV3ReportLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
440
3.76k
    {
441
3.76k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
3.76k
      {
443
3.76k
        return m_NextLayer;
444
3.76k
      }
445
446
0
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
3.76k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::AuthenticationHeaderLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
440
7.05k
    {
441
7.05k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
6.44k
      {
443
6.44k
        return m_NextLayer;
444
6.44k
      }
445
446
613
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
7.05k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::ESPLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
440
5.93k
    {
441
5.93k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
5.65k
      {
443
5.65k
        return m_NextLayer;
444
5.65k
      }
445
446
275
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
5.93k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::VrrpV2Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
440
9.37k
    {
441
9.37k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
9.37k
      {
443
9.37k
        return m_NextLayer;
444
9.37k
      }
445
446
0
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
9.37k
    }
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.01k
    {
441
5.01k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
5.01k
      {
443
5.01k
        return m_NextLayer;
444
5.01k
      }
445
446
0
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
5.01k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::PPPoESessionLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
440
57.6k
    {
441
57.6k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
57.4k
      {
443
57.4k
        return m_NextLayer;
444
57.4k
      }
445
446
202
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
57.6k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::PPPoEDiscoveryLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
440
1.11k
    {
441
1.11k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
1.04k
      {
443
1.04k
        return m_NextLayer;
444
1.04k
      }
445
446
69
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
1.11k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::CotpLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
440
15.6k
    {
441
15.6k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
9.58k
      {
443
9.58k
        return m_NextLayer;
444
9.58k
      }
445
446
6.07k
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
15.6k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::LLCLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
440
22.7k
    {
441
22.7k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
22.2k
      {
443
22.2k
        return m_NextLayer;
444
22.2k
      }
445
446
494
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
22.7k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::S7CommLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
440
7.50k
    {
441
7.50k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
6.42k
      {
443
6.42k
        return m_NextLayer;
444
6.42k
      }
445
446
1.08k
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
7.50k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::ArpLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
440
22.6k
    {
441
22.6k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
22.5k
      {
443
22.5k
        return m_NextLayer;
444
22.5k
      }
445
446
108
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
22.6k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::VlanLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
440
198k
    {
441
198k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
198k
      {
443
198k
        return m_NextLayer;
444
198k
      }
445
446
144
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
198k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::MplsLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
440
36.9k
    {
441
36.9k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
36.9k
      {
443
36.9k
        return m_NextLayer;
444
36.9k
      }
445
446
3
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
36.9k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::WakeOnLanLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
440
678
    {
441
678
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
18
      {
443
18
        return m_NextLayer;
444
18
      }
445
446
660
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
678
    }
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
446k
    {
474
      // Note that the fallback is first to allow template argument deduction of the factory type.
475
446k
      return tryConstructNextLayerFromFactoryWithFallback<TFallback, TFactory>(
476
446k
          factoryFn, data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
477
446k
    }
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.0k
    {
474
      // Note that the fallback is first to allow template argument deduction of the factory type.
475
84.0k
      return tryConstructNextLayerFromFactoryWithFallback<TFallback, TFactory>(
476
84.0k
          factoryFn, data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
477
84.0k
    }
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
63.4k
    {
474
      // Note that the fallback is first to allow template argument deduction of the factory type.
475
63.4k
      return tryConstructNextLayerFromFactoryWithFallback<TFallback, TFactory>(
476
63.4k
          factoryFn, data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
477
63.4k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerFromFactoryWithFallback<pcpp::PayloadLayer, pcpp::LdapLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*)>(pcpp::LdapLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*), unsigned char*, unsigned long)
Line
Count
Source
473
44.9k
    {
474
      // Note that the fallback is first to allow template argument deduction of the factory type.
475
44.9k
      return tryConstructNextLayerFromFactoryWithFallback<TFallback, TFactory>(
476
44.9k
          factoryFn, data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
477
44.9k
    }
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.33k
    {
474
      // Note that the fallback is first to allow template argument deduction of the factory type.
475
4.33k
      return tryConstructNextLayerFromFactoryWithFallback<TFallback, TFactory>(
476
4.33k
          factoryFn, data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
477
4.33k
    }
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
145k
    {
474
      // Note that the fallback is first to allow template argument deduction of the factory type.
475
145k
      return tryConstructNextLayerFromFactoryWithFallback<TFallback, TFactory>(
476
145k
          factoryFn, data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
477
145k
    }
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
446k
    {
503
446k
      auto nextLayer = constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, packet,
504
446k
                                                               std::forward<Args>(extraArgs)...);
505
446k
      if (nextLayer != nullptr)
506
269k
      {
507
269k
        return nextLayer;
508
269k
      }
509
510
      // factory failed, construct fallback layer
511
176k
      return constructNextLayer<TFallback>(data, dataLen, packet);
512
446k
    }
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.0k
    {
503
84.0k
      auto nextLayer = constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, packet,
504
84.0k
                                                               std::forward<Args>(extraArgs)...);
505
84.0k
      if (nextLayer != nullptr)
506
79.2k
      {
507
79.2k
        return nextLayer;
508
79.2k
      }
509
510
      // factory failed, construct fallback layer
511
4.79k
      return constructNextLayer<TFallback>(data, dataLen, packet);
512
84.0k
    }
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
63.4k
    {
503
63.4k
      auto nextLayer = constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, packet,
504
63.4k
                                                               std::forward<Args>(extraArgs)...);
505
63.4k
      if (nextLayer != nullptr)
506
63.1k
      {
507
63.1k
        return nextLayer;
508
63.1k
      }
509
510
      // factory failed, construct fallback layer
511
379
      return constructNextLayer<TFallback>(data, dataLen, packet);
512
63.4k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerFromFactoryWithFallback<pcpp::PayloadLayer, pcpp::LdapLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*)>(pcpp::LdapLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*), unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
502
44.9k
    {
503
44.9k
      auto nextLayer = constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, packet,
504
44.9k
                                                               std::forward<Args>(extraArgs)...);
505
44.9k
      if (nextLayer != nullptr)
506
30.3k
      {
507
30.3k
        return nextLayer;
508
30.3k
      }
509
510
      // factory failed, construct fallback layer
511
14.5k
      return constructNextLayer<TFallback>(data, dataLen, packet);
512
44.9k
    }
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.8k
      {
507
87.8k
        return nextLayer;
508
87.8k
      }
509
510
      // factory failed, construct fallback layer
511
16.3k
      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.33k
    {
503
4.33k
      auto nextLayer = constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, packet,
504
4.33k
                                                               std::forward<Args>(extraArgs)...);
505
4.33k
      if (nextLayer != nullptr)
506
4.33k
      {
507
4.33k
        return nextLayer;
508
4.33k
      }
509
510
      // factory failed, construct fallback layer
511
0
      return constructNextLayer<TFallback>(data, dataLen, packet);
512
4.33k
    }
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
145k
    {
503
145k
      auto nextLayer = constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, packet,
504
145k
                                                               std::forward<Args>(extraArgs)...);
505
145k
      if (nextLayer != nullptr)
506
5.08k
      {
507
5.08k
        return nextLayer;
508
5.08k
      }
509
510
      // factory failed, construct fallback layer
511
140k
      return constructNextLayer<TFallback>(data, dataLen, packet);
512
145k
    }
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.97M
    {
524
2.97M
      return data != nullptr && dataLen >= sizeof(T);
525
2.97M
    }
bool pcpp::Layer::canReinterpretAs<pcpp::arphdr>(unsigned char const*, unsigned long)
Line
Count
Source
523
22.6k
    {
524
22.6k
      return data != nullptr && dataLen >= sizeof(T);
525
22.6k
    }
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.3k
    {
524
14.3k
      return data != nullptr && dataLen >= sizeof(T);
525
14.3k
    }
bool pcpp::Layer::canReinterpretAs<pcpp::ip6_hdr>(unsigned char const*, unsigned long)
Line
Count
Source
523
408k
    {
524
408k
      return data != nullptr && dataLen >= sizeof(T);
525
408k
    }
bool pcpp::Layer::canReinterpretAs<pcpp::vlan_header>(unsigned char const*, unsigned long)
Line
Count
Source
523
198k
    {
524
198k
      return data != nullptr && dataLen >= sizeof(T);
525
198k
    }
bool pcpp::Layer::canReinterpretAs<pcpp::MplsLayer::mpls_header>(unsigned char const*, unsigned long)
Line
Count
Source
523
36.9k
    {
524
36.9k
      return data != nullptr && dataLen >= sizeof(T);
525
36.9k
    }
bool pcpp::Layer::canReinterpretAs<pcpp::igmp_header>(unsigned char const*, unsigned long)
Line
Count
Source
523
17.1k
    {
524
17.1k
      return data != nullptr && dataLen >= sizeof(T);
525
17.1k
    }
bool pcpp::Layer::canReinterpretAs<pcpp::igmpv3_query_header>(unsigned char const*, unsigned long)
Line
Count
Source
523
1.96k
    {
524
1.96k
      return data != nullptr && dataLen >= sizeof(T);
525
1.96k
    }
bool pcpp::Layer::canReinterpretAs<pcpp::igmpv3_report_header>(unsigned char const*, unsigned long)
Line
Count
Source
523
3.76k
    {
524
3.76k
      return data != nullptr && dataLen >= sizeof(T);
525
3.76k
    }
bool pcpp::Layer::canReinterpretAs<pcpp::tpkthdr>(unsigned char const*, unsigned long)
Line
Count
Source
523
359k
    {
524
359k
      return data != nullptr && dataLen >= sizeof(T);
525
359k
    }
bool pcpp::Layer::canReinterpretAs<pcpp::stp_tcn_bpdu>(unsigned char const*, unsigned long)
Line
Count
Source
523
3.11k
    {
524
3.11k
      return data != nullptr && dataLen >= sizeof(T);
525
3.11k
    }
bool pcpp::Layer::canReinterpretAs<pcpp::stp_conf_bpdu>(unsigned char const*, unsigned long)
Line
Count
Source
523
2.76k
    {
524
2.76k
      return data != nullptr && dataLen >= sizeof(T);
525
2.76k
    }
bool pcpp::Layer::canReinterpretAs<pcpp::rstp_conf_bpdu>(unsigned char const*, unsigned long)
Line
Count
Source
523
1.52k
    {
524
1.52k
      return data != nullptr && dataLen >= sizeof(T);
525
1.52k
    }
bool pcpp::Layer::canReinterpretAs<pcpp::mstp_conf_bpdu>(unsigned char const*, unsigned long)
Line
Count
Source
523
188
    {
524
188
      return data != nullptr && dataLen >= sizeof(T);
525
188
    }
526
  };
527
528
  inline std::ostream& operator<<(std::ostream& os, const pcpp::Layer& layer)
529
0
  {
530
0
    os << layer.toString();
531
0
    return os;
532
0
  }
533
}  // namespace pcpp