Commit | Line | Data |
---|---|---|
c120ad42 CH |
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 | |
057e6cc9 CH |
21 | Based on an example in Boost Documentation (by Christopher M. Kohlhoff) |
22 | and adaptation by Guilherme M. Ferreira | |
c120ad42 CH |
23 | */ |
24 | ||
a9c88e1c GMF |
25 | #ifndef ICMP_DATA_H |
26 | #define ICMP_DATA_H | |
d1ed4692 | 27 | |
c120ad42 CH |
28 | #include <stdint.h> |
29 | #include <iostream> | |
30 | #include <boost/shared_ptr.hpp> | |
31 | #include <boost/date_time/posix_time/ptime.hpp> | |
81c26517 | 32 | #include <boost/asio/ip/address.hpp> |
c120ad42 | 33 | #include "host/messagepayload.h" |
81c26517 CH |
34 | #include "ip/ipheader.h" |
35 | ||
36 | using boost::asio::ip::address; | |
c120ad42 CH |
37 | |
38 | /** @brief contents of ICMP packets after the first 4 bytes of the ICMP header | |
39 | * used for ICMPv4 and ICMPv6 | |
40 | * | |
41 | * subclasses only have to specify which part of raw_data to access for which | |
42 | * information | |
43 | */ | |
44 | class IcmpData | |
45 | { | |
46 | public: | |
0ba8adc0 | 47 | IcmpData(); |
c120ad42 | 48 | |
eb8ded5f CH |
49 | IcmpData(const std::size_t size_arg); |
50 | ||
0ba8adc0 | 51 | virtual ~IcmpData() {}; |
39d326f2 | 52 | |
c120ad42 | 53 | virtual bool match_echo_reply(const uint16_t identifier, |
0ba8adc0 | 54 | const uint16_t sequence_number) const; |
c120ad42 CH |
55 | |
56 | virtual bool match_destination_unreachable(const uint16_t identifier, | |
81c26517 CH |
57 | const uint16_t sequence_number, |
58 | const address &destination_address) const; | |
c120ad42 | 59 | |
15023b99 | 60 | virtual bool match_time_exceeded(const uint16_t identifier, |
24fdf496 CH |
61 | const uint16_t sequence_number, |
62 | const address &destination_address) const; | |
15023b99 | 63 | |
aadc7032 CH |
64 | // including 4 bytes from ICMPv4 header |
65 | std::size_t get_size() const; | |
c120ad42 | 66 | |
81c26517 CH |
67 | IpHeaderPtr get_ip_header() const; |
68 | ||
0ba8adc0 | 69 | uint32_t calc_checksum_part() const; |
aadc7032 | 70 | int get_ip_version() const; |
c120ad42 CH |
71 | |
72 | virtual void print( const size_t &bytes_received, | |
73 | const boost::posix_time::ptime &time_packet_sent, | |
74 | const std::string &remote_address, | |
0ba8adc0 | 75 | const uint32_t ttl) const; |
c120ad42 | 76 | |
39d326f2 CH |
77 | virtual std::string to_string() const; |
78 | ||
aadc7032 CH |
79 | virtual std::istream& read( std::istream &is); |
80 | virtual std::ostream& write(std::ostream &os) const; | |
81 | ||
39d326f2 CH |
82 | friend std::istream& operator>>( |
83 | std::istream &is, | |
84 | IcmpData &data | |
85 | ); | |
86 | friend std::ostream& operator<<( | |
87 | std::ostream &os, | |
88 | const IcmpData &data | |
89 | ); | |
747c13ca | 90 | |
c120ad42 CH |
91 | protected: |
92 | ||
c120ad42 CH |
93 | std::size_t size; |
94 | MessagePayload raw_data; | |
95 | }; | |
96 | ||
97 | typedef boost::shared_ptr<IcmpData> IcmpDataPtr; | |
d1ed4692 | 98 | |
c120ad42 | 99 | #endif |
d1ed4692 | 100 |