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

Fixed bug on IP when serializing fragmented packets.

The original protocol id was being overwritten with 0xff(unknown)
when the inner_pdu was a RawPDU, even if it was just a fragment of
a transport layer PDU. The protocol id is now kept if the packet
is fragmented.
This commit is contained in:
Matias Fontanini
2013-12-04 10:56:48 -03:00
parent 83dc8819b6
commit 2ddec368c3
3 changed files with 34 additions and 3 deletions

View File

@@ -8,13 +8,14 @@
#include "icmp.h"
#include "ip_address.h"
#include "utils.h"
#include "ethernetII.h"
using namespace std;
using namespace Tins;
class IPTest : public testing::Test {
public:
static const uint8_t expected_packet[], fragmented_packet[];
static const uint8_t expected_packet[], fragmented_packet[], fragmented_ether_ip_packet[];
void test_equals(const IP &ip1, const IP &ip2);
};
@@ -30,6 +31,13 @@ const uint8_t IPTest::fragmented_packet[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
const uint8_t IPTest::fragmented_ether_ip_packet[] = {
0, 10, 94, 83, 216, 229, 0, 21, 197, 50, 245, 6, 8, 0, 69, 0, 0, 60,
0, 242, 7, 223, 64, 17, 237, 220, 192, 0, 2, 1, 192, 0, 2, 2, 192, 0,
192, 0, 0, 40, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
TEST_F(IPTest, DefaultConstructor) {
IP ip;
@@ -75,6 +83,18 @@ TEST_F(IPTest, ConstructorFromFragmentedPacket) {
EXPECT_EQ(PDU::RAW, ip.inner_pdu()->pdu_type());
}
TEST_F(IPTest, SerializeFragmentedPacket) {
EthernetII pkt(fragmented_ether_ip_packet, sizeof(fragmented_ether_ip_packet));
PDU::serialization_type buffer = pkt.serialize();
EXPECT_EQ(
PDU::serialization_type(
fragmented_ether_ip_packet,
fragmented_ether_ip_packet + sizeof(fragmented_ether_ip_packet)
),
buffer
);
}
TEST_F(IPTest, TOS) {
IP ip;
ip.tos(0x7a);