Exemple #1
0
TEST_F(TCPTest, ConstructorFromBuffer) {
    TCP tcp1(expected_packet, sizeof(expected_packet));
    
    EXPECT_EQ(tcp1.dport(), 0x4f1d);
    EXPECT_EQ(tcp1.sport(), 0x7f4d);
    EXPECT_EQ(tcp1.seq(), 0xf1dae546);
    EXPECT_EQ(tcp1.ack_seq(), 0x5faed123U);
    EXPECT_EQ(tcp1.window(), 0x71da);
    EXPECT_EQ(tcp1.urg_ptr(), 0x1fae);
    EXPECT_EQ(tcp1.data_offset(), 0xd);
    
    EXPECT_EQ(tcp1.timestamp(), (std::pair<uint32_t, uint32_t>(0x4fd23acb, 0x89fe1234)));
    
    EXPECT_TRUE(tcp1.has_sack_permitted());
    
    EXPECT_EQ(tcp1.winscale(), 0x7a);
    
    EXPECT_EQ(tcp1.mss(), 0x98fa);
    
    TCP::sack_type edges = tcp1.sack();
    TCP::sack_type::const_iterator iter = edges.begin();
    ASSERT_EQ(edges.size(), 2U);
    EXPECT_EQ(*iter++, 0x00010203U);
    EXPECT_EQ(*iter++, 0x04050607U); 
    
    PDU::serialization_type buffer = tcp1.serialize();
    
    TCP tcp2(&buffer[0], buffer.size());
    test_equals(tcp1, tcp2);
}
Exemple #2
0
TEST_F(TCPTest, Sack) {
    TCP tcp;
    TCP::sack_type edges;
    edges.push_back(0x13);
    edges.push_back(0x63fa1d7a);
    edges.push_back(0xff1c);
    tcp.sack(edges);
    ASSERT_EQ(edges, tcp.sack());
}
int main(int argc, char *argv[]) {
    int packet_count, packet_size, test_case;
    if(argc != 5) {
        std::cout << "Usage: " << *argv << " <output_file> <test_case> <num_packets> <payload_size>" << std::endl;
        return 1;
    }
    else {
        test_case = atoi(argv[2]);
        packet_count = atoi(argv[3]);
        packet_size = atoi(argv[4]);
    }
    assert(packet_count > 0);
    assert(packet_size >= 0);
    PacketWriter writer(argv[1], PacketWriter::ETH2);
    EthernetII packet;
    
    if(test_case == 1 || test_case == 2) {
        packet = EthernetII() / IP() / TCP() / RawPDU(std::string(packet_size, 'A'));
        if(test_case == 2) {
            TCP::sack_type sack;
            sack.push_back(1234);
            sack.push_back(5678);
            sack.push_back(91011);
            TCP *tcp = packet.find_pdu<TCP>();
            tcp->mss(1234); 
            tcp->winscale(123);
            tcp->sack_permitted();
            tcp->sack(sack);
            tcp->timestamp(1, 2);
            tcp->altchecksum(TCP::CHK_TCP);
        }
    }
    else if(test_case == 3) {
        const uint8_t dns_data[] = {
            98, 243, 129, 128, 0, 1, 0, 1, 0, 0, 0, 0, 6, 103, 111, 111, 
            103, 108, 101, 3, 99, 111, 109, 0, 0, 2, 0, 1, 192, 12, 0, 2, 
            0, 1, 0, 0, 84, 96, 0, 6, 3, 110, 115, 52, 192, 12
        };
        
        packet = EthernetII() / IP() / UDP(52, 53) / DNS(dns_data, sizeof(dns_data));
    }
    dump_to_file(writer, packet_count, packet);
}