@@ -301,6 +301,47 @@ namespace pcpp
301301 return newLayer;
302302 }
303303
304+ // / Try to construct the next layer in the protocol stack.
305+ // /
306+ // / This overload infers the Packet from the current layer.
307+ // /
308+ // / The method checks if the data is valid for the layer type T before constructing it by calling
309+ // / T::isDataValid(data, dataLen). If the data is invalid, no layer is constructed and a nullptr is returned.
310+ // /
311+ // / @tparam T The type of the layer to construct
312+ // / @tparam Args The types of the extra arguments to pass to the layer constructor
313+ // / @param[in] data The data to construct the layer from
314+ // / @param[in] dataLen The length of the data
315+ // / @param[in] extraArgs Extra arguments to be forwarded to the layer constructor
316+ // / @return The constructed layer or nullptr if the data is invalid
317+ template <typename T, typename ... Args>
318+ Layer* tryConstructNextLayer (uint8_t * data, size_t dataLen, Args&&... extraArgs)
319+ {
320+ return tryConstructNextLayer<T>(data, dataLen, getAttachedPacket (), std::forward<Args>(extraArgs)...);
321+ }
322+
323+ // / Try to construct the next layer in the protocol stack.
324+ // /
325+ // / The method checks if the data is valid for the layer type T before constructing it by calling
326+ // / T::isDataValid(data, dataLen). If the data is invalid, no layer is constructed and a nullptr is returned.
327+ // /
328+ // / @tparam T The type of the layer to construct
329+ // / @tparam Args The types of the extra arguments to pass to the layer constructor
330+ // / @param[in] data The data to construct the layer from
331+ // / @param[in] dataLen The length of the data
332+ // / @param[in] packet The packet the layer belongs to
333+ // / @param[in] extraArgs Extra arguments to be forwarded to the layer constructor
334+ // / @return The constructed layer or nullptr if the data is invalid
335+ template <typename T, typename ... Args>
336+ Layer* tryConstructNextLayer (uint8_t * data, size_t dataLen, Packet* packet, Args&&... extraArgs)
337+ {
338+ if (T::isDataValid (data, dataLen))
339+ {
340+ return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
341+ }
342+ return nullptr ;
343+ }
344+
304345 // / @brief Try to construct the next layer in the protocol stack with a fallback option.
305346 // /
306347 // / This overload infers the Packet from the current layer.
@@ -358,29 +399,6 @@ namespace pcpp
358399 {
359400 return data != nullptr && dataLen >= sizeof (T);
360401 }
361-
362- private:
363- // / Try to construct the next layer in the protocol stack.
364- // /
365- // / The method checks if the data is valid for the layer type T before constructing it by calling
366- // / T::isDataValid(data, dataLen). If the data is invalid, a nullptr is returned.
367- // /
368- // / @tparam T The type of the layer to construct
369- // / @tparam Args The types of the extra arguments to pass to the layer constructor
370- // / @param[in] data The data to construct the layer from
371- // / @param[in] dataLen The length of the data
372- // / @param[in] packet The packet the layer belongs to
373- // / @param[in] extraArgs Extra arguments to be forwarded to the layer constructor
374- // / @return The constructed layer or nullptr if the data is invalid
375- template <typename T, typename ... Args>
376- Layer* tryConstructNextLayer (uint8_t * data, size_t dataLen, Packet* packet, Args&&... extraArgs)
377- {
378- if (T::isDataValid (data, dataLen))
379- {
380- return constructNextLayer<T>(data, dataLen, packet, std::forward<Args>(extraArgs)...);
381- }
382- return nullptr ;
383- }
384402 };
385403
386404 inline std::ostream& operator <<(std::ostream& os, const pcpp::Layer& layer)
0 commit comments