From 8dcfd6aae092c5b593662ba026cbb289b23a27ed Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Thu, 29 Sep 2016 07:24:44 -0700 Subject: [PATCH] Set protocol to 0 if no inner_pdu on IP --- src/ip.cpp | 3 +++ tests/src/ip.cpp | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/src/ip.cpp b/src/ip.cpp index 1df5127..d600617 100644 --- a/src/ip.cpp +++ b/src/ip.cpp @@ -439,6 +439,9 @@ void IP::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* pare protocol(new_flag); } } + else { + protocol(0); + } uint16_t original_frag_off = header_.frag_off; diff --git a/tests/src/ip.cpp b/tests/src/ip.cpp index 701688a..e2d6b8e 100644 --- a/tests/src/ip.cpp +++ b/tests/src/ip.cpp @@ -845,3 +845,13 @@ TEST_F(IPTest, SerializePacketHavingICMPExtensionsWithoutLengthAndShortPayload) ASSERT_EQ(1UL, serialized.rfind_pdu().extensions().extensions().size()); EXPECT_EQ(ext_payload, serialized.rfind_pdu().extensions().extensions().begin()->payload()); } + +TEST_F(IPTest, SerializeAfterInnerPduRemoved) { + EthernetII eth1 = EthernetII() / IP() / TCP(); + eth1.serialize(); + eth1.rfind_pdu().inner_pdu(0); + + PDU::serialization_type buffer = eth1.serialize(); + EthernetII eth2(&buffer[0], buffer.size()); + EXPECT_EQ(eth1.size(), eth2.size()); +}