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/icmpdestinationunreachabledata.h"
27 #include <logfunc.hpp>
28 using I2n::Logger::GlobalLogger;
31 IcmpDestinationUnreachableData::IcmpDestinationUnreachableData(
32 const std::size_t size_arg)
33 : IcmpData_PingFailReply( size_arg )
36 bool IcmpDestinationUnreachableData::match_destination_unreachable(
37 const uint16_t identifier,
38 const uint16_t sequence_number,
39 const address &destination_address) const
41 return IcmpData_PingFailReply::match_ping_request(identifier,
43 && IcmpData::get_ip_header()->get_destination_address()
44 == destination_address;
48 * @brief Prints the destination unreachable messages.
52 void IcmpDestinationUnreachableData::print(
53 const size_t &bytes_received,
54 const boost::posix_time::ptime &time_packet_sent,
55 const std::string &remote_address,
56 const uint32_t ttl) const
58 uint16_t sequence_number = get_icmp_sequence_number();
60 GlobalLogger.info() << "Destination " << remote_address
61 << " (icmp_seq=" << sequence_number << ") unreachable!"
65 std::string IcmpDestinationUnreachableData::to_string() const
67 if (IcmpData_PingFailReply::get_icmp_data_offset() == -1)
69 return "[DestUnrchbleData from non-ICMP request]";
72 std::stringstream buf;
73 buf << "[DestUnrchbleData: ID=" << std::showbase << std::hex
74 << IcmpData_PingFailReply::get_icmp_identifier() << ",seq.nr="
75 << std::noshowbase << std::dec
76 << IcmpData_PingFailReply::get_icmp_sequence_number() << "]";
81 // (created using vim -- the world's best text editor)