mirror of
https://github.com/mfontanini/libtins
synced 2026-01-29 04:54:28 +01:00
Replaced tabs for spaces in the previous commit
This commit is contained in:
@@ -103,12 +103,12 @@ uint32_t EthernetII::header_size() const {
|
||||
}
|
||||
|
||||
uint32_t EthernetII::trailer_size() const {
|
||||
int32_t padding = 60 - sizeof(ethhdr); // EthernetII min size is 60, padding is sometimes needed
|
||||
if (inner_pdu()) {
|
||||
padding -= inner_pdu()->size();
|
||||
padding = std::max(0, padding);
|
||||
}
|
||||
return padding;
|
||||
int32_t padding = 60 - sizeof(ethhdr); // EthernetII min size is 60, padding is sometimes needed
|
||||
if (inner_pdu()) {
|
||||
padding -= inner_pdu()->size();
|
||||
padding = std::max(0, padding);
|
||||
}
|
||||
return padding;
|
||||
}
|
||||
|
||||
#ifndef WIN32
|
||||
@@ -164,10 +164,10 @@ void EthernetII::write_serialization(uint8_t *buffer, uint32_t total_sz, const P
|
||||
memcpy(buffer, &_eth, sizeof(ethhdr));
|
||||
uint32_t trailer = trailer_size();
|
||||
if (trailer) {
|
||||
uint32_t trailer_offset = header_size();
|
||||
if (inner_pdu())
|
||||
trailer_offset += inner_pdu()->size();
|
||||
memset(buffer + trailer_offset, 0, trailer);
|
||||
uint32_t trailer_offset = header_size();
|
||||
if (inner_pdu())
|
||||
trailer_offset += inner_pdu()->size();
|
||||
memset(buffer + trailer_offset, 0, trailer);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ IP::IP(const uint8_t *buffer, uint32_t total_sz)
|
||||
// check this line PLX
|
||||
total_sz = std::min(total_sz, (uint32_t)tot_len());
|
||||
if (total_sz < head_len() * sizeof(uint32_t))
|
||||
throw malformed_packet();
|
||||
throw malformed_packet();
|
||||
total_sz -= head_len() * sizeof(uint32_t);
|
||||
if (total_sz) {
|
||||
switch(_ip.protocol) {
|
||||
|
||||
@@ -39,10 +39,10 @@ EthernetIITest::ipv6_packet[] = {
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1
|
||||
},
|
||||
EthernetIITest::smallip_packet[] = {
|
||||
64, 97, 134, 43, 174, 3, 0, 36, 1, 254, 210, 68, 8, 0, 69, 0, 0, 40,
|
||||
53, 163, 64, 0, 127, 6, 44, 53, 192, 168, 1, 120, 173, 194, 42, 21,
|
||||
163, 42, 1, 187, 162, 113, 212, 162, 132, 15, 66, 219, 80, 16, 16,
|
||||
194, 34, 54, 0, 0, 0, 0, 0, 0, 0, 0
|
||||
64, 97, 134, 43, 174, 3, 0, 36, 1, 254, 210, 68, 8, 0, 69, 0, 0, 40,
|
||||
53, 163, 64, 0, 127, 6, 44, 53, 192, 168, 1, 120, 173, 194, 42, 21,
|
||||
163, 42, 1, 187, 162, 113, 212, 162, 132, 15, 66, 219, 80, 16, 16,
|
||||
194, 34, 54, 0, 0, 0, 0, 0, 0, 0, 0
|
||||
};
|
||||
|
||||
address_type EthernetIITest::src_addr("8a:8b:8c:8d:8e:8f");
|
||||
@@ -125,11 +125,11 @@ TEST_F(EthernetIITest, Serialize) {
|
||||
}
|
||||
|
||||
TEST_F(EthernetIITest, SerializeSmallEthernetWithPadding) {
|
||||
EthernetII eth(smallip_packet, sizeof(smallip_packet));
|
||||
ASSERT_TRUE(eth.inner_pdu());
|
||||
PDU::serialization_type serialized = eth.serialize();
|
||||
EXPECT_EQ(serialized.size(), sizeof(smallip_packet));
|
||||
EXPECT_TRUE(std::equal(serialized.begin(), serialized.end(), smallip_packet));
|
||||
EthernetII eth(smallip_packet, sizeof(smallip_packet));
|
||||
ASSERT_TRUE(eth.inner_pdu());
|
||||
PDU::serialization_type serialized = eth.serialize();
|
||||
EXPECT_EQ(serialized.size(), sizeof(smallip_packet));
|
||||
EXPECT_TRUE(std::equal(serialized.begin(), serialized.end(), smallip_packet));
|
||||
}
|
||||
|
||||
TEST_F(EthernetIITest, ConstructorFromBuffer) {
|
||||
@@ -152,9 +152,9 @@ TEST_F(EthernetIITest, ConstructorFromIPv6Buffer) {
|
||||
}
|
||||
|
||||
TEST_F(EthernetIITest, EliminateEthernetPadding) {
|
||||
EthernetII eth(smallip_packet, sizeof(smallip_packet));
|
||||
ASSERT_TRUE(eth.inner_pdu());
|
||||
ASSERT_TRUE(eth.find_pdu<IP>());
|
||||
ASSERT_TRUE(eth.find_pdu<TCP>());
|
||||
ASSERT_FALSE(eth.find_pdu<RawPDU>());
|
||||
EthernetII eth(smallip_packet, sizeof(smallip_packet));
|
||||
ASSERT_TRUE(eth.inner_pdu());
|
||||
ASSERT_TRUE(eth.find_pdu<IP>());
|
||||
ASSERT_TRUE(eth.find_pdu<TCP>());
|
||||
ASSERT_FALSE(eth.find_pdu<RawPDU>());
|
||||
}
|
||||
|
||||
@@ -48,14 +48,14 @@ TEST_F(PPPoETest, StackedOnEthernet) {
|
||||
|
||||
TEST_F(PPPoETest, StackedOnEthernetSerializationWithTags) {
|
||||
PPPoE pdu(expected_packet, sizeof(expected_packet));
|
||||
EthernetII eth = EthernetII() / pdu;
|
||||
EthernetII eth = EthernetII() / pdu;
|
||||
PDU::serialization_type buffer = eth.serialize();
|
||||
EthernetII eth2(&buffer[0], buffer.size());
|
||||
PPPoE* unserialized = eth2.find_pdu<PPPoE>();
|
||||
ASSERT_TRUE(unserialized);
|
||||
EXPECT_EQ(
|
||||
PPPoE::serialization_type(expected_packet, expected_packet + sizeof(expected_packet)),
|
||||
unserialized->serialize()
|
||||
PPPoE::serialization_type(expected_packet, expected_packet + sizeof(expected_packet)),
|
||||
unserialized->serialize()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user