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

Protocols now always set the next layer protocol flag.

This commit is contained in:
Matias Fontanini
2014-08-07 20:42:17 -03:00
parent 1b47623484
commit 8a44b29d92
3 changed files with 12 additions and 21 deletions

View File

@@ -103,7 +103,7 @@ void Dot1Q::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *)
#ifdef TINS_DEBUG
assert(total_sz >= sizeof(_header) + trailer);
#endif
if ((payload_type() == 0) && inner_pdu()) {
if (inner_pdu()) {
Constants::Ethernet::e flag = Internals::pdu_flag_to_ether_type(
inner_pdu()->pdu_type()
);

View File

@@ -97,22 +97,13 @@ void Tins::SNAP::write_serialization(uint8_t *buffer, uint32_t total_sz, const P
#ifdef TINS_DEBUG
assert(total_sz >= sizeof(_snap));
#endif
if (!_snap.eth_type && inner_pdu()) {
uint16_t type = Tins::Constants::Ethernet::IP;
switch (inner_pdu()->pdu_type()) {
case PDU::IP:
type = Tins::Constants::Ethernet::IP;
break;
case PDU::ARP:
type = Tins::Constants::Ethernet::ARP;
break;
case PDU::EAPOL:
type = Tins::Constants::Ethernet::EAPOL;
break;
default:
type = 0;
}
_snap.eth_type = Endian::host_to_be(type);
if (inner_pdu()) {
Constants::Ethernet::e flag = Internals::pdu_flag_to_ether_type(
inner_pdu()->pdu_type()
);
_snap.eth_type = Endian::host_to_be(
static_cast<uint16_t>(flag)
);
}
std::memcpy(buffer, &_snap, sizeof(_snap));
}

View File

@@ -85,13 +85,13 @@ TEST_F(AllocatorsTest, LinkLayerPDUs) {
EXPECT_EQ(pkt.serialize(), link_layer_data);
}
{
SLL pkt(&link_layer_data[0], link_layer_data.size());
EXPECT_TRUE(pkt.find_pdu<DummyPDU<3> >());
Dot1Q pkt(&link_layer_data[0], link_layer_data.size());
EXPECT_TRUE(pkt.find_pdu<DummyPDU<2> >());
EXPECT_EQ(pkt.serialize(), link_layer_data);
}
{
Dot1Q pkt(&link_layer_data[0], link_layer_data.size());
EXPECT_TRUE(pkt.find_pdu<DummyPDU<2> >());
SLL pkt(&link_layer_data[0], link_layer_data.size());
EXPECT_TRUE(pkt.find_pdu<DummyPDU<3> >());
EXPECT_EQ(pkt.serialize(), link_layer_data);
}
}