Beispiel #1
0
void IPTest::test_equals(const IP &ip1, const IP &ip2) {
    EXPECT_EQ(ip1.dst_addr(), ip2.dst_addr());
    EXPECT_EQ(ip1.src_addr(), ip2.src_addr());
    EXPECT_EQ(ip1.id(), ip2.id());
    EXPECT_EQ(ip1.frag_off(), ip2.frag_off());
    EXPECT_EQ(ip1.tos(), ip2.tos());
    EXPECT_EQ(ip1.ttl(), ip2.ttl());
    EXPECT_EQ(ip1.version(), ip2.version());
    EXPECT_EQ((bool)ip1.inner_pdu(), (bool)ip2.inner_pdu());
}
Beispiel #2
0
IPv4Reassembler::packet_status IPv4Reassembler::process(PDU &pdu) {
    IP *ip = pdu.find_pdu<IP>();
    if(ip && ip->inner_pdu()) {
        // There's fragmentation
        if(ip->is_fragmented()) {
            // Create it or look it up, it's the same
            Internals::IPv4Stream &stream = streams[make_key(ip)];
            stream.add_fragment(ip);
            if(stream.is_complete()) {
                PDU *pdu = stream.allocate_pdu();
                // The packet is corrupt
                if(!pdu)  {
                    streams.erase(make_key(ip));
                    return FRAGMENTED;
                }
                ip->inner_pdu(pdu);
                ip->frag_off(0);
                return REASSEMBLED;
            }
            else
                return FRAGMENTED;
        }
    }
    return NOT_FRAGMENTED;
}
Beispiel #3
0
TEST_F(IPTest, FragOffset) {
    IP ip;
    ip.frag_off(0x7f1a);
    EXPECT_EQ(ip.frag_off(), 0x7f1a);
}