From 8d08f8dd79ac12874ba0da6b26973f5a33163131 Mon Sep 17 00:00:00 2001 From: Mauro Sardara Date: Thu, 4 Feb 2021 12:20:30 +0100 Subject: [HICN-679] Do not throw exception when receiving corrupted/not-hicn packet from network layer Signed-off-by: Mauro Sardara Change-Id: I082e3c1b5fc9f535089114cfe14940f094947b66 Signed-off-by: Mauro Sardara --- libtransport/includes/hicn/transport/core/packet.h | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'libtransport/includes/hicn/transport/core/packet.h') diff --git a/libtransport/includes/hicn/transport/core/packet.h b/libtransport/includes/hicn/transport/core/packet.h index 2efd7439d..91f957964 100644 --- a/libtransport/includes/hicn/transport/core/packet.h +++ b/libtransport/includes/hicn/transport/core/packet.h @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -97,13 +98,16 @@ class Packet : public std::enable_shared_from_this { static bool isInterest(const uint8_t *buffer); - static Format getFormatFromBuffer(const uint8_t *buffer) { + static Format getFormatFromBuffer(const uint8_t *buffer, std::size_t length) { Format format = HF_UNSPEC; if (TRANSPORT_EXPECT_FALSE( hicn_packet_get_format((const hicn_header_t *)buffer, &format) < 0)) { - throw errors::MalformedPacketException(); + TRANSPORT_LOGE( + "Error while getting format from packet buffer. Packet will be " + "discarded."); + hicn_packet_dump(buffer, length); } return format; @@ -114,7 +118,8 @@ class Packet : public std::enable_shared_from_this { packet_start_ = reinterpret_cast(packet_->writableData()); header_head_ = packet_.get(); payload_head_ = nullptr; - format_ = getFormatFromBuffer(reinterpret_cast(packet_start_)); + format_ = getFormatFromBuffer(reinterpret_cast(packet_start_), + packet_->length()); name_.clear(); } -- cgit 1.2.3-korg