made nicer static variables of packet dump mode and location
[pingcheck] / src / icmp / icmppacketfactory.h
CommitLineData
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
CH
36
37void dump_packet(const std::string &data);
38
ed614187
CH
39enum DumpMode {
40 DUMP_NEVER = 0,
41 DUMP_IF_ERROR = 1,
42 DUMP_ALWAYS = 2
43};
44
0fb1a712
GMF
45//-----------------------------------------------------------------------------
46// IcmpPacketFactory
47//-----------------------------------------------------------------------------
48
49/**
50 * @brief Class which constructs ICMP Packets, hiding from the class users the
51 * underlying details on how to build each packet.
688d4b27
CH
52 *
53 * @param dump_mode: 0 to never dump, 1 to dump in case of parsing trouble,
54 * 2 to always dump
0fb1a712
GMF
55 */
56class IcmpPacketFactory
57{
58public:
ed614187
CH
59 /// directory and file name start used to dump packets;
60 /// will be concatenated with time and pattern that ensures unique file name
61 static std::string DumpFilePrefix;
62 static DumpMode PacketDumpMode;
63
0fb1a712 64 static IcmpPacketItem create_icmp_packet(
fc3754b0 65 const boost::asio::ip::icmp::socket::protocol_type &protocol,
ed614187 66 std::istream &is
0fb1a712
GMF
67 );
68 static IcmpPacketItem create_icmp_packet_echo_request(
fc3754b0 69 const boost::asio::ip::icmp::socket::protocol_type &protocol,
0fb1a712
GMF
70 const uint16_t identifier,
71 const uint16_t sequence_number
72 );
0fb1a712
GMF
73};
74
75#endif // ICMP_PACKET_FACTORY_H