1
0
mirror of https://github.com/mfontanini/libtins synced 2026-01-23 02:35:57 +01:00

Don't set Ethernet type if inner PDU type is unknown

Fixes #116
This commit is contained in:
Matias Fontanini
2015-11-27 20:30:46 -08:00
parent 65b7919ebf
commit 35d5045db4
2 changed files with 13 additions and 1 deletions

View File

@@ -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<uint16_t>(flag));
if (flag != Constants::Ethernet::UNKNOWN) {
payload_type(static_cast<uint16_t>(flag));
}
}
memcpy(buffer, &_eth, sizeof(ethhdr));
uint32_t trailer = trailer_size();

View File

@@ -158,3 +158,13 @@ TEST_F(EthernetIITest, EliminateEthernetPadding) {
ASSERT_TRUE(eth.find_pdu<TCP>() != NULL);
ASSERT_FALSE(eth.find_pdu<RawPDU>() != 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());
}