diff --git a/src/ethernetII.cpp b/src/ethernetII.cpp index 0f46ed9..5d28f79 100644 --- a/src/ethernetII.cpp +++ b/src/ethernetII.cpp @@ -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); } } diff --git a/src/ip.cpp b/src/ip.cpp index 10dc611..e0acf09 100644 --- a/src/ip.cpp +++ b/src/ip.cpp @@ -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) { diff --git a/tests/src/ethernetII.cpp b/tests/src/ethernetII.cpp index 3cfb5c4..64b736b 100644 --- a/tests/src/ethernetII.cpp +++ b/tests/src/ethernetII.cpp @@ -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()); - ASSERT_TRUE(eth.find_pdu()); - ASSERT_FALSE(eth.find_pdu()); + EthernetII eth(smallip_packet, sizeof(smallip_packet)); + ASSERT_TRUE(eth.inner_pdu()); + ASSERT_TRUE(eth.find_pdu()); + ASSERT_TRUE(eth.find_pdu()); + ASSERT_FALSE(eth.find_pdu()); } diff --git a/tests/src/pppoe.cpp b/tests/src/pppoe.cpp index 4aaa429..83095fd 100644 --- a/tests/src/pppoe.cpp +++ b/tests/src/pppoe.cpp @@ -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(); 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() ); }