71f8290fa8cdaeb311f7197f4681080a1269ce1d
[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 #include "host/messagepayload.h"
16
17 //-----------------------------------------------------------------------------
18 // Ipv4Header
19 //-----------------------------------------------------------------------------
20
21 /**
22  * @brief This class represents the IP version 4 Packet Header.
23  *
24  * The IPv4 header format is:
25  *
26  * @code
27  * 0      3 4     7 8            15 16                           31
28  * +-------+-------+---------------+------------------------------+      ---
29  * |       |       |               |                              |       ^
30  * |version|header | differentiated|    total length in bytes     |       |
31  * |  (4)  | length|    services   |                              |       |
32  * +-------+-------+---------------+-+-+-+------------------------+       |
33  * |                               | | | |                        |       |
34  * |        identification         |0|D|M|    fragment offset     |       |
35  * |                               | |F|F|                        |       |
36  * +---------------+---------------+-+-+-+------------------------+       |
37  * |               |               |                              |       |
38  * | time to live  |   protocol    |       header checksum        |   20 bytes
39  * |               |               |                              |       |
40  * +---------------+---------------+------------------------------+       |
41  * |                                                              |       |
42  * |                      source IPv4 address                     |       |
43  * |                                                              |       |
44  * +--------------------------------------------------------------+       |
45  * |                                                              |       |
46  * |                   destination IPv4 address                   |       |
47  * |                                                              |       v
48  * +--------------------------------------------------------------+      ---
49  * |                                                              |       ^
50  * |                                                              |       |
51  * /                        options (if any)                      /    0 - 40
52  * /                                                              /     bytes
53  * |                                                              |       |
54  * |                                                              |       v
55  * +--------------------------------------------------------------+      ---
56  * @endcode
57  */
58 class Ipv4Header : public IpHeader
59 {
60 public:
61     Ipv4Header();
62
63     uint8_t get_version() const;
64     uint16_t get_header_length() const;
65     uint8_t get_differentiated_services() const;
66     uint16_t get_total_length() const;
67
68     uint16_t get_identification() const;
69     bool dont_fragment() const;
70     bool more_fragments() const;
71     uint16_t get_fragment_offset() const;
72
73     uint8_t get_time_to_live() const;
74     uint8_t get_protocol() const;
75     uint16_t get_header_checksum() const;
76
77     boost::asio::ip::address get_source_address() const;
78     boost::asio::ip::address get_destination_address() const;
79
80     friend std::istream &operator>>(
81             std::istream &is,
82             Ipv4Header &header
83     );
84
85 private:
86     MessagePayload Payload;
87
88 };
89
90 #endif // IPV4_HEADER_H