Coverage Report

Created: 2026-03-07 06:49

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/PcapPlusPlus/Packet++/header/Layer.h
Line
Count
Source
1
#pragma once
2
3
#include <stdint.h>
4
#include <stdio.h>
5
#include "ProtocolType.h"
6
#include <string>
7
#include <stdexcept>
8
#include <utility>
9
10
/// @file
11
12
/// @namespace pcpp
13
/// @brief The main namespace for the PcapPlusPlus lib
14
namespace pcpp
15
{
16
17
  /// @class IDataContainer
18
  /// An interface (virtual abstract class) that indicates an object that holds a pointer to a buffer data. The Layer
19
  /// class is an example of such object, hence it inherits this interface
20
  class IDataContainer
21
  {
22
  public:
23
    /// Get a pointer to the data
24
    /// @param[in] offset Get a pointer in a certain offset. Default is 0 - get a pointer to start of data
25
    /// @return A pointer to the data
26
    virtual uint8_t* getDataPtr(size_t offset = 0) const = 0;
27
28
9.57M
    virtual ~IDataContainer() = default;
29
  };
30
31
  class Packet;
32
33
  namespace internal
34
  {
35
    /// @brief Holds information about a Layer's data and object ownership.
36
    struct LayerAllocationInfo
37
    {
38
      /// @brief Pointer to the Packet this layer is attached to (if any).
39
      ///
40
      /// If the layer is attached to a Packet, the layer's memory span (data) is considered managed by the
41
      /// Packet. The Packet is responsible for keeping the layer's memory span valid and updating it should it
42
      /// become necessary as long as the layer is attached to it.
43
      ///
44
      /// In an event the Packet is destroyed, all of its attached layers's memory views are considered invalid.
45
      /// Accessing layer data after the Packet is destroyed results in undefined behavior.
46
      ///
47
      /// If nullptr, the layer is not attached to any Packet and is considered unmanaged.
48
      /// It also means the layer's memory span is considered owned by the layer itself and will be freed when
49
      /// the layer is destroyed.
50
      Packet* attachedPacket = nullptr;
51
52
      /// @brief Controls if the layer object is considered owned by the attached Packet
53
      ///
54
      /// If 'true', the Layer object is considered owned by the attached Packet and will be freed by it on Packet
55
      /// destruction.
56
      ///
57
      /// If 'false', the Layer object is considered unmanaged and the user is responsible for freeing it.
58
      /// This is commonly the case for layers created on the stack and attached to a Packet.
59
      bool ownedByPacket = false;
60
61
      /// @brief Sets the state of attachment to a specified Packet
62
      /// @param packet Pointer to the Packet this layer is attached to (or nullptr if not attached to any Packet)
63
      /// @param managed True if the layer object's lifetime is to be managed by the Packet, false otherwise
64
      /// @param force If true, bypasses the check for existing attachment. Default is false.
65
      /// @throws std::runtime_error if the layer is already attached to a Packet and 'force' is false
66
      void attachPacket(Packet* packet, bool managed, bool force = false)
67
0
      {
68
0
        if (!force && attachedPacket != nullptr)
69
0
        {
70
0
          throw std::runtime_error("Layer is already attached to a Packet");
71
0
        }
72
73
0
        attachedPacket = packet;
74
0
        ownedByPacket = managed;
75
0
      }
76
77
      /// @brief Clears the attachment to any Packet, resetting to unmanaged state.
78
      void detach()
79
0
      {
80
0
        attachedPacket = nullptr;
81
0
        ownedByPacket = false;
82
0
      }
83
    };
84
  }  // namespace internal
85
86
  /// @class Layer
87
  /// Layer is the base class for all protocol layers. Each protocol supported in PcapPlusPlus has a class that
88
  /// inherits Layer.
89
  /// The protocol layer class expose all properties and methods relevant for viewing and editing protocol fields.
90
  /// For example: a pointer to a structured header (e.g tcphdr, iphdr, etc.), protocol header size, payload size,
91
  /// compute fields that can be automatically computed, print protocol data to string, etc.
92
  /// Each protocol instance is obviously part of a protocol stack (which construct a packet). This protocol stack is
93
  /// represented in PcapPlusPlus in a linked list, and each layer is an element in this list. That's why each layer
94
  /// has properties to the next and previous layer in the protocol stack. The Layer class, as a base class, is
95
  /// abstract and the user can't create an instance of it (it has a private constructor). Each layer holds a pointer
96
  /// to the relevant place in the packet. The layer sees all the data from this pointer forward until the end of the
97
  /// packet. Here is an example packet showing this concept:
98
  ///
99
  /// @code{.unparsed}
100
  /// ====================================================
101
  /// |Eth       |IPv4       |TCP       |Packet          |
102
  /// |Header    |Header     |Header    |Payload         |
103
  /// ====================================================
104
  ///
105
  /// |--------------------------------------------------|
106
  /// EthLayer data
107
  ///            |---------------------------------------|
108
  ///            IPv4Layer data
109
  ///                        |---------------------------|
110
  ///                        TcpLayer data
111
  ///                                   |----------------|
112
  ///                                   PayloadLayer data
113
  /// @endcode
114
  class Layer : public IDataContainer
115
  {
116
    friend class Packet;
117
118
  public:
119
    /// A destructor for this class. Frees the data if it was allocated by the layer constructor (see
120
    /// isAllocatedToPacket() for more info)
121
    ~Layer() override;
122
123
    /// @return A pointer to the next layer in the protocol stack or nullptr if the layer is the last one
124
    Layer* getNextLayer() const
125
194M
    {
126
194M
      return m_NextLayer;
127
194M
    }
128
129
    /// @return A pointer to the previous layer in the protocol stack or nullptr if the layer is the first one
130
    Layer* getPrevLayer() const
131
1.80M
    {
132
1.80M
      return m_PrevLayer;
133
1.80M
    }
134
135
    /// @return The protocol enum
136
    ProtocolType getProtocol() const
137
141M
    {
138
141M
      return m_Protocol;
139
141M
    }
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
297k
    {
149
297k
      return m_Data;
150
297k
    }
151
152
    /// @return The length in bytes of the data from the first byte of the header until the end of the packet
153
    size_t getDataLen() const
154
3.07M
    {
155
3.07M
      return m_DataLen;
156
3.07M
    }
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
29.3k
    {
167
29.3k
      return m_DataLen - getHeaderLen();
168
29.3k
    }
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
9.57M
    {
181
9.57M
      return m_AllocationInfo.attachedPacket != nullptr;
182
9.57M
    }
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
159k
    {
192
159k
      return static_cast<uint8_t*>(m_Data + offset);
193
159k
    }
194
195
    // abstract methods
196
197
    /// Each layer is responsible for parsing the next layer
198
    virtual void parseNextLayer() = 0;
199
200
    /// @return The header length in bytes
201
    virtual size_t getHeaderLen() const = 0;
202
203
    /// Each layer can compute field values automatically using this method. This is an abstract method
204
    virtual void computeCalculateFields() = 0;
205
206
    /// @return A string representation of the layer most important data (should look like the layer description in
207
    /// Wireshark)
208
    virtual std::string toString() const = 0;
209
210
    /// @return The OSI Model layer this protocol belongs to
211
    virtual OsiModelLayer getOsiModelLayer() const = 0;
212
213
  protected:
214
    uint8_t* m_Data;
215
    size_t m_DataLen;
216
    ProtocolType m_Protocol;
217
    Layer* m_NextLayer;
218
    Layer* m_PrevLayer;
219
220
  private:
221
    internal::LayerAllocationInfo m_AllocationInfo;
222
223
  protected:
224
0
    Layer() : m_Data(nullptr), m_DataLen(0), m_Protocol(UnknownProtocol), m_NextLayer(nullptr), m_PrevLayer(nullptr)
225
0
    {}
226
227
    Layer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet, ProtocolType protocol = UnknownProtocol)
228
9.39M
        : m_Data(data), m_DataLen(dataLen), m_Protocol(protocol), m_NextLayer(nullptr), m_PrevLayer(prevLayer),
229
9.39M
          m_AllocationInfo{ packet, false }
230
9.39M
    {}
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
8.85M
    {
240
8.85M
      return m_AllocationInfo.attachedPacket;
241
8.85M
    }
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
1.99k
    {
247
1.99k
      return m_AllocationInfo.attachedPacket;
248
1.99k
    }
249
250
    void setNextLayer(Layer* nextLayer)
251
8.23M
    {
252
8.23M
      m_NextLayer = nextLayer;
253
8.23M
    }
254
    void setPrevLayer(Layer* prevLayer)
255
0
    {
256
0
      m_PrevLayer = prevLayer;
257
0
    }
258
259
    virtual bool extendLayer(int offsetInLayer, size_t numOfBytesToExtend);
260
    virtual bool shortenLayer(int offsetInLayer, size_t numOfBytesToShorten);
261
262
    bool hasNextLayer() const
263
11.9M
    {
264
11.9M
      return m_NextLayer != nullptr;
265
11.9M
    }
266
267
    /// @brief Construct the next layer in the protocol stack. No validation is performed on the data.
268
    ///
269
    /// This overload infers the Packet from the current layer.
270
    ///
271
    /// @tparam T The type of the layer to construct
272
    /// @tparam Args The types of the arguments to pass to the layer constructor
273
    /// @param data The data to construct the layer from
274
    /// @param dataLen The length of the data
275
    /// @param extraArgs Extra arguments to be forwarded to the layer constructor
276
    /// @return The constructed layer
277
    template <typename T, typename... Args>
278
    Layer* constructNextLayer(uint8_t* data, size_t dataLen, Args&&... extraArgs)
279
4.35M
    {
280
4.35M
      return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
281
4.35M
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::VlanLayer>(unsigned char*, unsigned long)
Line
Count
Source
279
23.4k
    {
280
23.4k
      return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
281
23.4k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::MplsLayer>(unsigned char*, unsigned long)
Line
Count
Source
279
4.04M
    {
280
4.04M
      return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
281
4.04M
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
279
89.9k
    {
280
89.9k
      return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
281
89.9k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::VrrpV3Layer, pcpp::IPAddress::AddressType>(unsigned char*, unsigned long, pcpp::IPAddress::AddressType&&)
Line
Count
Source
279
2.68k
    {
280
2.68k
      return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
281
2.68k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::ArpLayer>(unsigned char*, unsigned long)
Line
Count
Source
279
6.43k
    {
280
6.43k
      return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
281
6.43k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::DhcpLayer>(unsigned char*, unsigned long)
Line
Count
Source
279
18.5k
    {
280
18.5k
      return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
281
18.5k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::VxlanLayer>(unsigned char*, unsigned long)
Line
Count
Source
279
9.90k
    {
280
9.90k
      return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
281
9.90k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::DnsLayer>(unsigned char*, unsigned long)
Line
Count
Source
279
86.1k
    {
280
86.1k
      return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
281
86.1k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::RadiusLayer>(unsigned char*, unsigned long)
Line
Count
Source
279
22.4k
    {
280
22.4k
      return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
281
22.4k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::GtpV1Layer>(unsigned char*, unsigned long)
Line
Count
Source
279
13.8k
    {
280
13.8k
      return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
281
13.8k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::GtpV2Layer>(unsigned char*, unsigned long)
Line
Count
Source
279
1.06k
    {
280
1.06k
      return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
281
1.06k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::DhcpV6Layer>(unsigned char*, unsigned long)
Line
Count
Source
279
5.65k
    {
280
5.65k
      return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
281
5.65k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::NtpLayer>(unsigned char*, unsigned long)
Line
Count
Source
279
13.0k
    {
280
13.0k
      return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
281
13.0k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::WakeOnLanLayer>(unsigned char*, unsigned long)
Line
Count
Source
279
873
    {
280
873
      return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
281
873
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::EthLayer>(unsigned char*, unsigned long)
Line
Count
Source
279
9.51k
    {
280
9.51k
      return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
281
9.51k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::SdpLayer>(unsigned char*, unsigned long)
Line
Count
Source
279
7.35k
    {
280
7.35k
      return constructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
281
7.35k
    }
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
7.55M
    {
294
7.55M
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
7.55M
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
7.55M
      setNextLayer(newLayer);
301
7.55M
      return newLayer;
302
7.55M
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::IPv4Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
1.00M
    {
294
1.00M
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
1.00M
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
1.00M
      setNextLayer(newLayer);
301
1.00M
      return newLayer;
302
1.00M
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
470k
    {
294
470k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
470k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
470k
      setNextLayer(newLayer);
301
470k
      return newLayer;
302
470k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::IPv6Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
246k
    {
294
246k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
246k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
246k
      setNextLayer(newLayer);
301
246k
      return newLayer;
302
246k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::VlanLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
76.3k
    {
294
76.3k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
76.3k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
76.3k
      setNextLayer(newLayer);
301
76.3k
      return newLayer;
302
76.3k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::MplsLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
4.08M
    {
294
4.08M
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
4.08M
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
4.08M
      setNextLayer(newLayer);
301
4.08M
      return newLayer;
302
4.08M
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::PPP_PPTPLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
14.0k
    {
294
14.0k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
14.0k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
14.0k
      setNextLayer(newLayer);
301
14.0k
      return newLayer;
302
14.0k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::EthLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
9.51k
    {
294
9.51k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
9.51k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
9.51k
      setNextLayer(newLayer);
301
9.51k
      return newLayer;
302
9.51k
    }
Unexecuted instantiation: pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::EthDot3Layer>(unsigned char*, unsigned long, pcpp::Packet*)
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::GtpV2Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
1.68k
    {
294
1.68k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
1.68k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
1.68k
      setNextLayer(newLayer);
301
1.68k
      return newLayer;
302
1.68k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::UdpLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
377k
    {
294
377k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
377k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
377k
      setNextLayer(newLayer);
301
377k
      return newLayer;
302
377k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::TcpLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
771k
    {
294
771k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
771k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
771k
      setNextLayer(newLayer);
301
771k
      return newLayer;
302
771k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::IcmpLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
23.3k
    {
294
23.3k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
23.3k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
23.3k
      setNextLayer(newLayer);
301
23.3k
      return newLayer;
302
23.3k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::GREv0Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
8.17k
    {
294
8.17k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
8.17k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
8.17k
      setNextLayer(newLayer);
301
8.17k
      return newLayer;
302
8.17k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::GREv1Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
16.5k
    {
294
16.5k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
16.5k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
16.5k
      setNextLayer(newLayer);
301
16.5k
      return newLayer;
302
16.5k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::IgmpV1Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
3.11k
    {
294
3.11k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
3.11k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
3.11k
      setNextLayer(newLayer);
301
3.11k
      return newLayer;
302
3.11k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::IgmpV2Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
2.99k
    {
294
2.99k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
2.99k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
2.99k
      setNextLayer(newLayer);
301
2.99k
      return newLayer;
302
2.99k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::IgmpV3QueryLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
187
    {
294
187
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
187
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
187
      setNextLayer(newLayer);
301
187
      return newLayer;
302
187
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::IgmpV3ReportLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
1.67k
    {
294
1.67k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
1.67k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
1.67k
      setNextLayer(newLayer);
301
1.67k
      return newLayer;
302
1.67k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::AuthenticationHeaderLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
1.54k
    {
294
1.54k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
1.54k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
1.54k
      setNextLayer(newLayer);
301
1.54k
      return newLayer;
302
1.54k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::ESPLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
598
    {
294
598
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
598
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
598
      setNextLayer(newLayer);
301
598
      return newLayer;
302
598
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::VrrpV2Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
5.51k
    {
294
5.51k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
5.51k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
5.51k
      setNextLayer(newLayer);
301
5.51k
      return newLayer;
302
5.51k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::VrrpV3Layer, pcpp::IPAddress::AddressType>(unsigned char*, unsigned long, pcpp::Packet*, pcpp::IPAddress::AddressType&&)
Line
Count
Source
293
4.53k
    {
294
4.53k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
4.53k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
4.53k
      setNextLayer(newLayer);
301
4.53k
      return newLayer;
302
4.53k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::ArpLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
26.4k
    {
294
26.4k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
26.4k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
26.4k
      setNextLayer(newLayer);
301
26.4k
      return newLayer;
302
26.4k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::PPPoESessionLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
19.1k
    {
294
19.1k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
19.1k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
19.1k
      setNextLayer(newLayer);
301
19.1k
      return newLayer;
302
19.1k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::PPPoEDiscoveryLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
1.02k
    {
294
1.02k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
1.02k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
1.02k
      setNextLayer(newLayer);
301
1.02k
      return newLayer;
302
1.02k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::HttpRequestLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
91.1k
    {
294
91.1k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
91.1k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
91.1k
      setNextLayer(newLayer);
301
91.1k
      return newLayer;
302
91.1k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::HttpResponseLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
14.4k
    {
294
14.4k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
14.4k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
14.4k
      setNextLayer(newLayer);
301
14.4k
      return newLayer;
302
14.4k
    }
Unexecuted instantiation: pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::SipRequestLayer>(unsigned char*, unsigned long, pcpp::Packet*)
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::SipResponseLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
119
    {
294
119
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
119
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
119
      setNextLayer(newLayer);
301
119
      return newLayer;
302
119
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::DnsOverTcpLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
6.66k
    {
294
6.66k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
6.66k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
6.66k
      setNextLayer(newLayer);
301
6.66k
      return newLayer;
302
6.66k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::TelnetLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
10.5k
    {
294
10.5k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
10.5k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
10.5k
      setNextLayer(newLayer);
301
10.5k
      return newLayer;
302
10.5k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::FtpResponseLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
9.81k
    {
294
9.81k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
9.81k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
9.81k
      setNextLayer(newLayer);
301
9.81k
      return newLayer;
302
9.81k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::FtpRequestLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
4.38k
    {
294
4.38k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
4.38k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
4.38k
      setNextLayer(newLayer);
301
4.38k
      return newLayer;
302
4.38k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::FtpDataLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
1.22k
    {
294
1.22k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
1.22k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
1.22k
      setNextLayer(newLayer);
301
1.22k
      return newLayer;
302
1.22k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::TpktLayer>(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::SmtpResponseLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
6.39k
    {
294
6.39k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
6.39k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
6.39k
      setNextLayer(newLayer);
301
6.39k
      return newLayer;
302
6.39k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::SmtpRequestLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
8.04k
    {
294
8.04k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
8.04k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
8.04k
      setNextLayer(newLayer);
301
8.04k
      return newLayer;
302
8.04k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::ModbusLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
1.66k
    {
294
1.66k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
1.66k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
1.66k
      setNextLayer(newLayer);
301
1.66k
      return newLayer;
302
1.66k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::CotpLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
9.59k
    {
294
9.59k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
9.59k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
9.59k
      setNextLayer(newLayer);
301
9.59k
      return newLayer;
302
9.59k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::DhcpLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
18.5k
    {
294
18.5k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
18.5k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
18.5k
      setNextLayer(newLayer);
301
18.5k
      return newLayer;
302
18.5k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::VxlanLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
9.90k
    {
294
9.90k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
9.90k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
9.90k
      setNextLayer(newLayer);
301
9.90k
      return newLayer;
302
9.90k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::DnsLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
86.1k
    {
294
86.1k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
86.1k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
86.1k
      setNextLayer(newLayer);
301
86.1k
      return newLayer;
302
86.1k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::RadiusLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
22.4k
    {
294
22.4k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
22.4k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
22.4k
      setNextLayer(newLayer);
301
22.4k
      return newLayer;
302
22.4k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::GtpV1Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
13.8k
    {
294
13.8k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
13.8k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
13.8k
      setNextLayer(newLayer);
301
13.8k
      return newLayer;
302
13.8k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::DhcpV6Layer>(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::NtpLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
13.0k
    {
294
13.0k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
13.0k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
13.0k
      setNextLayer(newLayer);
301
13.0k
      return newLayer;
302
13.0k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::WakeOnLanLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
894
    {
294
894
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
894
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
894
      setNextLayer(newLayer);
301
894
      return newLayer;
302
894
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::LLCLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
15.5k
    {
294
15.5k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
15.5k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
15.5k
      setNextLayer(newLayer);
301
15.5k
      return newLayer;
302
15.5k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::S7CommLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
6.28k
    {
294
6.28k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
6.28k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
6.28k
      setNextLayer(newLayer);
301
6.28k
      return newLayer;
302
6.28k
    }
pcpp::Layer* pcpp::Layer::constructNextLayer<pcpp::SdpLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
293
7.35k
    {
294
7.35k
      if (hasNextLayer())
295
0
      {
296
0
        throw std::runtime_error("Next layer already exists");
297
0
      }
298
299
7.35k
      Layer* newLayer = new T(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
300
7.35k
      setNextLayer(newLayer);
301
7.35k
      return newLayer;
302
7.35k
    }
303
304
    /// @brief Construct the next layer in the protocol stack using a factory functor.
305
    ///
306
    /// No validation is performed on the data, outside of what the factory functor may perform.
307
    /// If the factory returns a nullptr, no next layer is set.
308
    ///
309
    /// The factory functor is expected to have the following signature:
310
    /// Layer* factoryFn(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet, ...);
311
    ///
312
    /// This overload infers the Packet from the current layer.
313
    ///
314
    /// @tparam TFactory The factory functor type.
315
    /// @tparam ...Args Parameter pack for extra arguments to pass to the factory functor.
316
    /// @param[in] factoryFn The factory functor to create the layer.
317
    /// @param[in] data The data to construct the layer from
318
    /// @param[in] dataLen The length of the data
319
    /// @param[in] extraArgs Extra arguments to be forwarded to the factory.
320
    /// @return The return value of the factory functor.
321
    template <typename TFactory, typename... Args>
322
    Layer* constructNextLayerFromFactory(TFactory factoryFn, uint8_t* data, size_t dataLen, Args&&... extraArgs)
323
473k
    {
324
473k
      return constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, getAttachedPacket(),
325
473k
                                                     std::forward<Args>(extraArgs)...);
326
473k
    }
pcpp::Layer* pcpp::Layer::constructNextLayerFromFactory<pcpp::BgpLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*)>(pcpp::BgpLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*), unsigned char*, unsigned long)
Line
Count
Source
323
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::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
76.5k
    {
324
76.5k
      return constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, getAttachedPacket(),
325
76.5k
                                                     std::forward<Args>(extraArgs)...);
326
76.5k
    }
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
349k
    {
324
349k
      return constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, getAttachedPacket(),
325
349k
                                                     std::forward<Args>(extraArgs)...);
326
349k
    }
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
12.6k
    {
324
12.6k
      return constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, getAttachedPacket(),
325
12.6k
                                                     std::forward<Args>(extraArgs)...);
326
12.6k
    }
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
849
    {
324
849
      return constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, getAttachedPacket(),
325
849
                                                     std::forward<Args>(extraArgs)...);
326
849
    }
pcpp::Layer* pcpp::Layer::constructNextLayerFromFactory<pcpp::StpLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*)>(pcpp::StpLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*), unsigned char*, unsigned long)
Line
Count
Source
323
7.01k
    {
324
7.01k
      return constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, getAttachedPacket(),
325
7.01k
                                                     std::forward<Args>(extraArgs)...);
326
7.01k
    }
327
328
    /// @brief Construct the next layer in the protocol stack using a factory functor.
329
    ///
330
    /// No validation is performed on the data, outside of what the factory functor may perform.
331
    /// If the factory returns a nullptr, no next layer is set.
332
    ///
333
    /// The factory functor is expected to have the following signature:
334
    /// Layer* factoryFn(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet, ...);
335
    ///
336
    /// @tparam TFactory The factory functor type.
337
    /// @tparam ...Args Parameter pack for extra arguments to pass to the factory functor.
338
    /// @param[in] factoryFn The factory functor to create the layer.
339
    /// @param[in] data The data to construct the layer from
340
    /// @param[in] dataLen The length of the data
341
    /// @param[in] packet The packet the layer belongs to
342
    /// @param[in] extraArgs Extra arguments to be forwarded to the factory.
343
    /// @return The return value of the factory functor.
344
    template <typename TFactory, typename... Args>
345
    Layer* constructNextLayerFromFactory(TFactory factoryFn, uint8_t* data, size_t dataLen, Packet* packet,
346
                                         Args&&... extraArgs)
347
661k
    {
348
661k
      if (hasNextLayer())
349
0
      {
350
0
        throw std::runtime_error("Next layer already exists");
351
0
      }
352
353
      // cppcheck-suppress redundantInitialization
354
661k
      Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
355
661k
      setNextLayer(newLayer);
356
661k
      return newLayer;
357
661k
    }
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
61.0k
    {
348
61.0k
      if (hasNextLayer())
349
0
      {
350
0
        throw std::runtime_error("Next layer already exists");
351
0
      }
352
353
      // cppcheck-suppress redundantInitialization
354
61.0k
      Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
355
61.0k
      setNextLayer(newLayer);
356
61.0k
      return newLayer;
357
61.0k
    }
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
76.5k
    {
348
76.5k
      if (hasNextLayer())
349
0
      {
350
0
        throw std::runtime_error("Next layer already exists");
351
0
      }
352
353
      // cppcheck-suppress redundantInitialization
354
76.5k
      Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
355
76.5k
      setNextLayer(newLayer);
356
76.5k
      return newLayer;
357
76.5k
    }
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
349k
    {
348
349k
      if (hasNextLayer())
349
0
      {
350
0
        throw std::runtime_error("Next layer already exists");
351
0
      }
352
353
      // cppcheck-suppress redundantInitialization
354
349k
      Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
355
349k
      setNextLayer(newLayer);
356
349k
      return newLayer;
357
349k
    }
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
12.6k
    {
348
12.6k
      if (hasNextLayer())
349
0
      {
350
0
        throw std::runtime_error("Next layer already exists");
351
0
      }
352
353
      // cppcheck-suppress redundantInitialization
354
12.6k
      Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
355
12.6k
      setNextLayer(newLayer);
356
12.6k
      return newLayer;
357
12.6k
    }
Unexecuted instantiation: pcpp::Layer* pcpp::Layer::constructNextLayerFromFactory<pcpp::DoIpLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*)>(pcpp::DoIpLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*), unsigned char*, unsigned long, pcpp::Packet*)
pcpp::Layer* pcpp::Layer::constructNextLayerFromFactory<pcpp::LdapLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*)>(pcpp::LdapLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*), unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
347
11.0k
    {
348
11.0k
      if (hasNextLayer())
349
0
      {
350
0
        throw std::runtime_error("Next layer already exists");
351
0
      }
352
353
      // cppcheck-suppress redundantInitialization
354
11.0k
      Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
355
11.0k
      setNextLayer(newLayer);
356
11.0k
      return newLayer;
357
11.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
36.5k
    {
348
36.5k
      if (hasNextLayer())
349
0
      {
350
0
        throw std::runtime_error("Next layer already exists");
351
0
      }
352
353
      // cppcheck-suppress redundantInitialization
354
36.5k
      Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
355
36.5k
      setNextLayer(newLayer);
356
36.5k
      return newLayer;
357
36.5k
    }
pcpp::Layer* pcpp::Layer::constructNextLayerFromFactory<pcpp::WireGuardLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*)>(pcpp::WireGuardLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*), unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
347
2.39k
    {
348
2.39k
      if (hasNextLayer())
349
0
      {
350
0
        throw std::runtime_error("Next layer already exists");
351
0
      }
352
353
      // cppcheck-suppress redundantInitialization
354
2.39k
      Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
355
2.39k
      setNextLayer(newLayer);
356
2.39k
      return newLayer;
357
2.39k
    }
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
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::StpLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*)>(pcpp::StpLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*), unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
347
7.01k
    {
348
7.01k
      if (hasNextLayer())
349
0
      {
350
0
        throw std::runtime_error("Next layer already exists");
351
0
      }
352
353
      // cppcheck-suppress redundantInitialization
354
7.01k
      Layer* newLayer = factoryFn(data, dataLen, this, packet, std::forward<Args>(extraArgs)...);
355
7.01k
      setNextLayer(newLayer);
356
7.01k
      return newLayer;
357
7.01k
    }
358
359
    /// Try to construct the next layer in the protocol stack.
360
    ///
361
    /// This overload infers the Packet from the current layer.
362
    ///
363
    /// The method checks if the data is valid for the layer type T before constructing it by calling
364
    /// T::isDataValid(data, dataLen). If the data is invalid, no layer is constructed and a nullptr is returned.
365
    ///
366
    /// @tparam T The type of the layer to construct
367
    /// @tparam Args The types of the extra arguments to pass to the layer constructor
368
    /// @param[in] data The data to construct the layer from
369
    /// @param[in] dataLen The length of the data
370
    /// @param[in] extraArgs Extra arguments to be forwarded to the layer constructor
371
    /// @return The constructed layer or nullptr if the data is invalid
372
    template <typename T, typename... Args>
373
    Layer* tryConstructNextLayer(uint8_t* data, size_t dataLen, Args&&... extraArgs)
374
0
    {
375
0
      return tryConstructNextLayer<T>(data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
376
0
    }
377
378
    /// Try to construct the next layer in the protocol stack.
379
    ///
380
    /// The method checks if the data is valid for the layer type T before constructing it by calling
381
    /// T::isDataValid(data, dataLen). If the data is invalid, no layer is constructed and a nullptr is returned.
382
    ///
383
    /// @tparam T The type of the layer to construct
384
    /// @tparam Args The types of the extra arguments to pass to the layer constructor
385
    /// @param[in] data The data to construct the layer from
386
    /// @param[in] dataLen The length of the data
387
    /// @param[in] packet The packet the layer belongs to
388
    /// @param[in] extraArgs Extra arguments to be forwarded to the layer constructor
389
    /// @return The constructed layer or nullptr if the data is invalid
390
    template <typename T, typename... Args>
391
    Layer* tryConstructNextLayer(uint8_t* data, size_t dataLen, Packet* packet, Args&&... extraArgs)
392
2.67M
    {
393
2.67M
      if (T::isDataValid(data, dataLen))
394
2.64M
      {
395
2.64M
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
2.64M
      }
397
21.3k
      return nullptr;
398
2.67M
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::IPv4Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
392
1.01M
    {
393
1.01M
      if (T::isDataValid(data, dataLen))
394
1.00M
      {
395
1.00M
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
1.00M
      }
397
6.13k
      return nullptr;
398
1.01M
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::IPv6Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
392
247k
    {
393
247k
      if (T::isDataValid(data, dataLen))
394
246k
      {
395
246k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
246k
      }
397
1.00k
      return nullptr;
398
247k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::PPP_PPTPLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
392
14.7k
    {
393
14.7k
      if (T::isDataValid(data, dataLen))
394
14.0k
      {
395
14.0k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
14.0k
      }
397
717
      return nullptr;
398
14.7k
    }
Unexecuted instantiation: pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::EthLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Unexecuted instantiation: pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::EthDot3Layer>(unsigned char*, unsigned long, pcpp::Packet*)
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::GtpV2Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
392
856
    {
393
856
      if (T::isDataValid(data, dataLen))
394
576
      {
395
576
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
576
      }
397
280
      return nullptr;
398
856
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::UdpLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
392
377k
    {
393
377k
      if (T::isDataValid(data, dataLen))
394
377k
      {
395
377k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
377k
      }
397
517
      return nullptr;
398
377k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::TcpLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
392
776k
    {
393
776k
      if (T::isDataValid(data, dataLen))
394
771k
      {
395
771k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
771k
      }
397
5.16k
      return nullptr;
398
776k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::IcmpLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
392
24.8k
    {
393
24.8k
      if (T::isDataValid(data, dataLen))
394
23.3k
      {
395
23.3k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
23.3k
      }
397
1.48k
      return nullptr;
398
24.8k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::GREv0Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
392
8.17k
    {
393
8.17k
      if (T::isDataValid(data, dataLen))
394
8.17k
      {
395
8.17k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
8.17k
      }
397
0
      return nullptr;
398
8.17k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::GREv1Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
392
16.8k
    {
393
16.8k
      if (T::isDataValid(data, dataLen))
394
16.5k
      {
395
16.5k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
16.5k
      }
397
214
      return nullptr;
398
16.8k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::IgmpV1Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
392
3.11k
    {
393
3.11k
      if (T::isDataValid(data, dataLen))
394
3.11k
      {
395
3.11k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
3.11k
      }
397
0
      return nullptr;
398
3.11k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::IgmpV2Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
392
2.99k
    {
393
2.99k
      if (T::isDataValid(data, dataLen))
394
2.99k
      {
395
2.99k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
2.99k
      }
397
0
      return nullptr;
398
2.99k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::IgmpV3QueryLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
392
187
    {
393
187
      if (T::isDataValid(data, dataLen))
394
187
      {
395
187
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
187
      }
397
0
      return nullptr;
398
187
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::IgmpV3ReportLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
392
1.67k
    {
393
1.67k
      if (T::isDataValid(data, dataLen))
394
1.67k
      {
395
1.67k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
1.67k
      }
397
0
      return nullptr;
398
1.67k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::AuthenticationHeaderLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
392
2.22k
    {
393
2.22k
      if (T::isDataValid(data, dataLen))
394
1.54k
      {
395
1.54k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
1.54k
      }
397
682
      return nullptr;
398
2.22k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::ESPLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
392
834
    {
393
834
      if (T::isDataValid(data, dataLen))
394
598
      {
395
598
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
598
      }
397
236
      return nullptr;
398
834
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::VrrpV2Layer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
392
5.51k
    {
393
5.51k
      if (T::isDataValid(data, dataLen))
394
5.51k
      {
395
5.51k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
5.51k
      }
397
0
      return nullptr;
398
5.51k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::VrrpV3Layer, pcpp::IPAddress::AddressType>(unsigned char*, unsigned long, pcpp::Packet*, pcpp::IPAddress::AddressType&&)
Line
Count
Source
392
1.84k
    {
393
1.84k
      if (T::isDataValid(data, dataLen))
394
1.84k
      {
395
1.84k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
1.84k
      }
397
0
      return nullptr;
398
1.84k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::PPPoESessionLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
392
19.3k
    {
393
19.3k
      if (T::isDataValid(data, dataLen))
394
19.1k
      {
395
19.1k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
19.1k
      }
397
197
      return nullptr;
398
19.3k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::PPPoEDiscoveryLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
392
1.09k
    {
393
1.09k
      if (T::isDataValid(data, dataLen))
394
1.02k
      {
395
1.02k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
1.02k
      }
397
69
      return nullptr;
398
1.09k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::CotpLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
392
10.9k
    {
393
10.9k
      if (T::isDataValid(data, dataLen))
394
9.59k
      {
395
9.59k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
9.59k
      }
397
1.35k
      return nullptr;
398
10.9k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::LLCLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
392
16.6k
    {
393
16.6k
      if (T::isDataValid(data, dataLen))
394
15.5k
      {
395
15.5k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
15.5k
      }
397
1.17k
      return nullptr;
398
16.6k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::S7CommLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
392
7.64k
    {
393
7.64k
      if (T::isDataValid(data, dataLen))
394
6.28k
      {
395
6.28k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
6.28k
      }
397
1.36k
      return nullptr;
398
7.64k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::ArpLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
392
20.0k
    {
393
20.0k
      if (T::isDataValid(data, dataLen))
394
19.9k
      {
395
19.9k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
19.9k
      }
397
75
      return nullptr;
398
20.0k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::VlanLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
392
52.9k
    {
393
52.9k
      if (T::isDataValid(data, dataLen))
394
52.8k
      {
395
52.8k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
52.8k
      }
397
75
      return nullptr;
398
52.9k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::MplsLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
392
44.3k
    {
393
44.3k
      if (T::isDataValid(data, dataLen))
394
44.2k
      {
395
44.2k
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
44.2k
      }
397
3
      return nullptr;
398
44.3k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayer<pcpp::WakeOnLanLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
392
603
    {
393
603
      if (T::isDataValid(data, dataLen))
394
21
      {
395
21
        return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
396
21
      }
397
582
      return nullptr;
398
603
    }
399
400
    /// @brief Try to construct the next layer in the protocol stack with a fallback option.
401
    ///
402
    /// This overload infers the Packet from the current layer.
403
    ///
404
    /// The method checks if the data is valid for the layer type T before constructing it by calling
405
    /// T::isDataValid(data, dataLen). If the data is invalid, it constructs the layer of type TFallback.
406
    ///
407
    /// @tparam T The type of the layer to construct
408
    /// @tparam TFallback The fallback layer type to construct if T fails
409
    /// @tparam Args The types of the extra arguments to pass to the layer constructor of T
410
    /// @param[in] data The data to construct the layer from
411
    /// @param[in] dataLen The length of the data
412
    /// @param[in] extraArgs Extra arguments to be forwarded to the layer constructor of T
413
    /// @return The constructed layer of type T or TFallback
414
    /// @remarks The parameters extraArgs are forwarded to the factory function, but not to the TFallback
415
    /// constructor.
416
    template <typename T, typename TFallback, typename... Args>
417
    Layer* tryConstructNextLayerWithFallback(uint8_t* data, size_t dataLen, Args&&... extraArgs)
418
1.67M
    {
419
1.67M
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
420
1.67M
                                                             std::forward<Args>(extraArgs)...);
421
1.67M
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::IPv4Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
418
1.01M
    {
419
1.01M
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
420
1.01M
                                                             std::forward<Args>(extraArgs)...);
421
1.01M
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::IPv6Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
418
240k
    {
419
240k
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
420
240k
                                                             std::forward<Args>(extraArgs)...);
421
240k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::PPP_PPTPLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
418
14.7k
    {
419
14.7k
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
420
14.7k
                                                             std::forward<Args>(extraArgs)...);
421
14.7k
    }
Unexecuted instantiation: pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::EthDot3Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::GtpV2Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
418
856
    {
419
856
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
420
856
                                                             std::forward<Args>(extraArgs)...);
421
856
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::UdpLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
418
13.2k
    {
419
13.2k
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
420
13.2k
                                                             std::forward<Args>(extraArgs)...);
421
13.2k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::TcpLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
418
213k
    {
419
213k
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
420
213k
                                                             std::forward<Args>(extraArgs)...);
421
213k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::GREv0Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
418
2.06k
    {
419
2.06k
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
420
2.06k
                                                             std::forward<Args>(extraArgs)...);
421
2.06k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::GREv1Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
418
916
    {
419
916
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
420
916
                                                             std::forward<Args>(extraArgs)...);
421
916
    }
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
654
    {
419
654
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
420
654
                                                             std::forward<Args>(extraArgs)...);
421
654
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::PPPoESessionLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
418
19.3k
    {
419
19.3k
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
420
19.3k
                                                             std::forward<Args>(extraArgs)...);
421
19.3k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::PPPoEDiscoveryLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
418
1.09k
    {
419
1.09k
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
420
1.09k
                                                             std::forward<Args>(extraArgs)...);
421
1.09k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::CotpLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
418
10.9k
    {
419
10.9k
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
420
10.9k
                                                             std::forward<Args>(extraArgs)...);
421
10.9k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::LLCLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
418
16.6k
    {
419
16.6k
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
420
16.6k
                                                             std::forward<Args>(extraArgs)...);
421
16.6k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::S7CommLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
418
7.64k
    {
419
7.64k
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
420
7.64k
                                                             std::forward<Args>(extraArgs)...);
421
7.64k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::ArpLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
418
20.0k
    {
419
20.0k
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
420
20.0k
                                                             std::forward<Args>(extraArgs)...);
421
20.0k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::VlanLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
418
52.9k
    {
419
52.9k
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
420
52.9k
                                                             std::forward<Args>(extraArgs)...);
421
52.9k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::MplsLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
418
44.3k
    {
419
44.3k
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
420
44.3k
                                                             std::forward<Args>(extraArgs)...);
421
44.3k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::WakeOnLanLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long)
Line
Count
Source
418
603
    {
419
603
      return tryConstructNextLayerWithFallback<T, TFallback>(data, dataLen, getAttachedPacket(),
420
603
                                                             std::forward<Args>(extraArgs)...);
421
603
    }
422
423
    /// Try to construct the next layer in the protocol stack with a fallback option.
424
    ///
425
    /// The method checks if the data is valid for the layer type T before constructing it by calling
426
    /// T::isDataValid(data, dataLen). If the data is invalid, it constructs the layer of type TFallback.
427
    ///
428
    /// @tparam T The type of the layer to construct
429
    /// @tparam TFallback The fallback layer type to construct if T fails
430
    /// @tparam Args The types of the extra arguments to pass to the layer constructor of T
431
    /// @param[in] data The data to construct the layer from
432
    /// @param[in] dataLen The length of the data
433
    /// @param[in] packet The packet the layer belongs to
434
    /// @param[in] extraArgs Extra arguments to be forwarded to the layer constructor of T
435
    /// @return The constructed layer of type T or TFallback
436
    /// @remarks The parameters extraArgs are forwarded to the factory function, but not to the TFallback
437
    /// constructor.
438
    template <typename T, typename TFallback, typename... Args>
439
    Layer* tryConstructNextLayerWithFallback(uint8_t* data, size_t dataLen, Packet* packet, Args&&... extraArgs)
440
2.67M
    {
441
2.67M
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
2.64M
      {
443
2.64M
        return m_NextLayer;
444
2.64M
      }
445
446
21.3k
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
2.67M
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::IPv4Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
440
1.01M
    {
441
1.01M
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
1.00M
      {
443
1.00M
        return m_NextLayer;
444
1.00M
      }
445
446
6.13k
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
1.01M
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::IPv6Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
440
247k
    {
441
247k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
246k
      {
443
246k
        return m_NextLayer;
444
246k
      }
445
446
1.00k
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
247k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::PPP_PPTPLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
440
14.7k
    {
441
14.7k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
14.0k
      {
443
14.0k
        return m_NextLayer;
444
14.0k
      }
445
446
717
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
14.7k
    }
Unexecuted instantiation: pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::EthDot3Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::GtpV2Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
440
856
    {
441
856
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
576
      {
443
576
        return m_NextLayer;
444
576
      }
445
446
280
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
856
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::UdpLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
440
377k
    {
441
377k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
377k
      {
443
377k
        return m_NextLayer;
444
377k
      }
445
446
517
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
377k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::TcpLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
440
776k
    {
441
776k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
771k
      {
443
771k
        return m_NextLayer;
444
771k
      }
445
446
5.16k
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
776k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::IcmpLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
440
24.8k
    {
441
24.8k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
23.3k
      {
443
23.3k
        return m_NextLayer;
444
23.3k
      }
445
446
1.48k
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
24.8k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::GREv0Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
440
8.17k
    {
441
8.17k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
8.17k
      {
443
8.17k
        return m_NextLayer;
444
8.17k
      }
445
446
0
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
8.17k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::GREv1Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
440
16.8k
    {
441
16.8k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
16.5k
      {
443
16.5k
        return m_NextLayer;
444
16.5k
      }
445
446
214
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
16.8k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::IgmpV1Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
440
3.11k
    {
441
3.11k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
3.11k
      {
443
3.11k
        return m_NextLayer;
444
3.11k
      }
445
446
0
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
3.11k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::IgmpV2Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
440
2.99k
    {
441
2.99k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
2.99k
      {
443
2.99k
        return m_NextLayer;
444
2.99k
      }
445
446
0
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
2.99k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::IgmpV3QueryLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
440
187
    {
441
187
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
187
      {
443
187
        return m_NextLayer;
444
187
      }
445
446
0
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
187
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::IgmpV3ReportLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
440
1.67k
    {
441
1.67k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
1.67k
      {
443
1.67k
        return m_NextLayer;
444
1.67k
      }
445
446
0
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
1.67k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::AuthenticationHeaderLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
440
2.22k
    {
441
2.22k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
1.54k
      {
443
1.54k
        return m_NextLayer;
444
1.54k
      }
445
446
682
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
2.22k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::ESPLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
440
834
    {
441
834
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
598
      {
443
598
        return m_NextLayer;
444
598
      }
445
446
236
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
834
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::VrrpV2Layer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
440
5.51k
    {
441
5.51k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
5.51k
      {
443
5.51k
        return m_NextLayer;
444
5.51k
      }
445
446
0
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
5.51k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::VrrpV3Layer, pcpp::PayloadLayer, pcpp::IPAddress::AddressType>(unsigned char*, unsigned long, pcpp::Packet*, pcpp::IPAddress::AddressType&&)
Line
Count
Source
440
1.84k
    {
441
1.84k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
1.84k
      {
443
1.84k
        return m_NextLayer;
444
1.84k
      }
445
446
0
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
1.84k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::PPPoESessionLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
440
19.3k
    {
441
19.3k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
19.1k
      {
443
19.1k
        return m_NextLayer;
444
19.1k
      }
445
446
197
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
19.3k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::PPPoEDiscoveryLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
440
1.09k
    {
441
1.09k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
1.02k
      {
443
1.02k
        return m_NextLayer;
444
1.02k
      }
445
446
69
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
1.09k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::CotpLayer, 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
9.59k
      {
443
9.59k
        return m_NextLayer;
444
9.59k
      }
445
446
1.35k
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
10.9k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::LLCLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
440
16.6k
    {
441
16.6k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
15.5k
      {
443
15.5k
        return m_NextLayer;
444
15.5k
      }
445
446
1.17k
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
16.6k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::S7CommLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
440
7.64k
    {
441
7.64k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
6.28k
      {
443
6.28k
        return m_NextLayer;
444
6.28k
      }
445
446
1.36k
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
7.64k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::ArpLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
440
20.0k
    {
441
20.0k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
19.9k
      {
443
19.9k
        return m_NextLayer;
444
19.9k
      }
445
446
75
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
20.0k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::VlanLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
440
52.9k
    {
441
52.9k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
52.8k
      {
443
52.8k
        return m_NextLayer;
444
52.8k
      }
445
446
75
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
52.9k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::MplsLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
440
44.3k
    {
441
44.3k
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
44.2k
      {
443
44.2k
        return m_NextLayer;
444
44.2k
      }
445
446
3
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
44.3k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerWithFallback<pcpp::WakeOnLanLayer, pcpp::PayloadLayer>(unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
440
603
    {
441
603
      if (tryConstructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...))
442
21
      {
443
21
        return m_NextLayer;
444
21
      }
445
446
582
      return constructNextLayer<TFallback>(data, dataLen, packet);
447
603
    }
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
188k
    {
474
      // Note that the fallback is first to allow template argument deduction of the factory type.
475
188k
      return tryConstructNextLayerFromFactoryWithFallback<TFallback, TFactory>(
476
188k
          factoryFn, data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
477
188k
    }
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
34.6k
    {
474
      // Note that the fallback is first to allow template argument deduction of the factory type.
475
34.6k
      return tryConstructNextLayerFromFactoryWithFallback<TFallback, TFactory>(
476
34.6k
          factoryFn, data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
477
34.6k
    }
Unexecuted instantiation: pcpp::Layer* pcpp::Layer::tryConstructNextLayerFromFactoryWithFallback<pcpp::PayloadLayer, pcpp::DoIpLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*)>(pcpp::DoIpLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*), unsigned char*, unsigned long)
pcpp::Layer* pcpp::Layer::tryConstructNextLayerFromFactoryWithFallback<pcpp::PayloadLayer, pcpp::LdapLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*)>(pcpp::LdapLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*), unsigned char*, unsigned long)
Line
Count
Source
473
10.2k
    {
474
      // Note that the fallback is first to allow template argument deduction of the factory type.
475
10.2k
      return tryConstructNextLayerFromFactoryWithFallback<TFallback, TFactory>(
476
10.2k
          factoryFn, data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
477
10.2k
    }
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
36.5k
    {
474
      // Note that the fallback is first to allow template argument deduction of the factory type.
475
36.5k
      return tryConstructNextLayerFromFactoryWithFallback<TFallback, TFactory>(
476
36.5k
          factoryFn, data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
477
36.5k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerFromFactoryWithFallback<pcpp::PayloadLayer, pcpp::WireGuardLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*)>(pcpp::WireGuardLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*), unsigned char*, unsigned long)
Line
Count
Source
473
2.39k
    {
474
      // Note that the fallback is first to allow template argument deduction of the factory type.
475
2.39k
      return tryConstructNextLayerFromFactoryWithFallback<TFallback, TFactory>(
476
2.39k
          factoryFn, data, dataLen, getAttachedPacket(), std::forward<Args>(extraArgs)...);
477
2.39k
    }
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
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
    }
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
188k
    {
503
188k
      auto nextLayer = constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, packet,
504
188k
                                                               std::forward<Args>(extraArgs)...);
505
188k
      if (nextLayer != nullptr)
506
65.0k
      {
507
65.0k
        return nextLayer;
508
65.0k
      }
509
510
      // factory failed, construct fallback layer
511
123k
      return constructNextLayer<TFallback>(data, dataLen, packet);
512
188k
    }
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
34.6k
    {
503
34.6k
      auto nextLayer = constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, packet,
504
34.6k
                                                               std::forward<Args>(extraArgs)...);
505
34.6k
      if (nextLayer != nullptr)
506
32.4k
      {
507
32.4k
        return nextLayer;
508
32.4k
      }
509
510
      // factory failed, construct fallback layer
511
2.20k
      return constructNextLayer<TFallback>(data, dataLen, packet);
512
34.6k
    }
Unexecuted instantiation: pcpp::Layer* pcpp::Layer::tryConstructNextLayerFromFactoryWithFallback<pcpp::PayloadLayer, pcpp::DoIpLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*)>(pcpp::DoIpLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*), unsigned char*, unsigned long, pcpp::Packet*)
pcpp::Layer* pcpp::Layer::tryConstructNextLayerFromFactoryWithFallback<pcpp::PayloadLayer, pcpp::LdapLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*)>(pcpp::LdapLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*), unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
502
10.2k
    {
503
10.2k
      auto nextLayer = constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, packet,
504
10.2k
                                                               std::forward<Args>(extraArgs)...);
505
10.2k
      if (nextLayer != nullptr)
506
903
      {
507
903
        return nextLayer;
508
903
      }
509
510
      // factory failed, construct fallback layer
511
9.34k
      return constructNextLayer<TFallback>(data, dataLen, packet);
512
10.2k
    }
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
36.5k
    {
503
36.5k
      auto nextLayer = constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, packet,
504
36.5k
                                                               std::forward<Args>(extraArgs)...);
505
36.5k
      if (nextLayer != nullptr)
506
23.7k
      {
507
23.7k
        return nextLayer;
508
23.7k
      }
509
510
      // factory failed, construct fallback layer
511
12.8k
      return constructNextLayer<TFallback>(data, dataLen, packet);
512
36.5k
    }
pcpp::Layer* pcpp::Layer::tryConstructNextLayerFromFactoryWithFallback<pcpp::PayloadLayer, pcpp::WireGuardLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*)>(pcpp::WireGuardLayer* (*)(unsigned char*, unsigned long, pcpp::Layer*, pcpp::Packet*), unsigned char*, unsigned long, pcpp::Packet*)
Line
Count
Source
502
2.39k
    {
503
2.39k
      auto nextLayer = constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, packet,
504
2.39k
                                                               std::forward<Args>(extraArgs)...);
505
2.39k
      if (nextLayer != nullptr)
506
2.39k
      {
507
2.39k
        return nextLayer;
508
2.39k
      }
509
510
      // factory failed, construct fallback layer
511
0
      return constructNextLayer<TFallback>(data, dataLen, packet);
512
2.39k
    }
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
104k
    {
503
104k
      auto nextLayer = constructNextLayerFromFactory<TFactory>(factoryFn, data, dataLen, packet,
504
104k
                                                               std::forward<Args>(extraArgs)...);
505
104k
      if (nextLayer != nullptr)
506
5.50k
      {
507
5.50k
        return nextLayer;
508
5.50k
      }
509
510
      // factory failed, construct fallback layer
511
98.9k
      return constructNextLayer<TFallback>(data, dataLen, packet);
512
104k
    }
513
514
    /// @brief Check if the data is large enough to reinterpret as a type
515
    ///
516
    /// The data must be non-null and at least as large as the type
517
    ///
518
    /// @tparam T The type to reinterpret as
519
    /// @param data The data to check
520
    /// @param dataLen The length of the data
521
    /// @return True if the data is large enough to reinterpret as T, false otherwise
522
    template <typename T> static bool canReinterpretAs(const uint8_t* data, size_t dataLen)
523
1.66M
    {
524
1.66M
      return data != nullptr && dataLen >= sizeof(T);
525
1.66M
    }
bool pcpp::Layer::canReinterpretAs<pcpp::arphdr>(unsigned char const*, unsigned long)
Line
Count
Source
523
20.0k
    {
524
20.0k
      return data != nullptr && dataLen >= sizeof(T);
525
20.0k
    }
bool pcpp::Layer::canReinterpretAs<pcpp::iphdr>(unsigned char const*, unsigned long)
Line
Count
Source
523
1.02M
    {
524
1.02M
      return data != nullptr && dataLen >= sizeof(T);
525
1.02M
    }
bool pcpp::Layer::canReinterpretAs<pcpp::vrrp_header>(unsigned char const*, unsigned long)
Line
Count
Source
523
7.36k
    {
524
7.36k
      return data != nullptr && dataLen >= sizeof(T);
525
7.36k
    }
bool pcpp::Layer::canReinterpretAs<pcpp::ip6_hdr>(unsigned char const*, unsigned long)
Line
Count
Source
523
251k
    {
524
251k
      return data != nullptr && dataLen >= sizeof(T);
525
251k
    }
bool pcpp::Layer::canReinterpretAs<pcpp::vlan_header>(unsigned char const*, unsigned long)
Line
Count
Source
523
52.9k
    {
524
52.9k
      return data != nullptr && dataLen >= sizeof(T);
525
52.9k
    }
bool pcpp::Layer::canReinterpretAs<pcpp::MplsLayer::mpls_header>(unsigned char const*, unsigned long)
Line
Count
Source
523
44.3k
    {
524
44.3k
      return data != nullptr && dataLen >= sizeof(T);
525
44.3k
    }
bool pcpp::Layer::canReinterpretAs<pcpp::igmp_header>(unsigned char const*, unsigned long)
Line
Count
Source
523
6.10k
    {
524
6.10k
      return data != nullptr && dataLen >= sizeof(T);
525
6.10k
    }
bool pcpp::Layer::canReinterpretAs<pcpp::igmpv3_query_header>(unsigned char const*, unsigned long)
Line
Count
Source
523
187
    {
524
187
      return data != nullptr && dataLen >= sizeof(T);
525
187
    }
bool pcpp::Layer::canReinterpretAs<pcpp::igmpv3_report_header>(unsigned char const*, unsigned long)
Line
Count
Source
523
1.67k
    {
524
1.67k
      return data != nullptr && dataLen >= sizeof(T);
525
1.67k
    }
bool pcpp::Layer::canReinterpretAs<pcpp::tpkthdr>(unsigned char const*, unsigned long)
Line
Count
Source
523
249k
    {
524
249k
      return data != nullptr && dataLen >= sizeof(T);
525
249k
    }
bool pcpp::Layer::canReinterpretAs<pcpp::stp_tcn_bpdu>(unsigned char const*, unsigned long)
Line
Count
Source
523
2.35k
    {
524
2.35k
      return data != nullptr && dataLen >= sizeof(T);
525
2.35k
    }
bool pcpp::Layer::canReinterpretAs<pcpp::stp_conf_bpdu>(unsigned char const*, unsigned long)
Line
Count
Source
523
2.65k
    {
524
2.65k
      return data != nullptr && dataLen >= sizeof(T);
525
2.65k
    }
bool pcpp::Layer::canReinterpretAs<pcpp::rstp_conf_bpdu>(unsigned char const*, unsigned long)
Line
Count
Source
523
1.52k
    {
524
1.52k
      return data != nullptr && dataLen >= sizeof(T);
525
1.52k
    }
bool pcpp::Layer::canReinterpretAs<pcpp::mstp_conf_bpdu>(unsigned char const*, unsigned long)
Line
Count
Source
523
192
    {
524
192
      return data != nullptr && dataLen >= sizeof(T);
525
192
    }
526
  };
527
528
  inline std::ostream& operator<<(std::ostream& os, const pcpp::Layer& layer)
529
0
  {
530
0
    os << layer.toString();
531
0
    return os;
532
0
  }
533
}  // namespace pcpp