b5a9fed7bc71dafea6a27c0bef8f4f1fe42cdc7b
[pingcheck] / src / icmp / icmpechodata.h
1 /*
2  The software in this package is distributed under the GNU General
3  Public License version 2 (with a special exception described below).
4
5  A copy of GNU General Public License (GPL) is included in this distribution,
6  in the file COPYING.GPL.
7
8  As a special exception, if other files instantiate templates or use macros
9  or inline functions from this file, or you compile this file and link it
10  with other works to produce a work based on this file, this file
11  does not by itself cause the resulting work to be covered
12  by the GNU General Public License.
13
14  However the source code for this file must still be made available
15  in accordance with section (3) of the GNU General Public License.
16
17  This exception does not invalidate any other reasons why a work based
18  on this file might be covered by the GNU General Public License.
19
20  Christian Herdtweck, Intra2net AG 2015
21  Based on an example in Boost Documentation (by Christopher M. Kohlhoff)
22  and adaptation by Guilherme M. Ferreira
23  */
24
25 #ifndef ICMP_ECHO_DATA_H
26 #define ICMP_ECHO_DATA_H
27
28 #include <stdint.h>
29 #include "icmp/icmpdata.h"
30
31 #include <boost/date_time/posix_time/ptime.hpp>
32 #include <boost/asio/ip/address.hpp>
33 using boost::asio::ip::address;
34
35 /** @brief Data part of ICMP echo request and echo reply packets
36  *
37  * represents the last 4 bytes of the ICMP header (for v4) and the 8 bytes
38  *   of optional data; for v6 this (same amount of?!) data is defined as the
39  *   body
40  */
41 class IcmpEchoData : public IcmpData
42 {
43 public:
44     IcmpEchoData(const uint16_t identifier, const uint16_t sequence_number,
45                  const std::string &optional_data);
46
47     IcmpEchoData(const std::size_t size_arg);
48
49     bool match_destination_unreachable(const uint16_t identifier,
50                                   const uint16_t sequence_number,
51                                   const address &destination_address) const;
52
53     bool match_echo_reply(const uint16_t identifier,
54                           const uint16_t sequence_number) const;
55
56     bool match_time_exceeded(const uint16_t identifier,
57                              const uint16_t sequence_number) const;
58
59     uint16_t get_identifier() const;
60
61     uint16_t get_sequence_number() const;
62
63     /**
64      * @brief Prints the ICMP echo reply messages.
65      *
66      * @return void
67      */
68     void print( const size_t &bytes_received,
69                 const boost::posix_time::ptime &time_packet_sent,
70                 const std::string &remote_address,
71                 const uint32_t ttl) const;
72
73     std::string to_string() const;
74 };
75
76 #endif
77