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 | ||
25 | #ifndef ICMP_HEADER_H | |
26 | #define ICMP_HEADER_H | |
27 | ||
28 | #include <stdint.h> | |
29 | #include <iostream> | |
747c13ca | 30 | |
c120ad42 CH |
31 | /** @brief first 4 byte of ICMP header (v4 and v6) |
32 | * | |
33 | * In ICMP v4, the first 4 bytes are standardized, the other 4 depend on | |
34 | * message type. In Icmp v6, the header IS only the first 4 bytes. | |
35 | * So everything after those first 4 bytes is contained in IcmpData subclasses | |
36 | */ | |
37 | class IcmpHeader | |
38 | { | |
39 | public: | |
0ba8adc0 CH |
40 | IcmpHeader(); |
41 | ||
42 | IcmpHeader(const uint8_t type_arg, const uint8_t code_arg); | |
c120ad42 | 43 | |
39d326f2 CH |
44 | std::istream& read(std::istream &is); |
45 | std::ostream& write(std::ostream &os) const; | |
46 | ||
0ba8adc0 CH |
47 | uint8_t get_type() const; |
48 | uint8_t get_code() const; | |
49 | uint16_t get_checksum() const; | |
39d326f2 CH |
50 | |
51 | void calc_checksum( const uint32_t body_checksum_part ); | |
c120ad42 CH |
52 | |
53 | // returns the amount of data represented by this class; | |
54 | // for Icmp v4, the header is actually 8 bytes, see comments above | |
0ba8adc0 | 55 | uint16_t get_header_length() const; |
c120ad42 | 56 | |
39d326f2 CH |
57 | std::string to_string() const; |
58 | ||
59 | friend std::istream& operator>>( | |
60 | std::istream &is, | |
61 | IcmpHeader &header | |
62 | ); | |
63 | friend std::ostream& operator<<( | |
64 | std::ostream &os, | |
65 | const IcmpHeader &header | |
66 | ); | |
747c13ca | 67 | |
c120ad42 CH |
68 | protected: |
69 | uint8_t type; | |
70 | uint8_t code; | |
747c13ca | 71 | uint16_t checksum; |
c120ad42 CH |
72 | }; |
73 | ||
c120ad42 CH |
74 | #endif |
75 |