From 24fdf496a84f3d84dfd58cd82d2bcd9213775575 Mon Sep 17 00:00:00 2001 From: Christian Herdtweck Date: Fri, 20 Mar 2015 09:38:19 +0100 Subject: [PATCH] fixed same bug as for DestinationUnreachable in TimeExceeded messages: accept reply from mid-way altered unit test accordingly removed unnecessary implementations of match_xy functions that also just return false --- src/icmp/icmpdata.cpp | 3 ++- src/icmp/icmpdata.h | 3 ++- src/icmp/icmpdestinationunreachabledata.cpp | 5 ----- src/icmp/icmpdestinationunreachabledata.h | 3 --- src/icmp/icmppacket.cpp | 5 +++-- src/icmp/icmptimeexceededdata.cpp | 15 ++++++--------- src/icmp/icmptimeexceededdata.h | 7 ++----- test/test_icmppacket.cpp | 2 +- 8 files changed, 16 insertions(+), 27 deletions(-) diff --git a/src/icmp/icmpdata.cpp b/src/icmp/icmpdata.cpp index 3e54173..791aa5d 100644 --- a/src/icmp/icmpdata.cpp +++ b/src/icmp/icmpdata.cpp @@ -56,7 +56,8 @@ bool IcmpData::match_destination_unreachable(const uint16_t identifier, { return false; } bool IcmpData::match_time_exceeded(const uint16_t identifier, - const uint16_t sequence_number) const + const uint16_t sequence_number, + const address &destination_address) const { return false; } std::size_t IcmpData::get_size() const diff --git a/src/icmp/icmpdata.h b/src/icmp/icmpdata.h index 3b25064..f428b3e 100644 --- a/src/icmp/icmpdata.h +++ b/src/icmp/icmpdata.h @@ -58,7 +58,8 @@ public: const address &destination_address) const; virtual bool match_time_exceeded(const uint16_t identifier, - const uint16_t sequence_number) const; + const uint16_t sequence_number, + const address &destination_address) const; // including 4 bytes from ICMPv4 header std::size_t get_size() const; diff --git a/src/icmp/icmpdestinationunreachabledata.cpp b/src/icmp/icmpdestinationunreachabledata.cpp index 825697e..bfb17f4 100644 --- a/src/icmp/icmpdestinationunreachabledata.cpp +++ b/src/icmp/icmpdestinationunreachabledata.cpp @@ -44,11 +44,6 @@ bool IcmpDestinationUnreachableData::match_destination_unreachable( == destination_address; } -bool IcmpDestinationUnreachableData::match_time_exceeded( - const uint16_t identifier, - const uint16_t sequence_number) const -{ return false; } - /** * @brief Prints the destination unreachable messages. * diff --git a/src/icmp/icmpdestinationunreachabledata.h b/src/icmp/icmpdestinationunreachabledata.h index 0f49fb3..4db1b34 100644 --- a/src/icmp/icmpdestinationunreachabledata.h +++ b/src/icmp/icmpdestinationunreachabledata.h @@ -48,9 +48,6 @@ public: const uint16_t sequence_number, const address &destination_address) const; - bool match_time_exceeded(const uint16_t identifier, - const uint16_t sequence_number) const; - /** * @brief Prints the destination unreachable messages. * diff --git a/src/icmp/icmppacket.cpp b/src/icmp/icmppacket.cpp index ab6e682..fe896b7 100644 --- a/src/icmp/icmppacket.cpp +++ b/src/icmp/icmppacket.cpp @@ -133,8 +133,9 @@ bool IcmpPacket::match_time_exceeded(const uint16_t identifier, const uint16_t sequence_number, const address &destination_address) const { - return icmp_data_ptr->match_time_exceeded(identifier, sequence_number); - // do not test ip since probably comes from router on route to dest. addr + return icmp_data_ptr->match_time_exceeded(identifier, + sequence_number, + destination_address); } bool IcmpPacket::match_echo_reply(const uint16_t identifier, diff --git a/src/icmp/icmptimeexceededdata.cpp b/src/icmp/icmptimeexceededdata.cpp index 8f2af93..e778bb9 100644 --- a/src/icmp/icmptimeexceededdata.cpp +++ b/src/icmp/icmptimeexceededdata.cpp @@ -33,18 +33,15 @@ IcmpTimeExceededData::IcmpTimeExceededData(const std::size_t size_arg) {} bool IcmpTimeExceededData::match_time_exceeded( - const uint16_t identifier, - const uint16_t sequence_number) const -{ - return IcmpData_PingFailReply::match_ping_request(identifier, - sequence_number); -} - -bool IcmpTimeExceededData::match_destination_unreachable( const uint16_t identifier, const uint16_t sequence_number, const address &destination_address) const -{ return false; } +{ + return IcmpData_PingFailReply::match_ping_request(identifier, + sequence_number) + && IcmpData::get_ip_header()->get_destination_address() + == destination_address; +} void IcmpTimeExceededData::print( const size_t &bytes_received, diff --git a/src/icmp/icmptimeexceededdata.h b/src/icmp/icmptimeexceededdata.h index 45b73c1..3f6eef8 100644 --- a/src/icmp/icmptimeexceededdata.h +++ b/src/icmp/icmptimeexceededdata.h @@ -44,12 +44,9 @@ class IcmpTimeExceededData : public IcmpData_PingFailReply public: IcmpTimeExceededData(const std::size_t size_arg); - bool match_destination_unreachable(const uint16_t identifier, - const uint16_t sequence_number, - const address &destination_address) const; - bool match_time_exceeded(const uint16_t identifier, - const uint16_t sequence_number) const; + const uint16_t sequence_number, + const address &destination_address) const; void print( const size_t &bytes_received, const boost::posix_time::ptime &time_packet_sent, diff --git a/test/test_icmppacket.cpp b/test/test_icmppacket.cpp index 559b095..a8ea85d 100644 --- a/test/test_icmppacket.cpp +++ b/test/test_icmppacket.cpp @@ -126,7 +126,7 @@ BOOST_AUTO_TEST_CASE( TimeExceeded ) BOOST_CHECK_EQUAL( packet->get_icmp_code(), 0 ); BOOST_CHECK_EQUAL( packet->get_icmp_size(), 48 ); BOOST_CHECK( packet->match_time_exceeded(0x4ae3, 1, - boost::asio::ip::address_v4::from_string("193.168.7.1")) ); + boost::asio::ip::address_v4::from_string("216.218.186.2")) ); } BOOST_AUTO_TEST_CASE( DestinationUnreachable ) -- 1.7.1