From 35d5045db4292468d4ba6ac2b67b3e0d0dbf183d Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Fri, 27 Nov 2015 20:30:46 -0800 Subject: [PATCH] Don't set Ethernet type if inner PDU type is unknown Fixes #116 --- src/ethernetII.cpp | 4 +++- tests/src/ethernetII.cpp | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/ethernetII.cpp b/src/ethernetII.cpp index 99721ab..5f824f4 100644 --- a/src/ethernetII.cpp +++ b/src/ethernetII.cpp @@ -161,7 +161,9 @@ void EthernetII::write_serialization(uint8_t *buffer, uint32_t total_sz, const P Constants::Ethernet::e flag = Internals::pdu_flag_to_ether_type( inner_pdu()->pdu_type() ); - payload_type(static_cast(flag)); + if (flag != Constants::Ethernet::UNKNOWN) { + payload_type(static_cast(flag)); + } } memcpy(buffer, &_eth, sizeof(ethhdr)); uint32_t trailer = trailer_size(); diff --git a/tests/src/ethernetII.cpp b/tests/src/ethernetII.cpp index c67d367..56bd3f8 100644 --- a/tests/src/ethernetII.cpp +++ b/tests/src/ethernetII.cpp @@ -158,3 +158,13 @@ TEST_F(EthernetIITest, EliminateEthernetPadding) { ASSERT_TRUE(eth.find_pdu() != NULL); ASSERT_FALSE(eth.find_pdu() != NULL); } + +TEST_F(EthernetIITest, SerializePreservesGivenPayloadType) { + EthernetII eth; + uint32_t payload_size = 100; + uint8_t payload[100] = {0}; + eth /= RawPDU(payload, payload_size); + eth.payload_type(p_type); + eth.serialize(); + EXPECT_EQ(p_type, eth.payload_type()); +} \ No newline at end of file