2 The software in this package is distributed under the GNU General
3 Public License version 2 (with a special exception described below).
5 A copy of GNU General Public License (GPL) is included in this distribution,
6 in the file COPYING.GPL.
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.
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.
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.
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
25 #include "icmp/icmptimeexceededdata.h"
27 #include <logfunc.hpp>
28 using I2n::Logger::GlobalLogger;
31 IcmpTimeExceededData::IcmpTimeExceededData(const std::size_t size_arg)
32 : IcmpData_PingFailReply( size_arg )
35 bool IcmpTimeExceededData::match_time_exceeded(
36 const uint16_t identifier,
37 const uint16_t sequence_number,
38 const address &destination_address) const
40 return IcmpData_PingFailReply::match_ping_request(identifier,
42 && IcmpData::get_ip_header()->get_destination_address()
43 == destination_address;
46 void IcmpTimeExceededData::print(
47 const size_t &bytes_received,
48 const boost::posix_time::ptime &time_packet_sent,
49 const std::string &remote_address,
50 const uint32_t ttl) const
52 uint16_t sequence_number = get_icmp_sequence_number();
54 GlobalLogger.info() << "Time exceeded pinging " << remote_address
55 << " (icmp_seq=" << sequence_number << ")!"
57 // TTL given as arg is the one of the return packet, so not of interest
58 // IcmpData_PingFailReply::get_ip_ttl() always gives 1
61 std::string IcmpTimeExceededData::to_string() const
63 if (IcmpData_PingFailReply::get_icmp_data_offset() == -1)
65 return "[TimeExceededData from non-ICMP request]";
68 std::stringstream buf;
69 buf << "[TimeExceededData: ID=" << std::showbase << std::hex
70 << IcmpData_PingFailReply::get_icmp_identifier() << ",seq.nr="
71 << std::noshowbase << std::dec
72 << IcmpData_PingFailReply::get_icmp_sequence_number() << "]";
78 // (created using vim -- the world's best text editor)