/* 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_HEADER_H #define ICMP_HEADER_H #include #include /** @brief first 4 byte of ICMP header (v4 and v6) * * In ICMP v4, the first 4 bytes are standardized, the other 4 depend on * message type. In Icmp v6, the header IS only the first 4 bytes. * So everything after those first 4 bytes is contained in IcmpData subclasses */ class IcmpHeader { public: IcmpHeader(); IcmpHeader(const uint8_t type_arg, const uint8_t code_arg); std::istream& read(std::istream &is); std::ostream& write(std::ostream &os) const; uint8_t get_type() const; uint8_t get_code() const; uint16_t get_checksum() const; void calc_checksum( const uint32_t body_checksum_part ); // returns the amount of data represented by this class; // for Icmp v4, the header is actually 8 bytes, see comments above uint16_t get_header_length() const; std::string to_string() const; friend std::istream& operator>>( std::istream &is, IcmpHeader &header ); friend std::ostream& operator<<( std::ostream &os, const IcmpHeader &header ); protected: uint8_t type; uint8_t code; uint16_t checksum; }; #endif