Commit | Line | Data |
---|---|---|
0fb1a712 GMF |
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. | |
057e6cc9 CH |
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 | |
0fb1a712 GMF |
23 | */ |
24 | ||
25 | #ifndef ICMP_PACKET_FACTORY_H | |
26 | #define ICMP_PACKET_FACTORY_H | |
27 | ||
28 | #include <stdint.h> | |
29 | ||
30 | #include <iostream> | |
31 | ||
fc3754b0 GMF |
32 | #include <boost/asio.hpp> |
33 | ||
0fb1a712 | 34 | #include "icmp/icmppacket.h" |
0fb1a712 | 35 | |
a92bd1ca | 36 | |
ed614187 CH |
37 | enum DumpMode { |
38 | DUMP_NEVER = 0, | |
39 | DUMP_IF_ERROR = 1, | |
40 | DUMP_ALWAYS = 2 | |
41 | }; | |
42 | ||
0fb1a712 GMF |
43 | //----------------------------------------------------------------------------- |
44 | // IcmpPacketFactory | |
45 | //----------------------------------------------------------------------------- | |
46 | ||
47 | /** | |
48 | * @brief Class which constructs ICMP Packets, hiding from the class users the | |
49 | * underlying details on how to build each packet. | |
688d4b27 CH |
50 | * |
51 | * @param dump_mode: 0 to never dump, 1 to dump in case of parsing trouble, | |
52 | * 2 to always dump | |
0fb1a712 GMF |
53 | */ |
54 | class IcmpPacketFactory | |
55 | { | |
56 | public: | |
ed614187 CH |
57 | /// directory and file name start used to dump packets; |
58 | /// will be concatenated with time and pattern that ensures unique file name | |
59 | static std::string DumpFilePrefix; | |
60 | static DumpMode PacketDumpMode; | |
61 | ||
6d80c0be CH |
62 | static void dump_packet(const std::string &data); |
63 | static void dump_packet(const IcmpPacket &packet); | |
64 | ||
0fb1a712 | 65 | static IcmpPacketItem create_icmp_packet( |
fc3754b0 | 66 | const boost::asio::ip::icmp::socket::protocol_type &protocol, |
ed614187 | 67 | std::istream &is |
0fb1a712 GMF |
68 | ); |
69 | static IcmpPacketItem create_icmp_packet_echo_request( | |
fc3754b0 | 70 | const boost::asio::ip::icmp::socket::protocol_type &protocol, |
0fb1a712 GMF |
71 | const uint16_t identifier, |
72 | const uint16_t sequence_number | |
73 | ); | |
0fb1a712 GMF |
74 | }; |
75 | ||
76 | #endif // ICMP_PACKET_FACTORY_H |