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
 void send_packets(PacketSender& sender) {
     // ICMPs are icmp-requests by default
     IP ip = IP(addr, iface.addresses().ip_addr) / ICMP();
     ICMP& icmp = ip.rfind_pdu<ICMP>();
     icmp.sequence(sequence);
     // We'll find at most 20 hops.
     
     for (auto i = 1; i <= 20; ++i) {
         // Set this ICMP id
         icmp.id(i);
         // Set the time-to-live option
         ip.ttl(i);
         
         // Critical section
         {
             lock_guard<mutex> _(lock);
             ttls[i] = i;
         }
         
         sender.send(ip);
         // Give it a little time
         sleep_for(milliseconds(100));
     }
     running = false;
     sender.send(ip);
 }
Beispiel #3
0
 void send_packets(PacketSender &sender) {
     // ICMPs are icmp-requests by default
     IP ip = IP(addr, iface.addresses().ip_addr) / ICMP();
     // We'll find at most 10 hops.
     
     for(auto i = 1; i <= 10; ++i) {
         // Set this "unique" id
         ip.id(i);
         // Set the time-to-live option
         ip.ttl(i);
         
         // Critical section
         {
             std::lock_guard<std::mutex> _(lock);
             ttls[i] = i;
         }
         
         sender.send(ip);
         // Give him a little time
         std::this_thread::sleep_for(std::chrono::milliseconds(100));
     }
     running = false;
     sender.send(ip);
 }
Beispiel #4
0
TEST_F(IPTest, TTL) {
    IP ip;
    ip.ttl(0x7f);
    EXPECT_EQ(ip.ttl(), 0x7f);
}