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

Set EthernetII payload type to UNKNOWN if no inner_pdu

This commit is contained in:
Matias Fontanini
2016-09-27 07:47:32 -07:00
parent f0b32edaa9
commit 552006c876
2 changed files with 17 additions and 9 deletions

View File

@@ -179,6 +179,9 @@ void EthernetII::write_serialization(uint8_t* buffer, uint32_t total_sz, const P
payload_type(static_cast<uint16_t>(flag));
}
}
else {
payload_type(Constants::Ethernet::UNKNOWN);
}
stream.write(header_);
const uint32_t trailer = trailer_size();
if (trailer) {

View File

@@ -116,14 +116,6 @@ TEST_F(EthernetIITest, CompleteConstructor) {
EXPECT_EQ(eth.payload_type(), 0);
}
TEST_F(EthernetIITest, Serialize) {
EthernetII eth(dst_addr, src_addr);
eth.payload_type(p_type);
PDU::serialization_type serialized = eth.serialize();
ASSERT_EQ(serialized.size(), sizeof(expected_packet));
EXPECT_TRUE(std::equal(serialized.begin(), serialized.end(), expected_packet));
}
TEST_F(EthernetIITest, SerializeSmallEthernetWithPadding) {
EthernetII eth(smallip_packet, sizeof(smallip_packet));
ASSERT_TRUE(eth.inner_pdu() != NULL);
@@ -168,3 +160,16 @@ TEST_F(EthernetIITest, SerializePreservesGivenPayloadType) {
eth.serialize();
EXPECT_EQ(p_type, eth.payload_type());
}
// Issue #168
TEST_F(EthernetIITest, SerializeWhenInnerPDUIsGone) {
EthernetII eth1 = EthernetII() / IP();
eth1.serialize(); // sets payload type
eth1.inner_pdu(NULL); // make it "incomplete"
PDU::serialization_type buffer = eth1.serialize();
EXPECT_EQ(eth1.size(), buffer.size());
EthernetII eth2(&buffer[0], buffer.size());
EXPECT_EQ(eth1.size(), eth2.size());
}