extended ICMP packet dumping to parts after packet creation
[pingcheck] / src / ip / ipv4header.h
1 // Copyright (c) 2003-2010 Christopher M. Kohlhoff
2 // Modifications (c) 2011 by Guilherme Maciel Ferreira / Intra2net AG
3 //
4 // Distributed under the Boost Software License, Version 1.0.
5 //    (See accompanying file LICENSE_1_0.txt or copy at
6 //          http://www.boost.org/LICENSE_1_0.txt)
7 #ifndef IPV4_HEADER_H
8 #define IPV4_HEADER_H
9
10 #include <stdint.h>
11
12 #include <boost/asio/ip/address_v4.hpp>
13
14 #include "ip/ipheader.h"
15
16 //-----------------------------------------------------------------------------
17 // Ipv4Header
18 //-----------------------------------------------------------------------------
19
20 /**
21  * @brief This class represents the IP version 4 Packet Header.
22  *
23  * The IPv4 header format is:
24  *
25  * @code
26  * 0      3 4     7 8            15 16                           31
27  * +-------+-------+---------------+------------------------------+      ---
28  * |       |       |               |                              |       ^
29  * |version|header | differentiated|    total length in bytes     |       |
30  * |  (4)  | length|    services   |                              |       |
31  * +-------+-------+---------------+-+-+-+------------------------+       |
32  * |                               | | | |                        |       |
33  * |        identification         |0|D|M|    fragment offset     |       |
34  * |                               | |F|F|                        |       |
35  * +---------------+---------------+-+-+-+------------------------+       |
36  * |               |               |                              |       |
37  * | time to live  |   protocol    |       header checksum        |   20 bytes
38  * |               |               |                              |       |
39  * +---------------+---------------+------------------------------+       |
40  * |                                                              |       |
41  * |                      source IPv4 address                     |       |
42  * |                                                              |       |
43  * +--------------------------------------------------------------+       |
44  * |                                                              |       |
45  * |                   destination IPv4 address                   |       |
46  * |                                                              |       v
47  * +--------------------------------------------------------------+      ---
48  * |                                                              |       ^
49  * |                                                              |       |
50  * /                        options (if any)                      /    0 - 40
51  * /                                                              /     bytes
52  * |                                                              |       |
53  * |                                                              |       v
54  * +--------------------------------------------------------------+      ---
55  * @endcode
56  */
57 class Ipv4Header : public IpHeader
58 {
59 public:
60     Ipv4Header();
61
62     uint8_t get_version() const;
63     uint16_t get_header_length() const;
64     uint8_t get_differentiated_services() const;
65     uint16_t get_total_length() const;
66
67     uint16_t get_identification() const;
68     bool dont_fragment() const;
69     bool more_fragments() const;
70     uint16_t get_fragment_offset() const;
71
72     uint8_t get_time_to_live() const;
73     uint8_t get_protocol() const;
74     uint16_t get_header_checksum() const;
75
76     boost::asio::ip::address get_source_address() const;
77     boost::asio::ip::address get_destination_address() const;
78
79     friend std::istream &operator>>(
80             std::istream &is,
81             Ipv4Header &header
82     );
83
84 };
85
86 #endif // IPV4_HEADER_H