remove the footer saying that vim is the best editor -- anyone knows anyway
[pingcheck] / src / icmp / icmptimeexceededdata.cpp
CommitLineData
15023b99
CH
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.
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
23 */
24
25#include "icmp/icmptimeexceededdata.h"
26
27#include <logfunc.hpp>
28using I2n::Logger::GlobalLogger;
29
30
31IcmpTimeExceededData::IcmpTimeExceededData(const std::size_t size_arg)
32 : IcmpData_PingFailReply( size_arg )
33{}
34
35bool IcmpTimeExceededData::match_time_exceeded(
81c26517
CH
36 const uint16_t identifier,
37 const uint16_t sequence_number,
38 const address &destination_address) const
24fdf496
CH
39{
40 return IcmpData_PingFailReply::match_ping_request(identifier,
41 sequence_number)
42 && IcmpData::get_ip_header()->get_destination_address()
43 == destination_address;
44}
15023b99
CH
45
46void 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
51{
52 uint16_t sequence_number = get_icmp_sequence_number();
53
54 GlobalLogger.info() << "Time exceeded pinging " << remote_address
55 << " (icmp_seq=" << sequence_number << ")!"
56 << std::endl;
7edd33cf
CH
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
15023b99
CH
59}
60
61std::string IcmpTimeExceededData::to_string() const
62{
aadc7032
CH
63 if (IcmpData_PingFailReply::get_icmp_data_offset() == -1)
64 // not icmp!
65 return "[TimeExceededData from non-ICMP request]";
66 else
67 {
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() << "]";
73
74 return buf.str();
75 }
15023b99
CH
76}
77