is >> icmp_packet;
// We can receive all ICMP packets received by the host, so we need to
- // filter out only the echo replies that match the our identifier and
- // expected sequence number.
+ // filter out only the echo replies that match the our identifier,
+ // expected sequence number, and destination host address (receive just the
+ // ICMP packets from the host we had ping).
if ( icmp_packet.match(
- IcmpType_EchoReply, get_identifier(), SequenceNumber
+ IcmpType_EchoReply, get_identifier(), SequenceNumber,
+ DestinationEndpoint.address()
) )
{
// If this is the first reply, interrupt the echo reply timeout.
set_ping_status( PingStatus_SuccessReply );
}
else if ( icmp_packet.match(
- IcmpType_DestinationUnreachable, get_identifier(), SequenceNumber
+ IcmpType_DestinationUnreachable, get_identifier(), SequenceNumber,
+ DestinationEndpoint.address()
) )
{
// If this is the first reply, interrupt the echo reply timeout.
#include "icmp/icmppacket.h"
+using namespace std;
+using boost::asio::ip::address;
+
//-----------------------------------------------------------------------------
// IcmpPacket
//-----------------------------------------------------------------------------
}
bool IcmpPacket::match(
- IcmpType type,
- uint16_t identifier,
- uint16_t sequence_number
+ const IcmpType type,
+ const uint16_t identifier,
+ const uint16_t sequence_number,
+ const address &source_address
) const
{
bool type_match = IcmpPayloadHeader.get_type() == type;
bool identifier_match = IcmpPayloadHeader.get_identifier() == identifier;
bool seq_num_match = IcmpPayloadHeader.get_sequence_number() == sequence_number;
+ bool address_match = IpHeader.get_source_address() == source_address;
- return ( type_match && identifier_match && seq_num_match );
+ return ( type_match && identifier_match && seq_num_match && address_match );
}
-std::istream& operator>>(
- std::istream &is,
+istream& operator>>(
+ istream &is,
IcmpPacket &packet
)
{
return is;
}
-std::ostream& operator<<(
- std::ostream& os,
+ostream& operator<<(
+ ostream& os,
const IcmpPacket& packet
)
{
#include <istream>
#include <ostream>
+#include <boost/asio.hpp>
+
#include "icmp/ipv4header.h"
#include "icmp/icmpheader.h"
#include "icmp/icmpdata.h"
IcmpData get_icmp_data() const;
bool match(
- IcmpType type,
- uint16_t identifier,
- uint16_t sequence_number
+ const IcmpType type,
+ const uint16_t identifier,
+ const uint16_t sequence_number,
+ const boost::asio::ip::address &source_address
) const;
friend std::istream& operator>>(