/* The software in this package is distributed under the GNU General Public License version 2 (with a special exception described below). A copy of GNU General Public License (GPL) is included in this distribution, in the file COPYING.GPL. As a special exception, if other files instantiate templates or use macros or inline functions from this file, or you compile this file and link it with other works to produce a work based on this file, this file does not by itself cause the resulting work to be covered by the GNU General Public License. However the source code for this file must still be made available in accordance with section (3) of the GNU General Public License. This exception does not invalidate any other reasons why a work based on this file might be covered by the GNU General Public License. Christian Herdtweck, Intra2net AG 2015 Based on an example in Boost Documentation (by Christopher M. Kohlhoff) and adaptation by Guilherme M. Ferreira */ #ifndef ICMP_DATA_H #define ICMP_DATA_H #include #include #include #include #include #include "host/messagepayload.h" #include "ip/ipheader.h" using boost::asio::ip::address; /** @brief contents of ICMP packets after the first 4 bytes of the ICMP header * used for ICMPv4 and ICMPv6 * * subclasses only have to specify which part of raw_data to access for which * information */ class IcmpData { public: IcmpData(); IcmpData(const std::size_t size_arg); virtual ~IcmpData() {}; virtual bool match_echo_reply(const uint16_t identifier, const uint16_t sequence_number) const; virtual bool match_destination_unreachable(const uint16_t identifier, const uint16_t sequence_number, const address &destination_address) const; virtual bool match_time_exceeded(const uint16_t identifier, const uint16_t sequence_number, const address &destination_address) const; // including 4 bytes from ICMPv4 header std::size_t get_size() const; IpHeaderPtr get_ip_header() const; uint32_t calc_checksum_part() const; int get_ip_version() const; virtual void print( const size_t &bytes_received, const boost::posix_time::ptime &time_packet_sent, const std::string &remote_address, const uint32_t ttl) const; virtual std::string to_string() const; virtual std::istream& read( std::istream &is); virtual std::ostream& write(std::ostream &os) const; friend std::istream& operator>>( std::istream &is, IcmpData &data ); friend std::ostream& operator<<( std::ostream &os, const IcmpData &data ); protected: std::size_t size; MessagePayload raw_data; }; typedef boost::shared_ptr IcmpDataPtr; #endif