#ifndef ICMP_PACKET_H
#define ICMP_PACKET_H
+#include <stdint.h>
+
#include <string>
+#include <boost/asio.hpp>
#include <boost/date_time/posix_time/posix_time_types.hpp>
//-----------------------------------------------------------------------------
IcmpPacket();
virtual ~IcmpPacket();
+ virtual bool is_echo_reply(
+ const uint16_t identifier,
+ const uint16_t sequence_number,
+ const boost::asio::ip::address &source_address
+ ) const = 0;
+ virtual bool is_destination_unreachable(
+ const uint16_t identifier,
+ const uint16_t sequence_number,
+ const boost::asio::ip::address &source_address
+ ) const = 0;
+
virtual void print_echo_reply(
const std::size_t &bytes_transferred,
const boost::posix_time::ptime &time_packet_sent
// expected sequence number, and destination host address (receive just
// the ICMP packets from the host we had ping).
- if ( icmp_packet.match( Icmpv4Type_EchoReply,
+ if ( icmp_packet.is_echo_reply(
Identifier, SequenceNumber,
DestinationEndpoint.address() ) )
{
IcmpPacketReceiveTimer.cancel();
}
- else if ( icmp_packet.match( Icmpv4Type_DestinationUnreachable,
+ else if ( icmp_packet.is_destination_unreachable(
Identifier, SequenceNumber,
DestinationEndpoint.address() ) )
{
}
/**
+ * @brief Convenience method to check if this packet, matching the arguments,
+ * is a echo reply.
+ *
+ * @param identifier The identifier.
+ * @param sequence_number The sequence number.
+ * @param source_address The source address.
+ *
+ * @return @c true if this packet is a echo reply, or @c false otherwise.
+ */
+bool Icmpv4Packet::is_echo_reply(
+ const uint16_t identifier,
+ const uint16_t sequence_number,
+ const address &source_address
+) const
+{
+ return match( Icmpv4Type_EchoReply, identifier, sequence_number, source_address );
+}
+
+/**
+ * @brief Convenience method to check if this packet, matching the arguments,
+ * is a destination unreachable.
+ *
+ * @param identifier The identifier.
+ * @param sequence_number The sequence number.
+ * @param source_address The source address.
+ *
+ * @return @c true if this packet is a destination unreachable, or @c false
+ * otherwise.
+ */
+bool Icmpv4Packet::is_destination_unreachable(
+ const uint16_t identifier,
+ const uint16_t sequence_number,
+ const address &source_address
+) const
+{
+ return match( Icmpv4Type_DestinationUnreachable, identifier, sequence_number, source_address );
+}
+
+/**
* @brief Check if this object matches with all the parameters.
*
* @param type The type of ICMP message.
Icmpv4Header get_icmp_header() const;
IcmpData get_icmp_data() const;
- bool match(
- const Icmpv4Type type,
+ bool is_echo_reply(
+ const uint16_t identifier,
+ const uint16_t sequence_number,
+ const boost::asio::ip::address &source_address
+ ) const;
+ bool is_destination_unreachable(
const uint16_t identifier,
const uint16_t sequence_number,
const boost::asio::ip::address &source_address
);
private:
+ bool match(
+ const Icmpv4Type type,
+ const uint16_t identifier,
+ const uint16_t sequence_number,
+ const boost::asio::ip::address &source_address
+ ) const;
+
+private:
/// The IP header.
Ipv4Header IpHeader;
/// The ICMP packet header.
}
/**
+ * @brief Convenience method to check if this packet, matching the arguments,
+ * is a echo reply.
+ *
+ * @param identifier The identifier.
+ * @param sequence_number The sequence number.
+ * @param source_address The source address.
+ *
+ * @return @c true if this packet is a echo reply, or @c false otherwise.
+ */
+bool Icmpv6Packet::is_echo_reply(
+ const uint16_t identifier,
+ const uint16_t sequence_number,
+ const address &source_address
+) const
+{
+ return match( Icmpv6Type_EchoReply, identifier, sequence_number, source_address );
+}
+
+/**
+ * @brief Convenience method to check if this packet, matching the arguments,
+ * is a destination unreachable.
+ *
+ * @param identifier The identifier.
+ * @param sequence_number The sequence number.
+ * @param source_address The source address.
+ *
+ * @return @c true if this packet is a destination unreachable, or @c false
+ * otherwise.
+ */
+bool Icmpv6Packet::is_destination_unreachable(
+ const uint16_t identifier,
+ const uint16_t sequence_number,
+ const address &source_address
+) const
+{
+ return match( Icmpv6Type_DestinationUnreachable, identifier, sequence_number, source_address );
+}
+
+/**
* @brief Check if this object matches with all the parameters.
*
* @param type The type of ICMP message.
Icmpv6Header get_icmp_header() const;
IcmpData get_icmp_data() const;
- bool match(
- const Icmpv6Type type,
+ bool is_echo_reply(
+ const uint16_t identifier,
+ const uint16_t sequence_number,
+ const boost::asio::ip::address &source_address
+ ) const;
+ bool is_destination_unreachable(
const uint16_t identifier,
const uint16_t sequence_number,
const boost::asio::ip::address &source_address
);
private:
+ bool match(
+ const Icmpv6Type type,
+ const uint16_t identifier,
+ const uint16_t sequence_number,
+ const boost::asio::ip::address &source_address
+ ) const;
+
+private:
/// The IP header.
Ipv6Header IpHeader;
/// The ICMP packet header.