host/pingprotocol.cpp
host/pingrotate.cpp
host/pingscheduler.cpp
+ icmp/icmpdata.cpp
+ icmp/icmpheader.cpp
icmp/icmppacket.cpp
icmp/icmppinger.cpp
icmp/icmppacketfactory.cpp
--- /dev/null
+/*
+ The software in this package is distributed under the GNU General
+ Public License version 2 (with a special exception described below).
+
+ A copy of GNU General Public License (GPL) is included in this distribution,
+ in the file COPYING.GPL.
+
+ As a special exception, if other files instantiate templates or use macros
+ or inline functions from this file, or you compile this file and link it
+ with other works to produce a work based on this file, this file
+ does not by itself cause the resulting work to be covered
+ by the GNU General Public License.
+
+ However the source code for this file must still be made available
+ in accordance with section (3) of the GNU General Public License.
+
+ This exception does not invalidate any other reasons why a work based
+ on this file might be covered by the GNU General Public License.
+
+ Christian Herdtweck, Intra2net AG 2015
+ */
+
+#include "icmpdata.h"
+
+#include <sstream>
+
+std::istream& IcmpData::read(std::istream &is) // read raw data
+{
+ return raw_data.read(is);
+}
+
+std::ostream& IcmpData::write(std::ostream &os) const
+{
+ return raw_data.write(os);
+}
+
+std::string IcmpData::to_string() const
+{
+ std::stringstream buf;
+ buf << "[IcmpData of length " << size << "]";
+ return buf.str();
+}
+
+std::istream& operator>>(
+ std::istream &is,
+ IcmpData &data
+)
+{ return data.read( is ); }
+
+std::ostream& operator<<(
+ std::ostream &os,
+ const IcmpData &data
+)
+{ return data.write( os ); }
+
+// (created using vim -- the world's best text editor)
+
#include <stdint.h>
#include <iostream>
-#include <sstream>
#include <boost/shared_ptr.hpp>
#include <boost/date_time/posix_time/ptime.hpp>
#include "host/messagepayload.h"
, raw_data( 0 )
{}
+ virtual ~IcmpData() {}
+
virtual bool match_echo_reply(const uint16_t identifier,
const uint16_t sequence_number) const
{ return false; };
const uint16_t sequence_number) const
{ return false; };
- std::size_t get_size() { return size; };
-
- virtual std::istream& read(std::istream &is) // read raw data
- { return raw_data.read(is); }
+ inline std::size_t get_size() { return size; };
- std::ostream& write(std::ostream &os)
- { return raw_data.write(os); }
+ virtual std::istream& read( std::istream &is);
+ virtual std::ostream& write(std::ostream &os) const;
- virtual ~IcmpData() {}
-
- uint32_t calc_checksum_part() const
+ inline uint32_t calc_checksum_part() const
{ return raw_data.calc_checksum_part(); }
virtual void print( const size_t &bytes_received,
const uint32_t ttl) const
{}
- virtual std::string to_string() const
- {
- std::stringstream buf;
- buf << "[IcmpData of length " << size << "]";
- return buf.str();
- }
+ virtual std::string to_string() const;
+
+ friend std::istream& operator>>(
+ std::istream &is,
+ IcmpData &data
+ );
+ friend std::ostream& operator<<(
+ std::ostream &os,
+ const IcmpData &data
+ );
protected:
else
// if it is an icmp message, then the icmp packet comes right after
// the IP header. Inside the icmp packet we need bytes 5-8
- IcmpData::raw_data.decode16(offset+data_offset,
- offset+data_offset+1);
+ return IcmpData::raw_data.decode16(offset+data_offset,
+ offset+data_offset+1);
}
/**
--- /dev/null
+/*
+ The software in this package is distributed under the GNU General
+ Public License version 2 (with a special exception described below).
+
+ A copy of GNU General Public License (GPL) is included in this distribution,
+ in the file COPYING.GPL.
+
+ As a special exception, if other files instantiate templates or use macros
+ or inline functions from this file, or you compile this file and link it
+ with other works to produce a work based on this file, this file
+ does not by itself cause the resulting work to be covered
+ by the GNU General Public License.
+
+ However the source code for this file must still be made available
+ in accordance with section (3) of the GNU General Public License.
+
+ This exception does not invalidate any other reasons why a work based
+ on this file might be covered by the GNU General Public License.
+
+ Christian Herdtweck, Intra2net AG 2015
+ */
+
+#include "icmp/icmpheader.h"
+#include <boost/scoped_array.hpp>
+
+std::istream& IcmpHeader::read(std::istream &is)
+{
+ boost::scoped_array<char> buf( new char[4] );
+ is.read(buf.get(), 4);
+ type = static_cast<uint8_t>(buf[0]);
+ code = static_cast<uint8_t>(buf[1]);
+ checksum = ( static_cast<uint16_t>(buf[2]) << 8 )
+ + static_cast<uint16_t>(buf[3]);
+
+ return is;
+}
+
+std::ostream& IcmpHeader::write(std::ostream &os) const
+{
+ uint8_t checksum_lsb = static_cast<uint8_t>(checksum & 0x00FF);
+ uint8_t checksum_msb = static_cast<uint8_t>((checksum & 0xFF00) >> 8);
+ return os << type << code << checksum_msb << checksum_lsb;
+}
+
+
+// code adapted from boost icmp example by Christopher M. Kohlhoff
+// --> boost license?!?
+void IcmpHeader::calc_checksum( const uint32_t body_checksum_part )
+{
+ uint32_t sum = (type << 8) + code;
+ sum += body_checksum_part;
+
+ sum = (sum >> 16) + (sum & 0xFFFF);
+ sum += (sum >> 16);
+
+ checksum = static_cast<uint16_t>( ~sum );
+}
+
+
+std::string IcmpHeader::to_string() const
+{
+ std::stringstream buf;
+ buf << "[Icmp header type=" << static_cast<int>(type)
+ << ",code=" << static_cast<int>(code)
+ << " (cksum:" << std::showbase << std::hex << checksum << ")]";
+ return buf.str();
+}
+
+
+std::istream& operator>>(
+ std::istream &is,
+ IcmpHeader &header
+)
+{ return header.read( is ); }
+
+std::ostream& operator<<(
+ std::ostream &os,
+ const IcmpHeader &header
+)
+{ return header.write( os ); }
+
+
+// (created using vim -- the world's best text editor)
+
#include <stdint.h>
#include <iostream>
-#include <sstream>
-#include <boost/scoped_array.hpp>
-
-#include <logfunc.hpp>
-using I2n::Logger::GlobalLogger;
/** @brief first 4 byte of ICMP header (v4 and v6)
*
, checksum( 0 )
{}
- std::istream& read(std::istream &is)
- {
- boost::scoped_array<char> buf( new char[4] );
- is.read(buf.get(), 4);
- type = static_cast<uint8_t>(buf[0]);
- code = static_cast<uint8_t>(buf[1]);
- checksum = ( static_cast<uint16_t>(buf[2]) << 8 )
- + static_cast<uint16_t>(buf[3]);
-
- return is;
- }
-
- uint8_t get_type() const { return type; }
- uint8_t get_code() const { return code; }
- uint16_t get_checksum() const { return checksum; }
-
- // code adapted from boost icmp example by Christopher M. Kohlhoff
- // --> boost license?!?
- void calc_checksum( const uint32_t body_checksum_part )
- {
- uint32_t sum = (type << 8) + code;
- sum += body_checksum_part;
-
- sum = (sum >> 16) + (sum & 0xFFFF);
- sum += (sum >> 16);
-
- checksum = static_cast<uint16_t>( ~sum );
- }
-
- std::ostream& write(std::ostream &os) const
- {
- uint8_t checksum_lsb = static_cast<uint8_t>(checksum & 0x00FF);
- uint8_t checksum_msb = static_cast<uint8_t>((checksum & 0xFF00) >> 8);
- os << type << code << checksum_msb << checksum_lsb;
- }
+ std::istream& read(std::istream &is);
+ std::ostream& write(std::ostream &os) const;
+
+ inline uint8_t get_type() const { return type; }
+ inline uint8_t get_code() const { return code; }
+ inline uint16_t get_checksum() const { return checksum; }
+
+ void calc_checksum( const uint32_t body_checksum_part );
// returns the amount of data represented by this class;
// for Icmp v4, the header is actually 8 bytes, see comments above
- uint16_t get_header_length() const
+ inline uint16_t get_header_length() const
{ return 4; }
- std::string to_string() const
- {
- std::stringstream buf;
- buf << "[Icmp header type=" << static_cast<int>(type)
- << ",code=" << static_cast<int>(code)
- << " (cksum:" << std::showbase << std::hex << checksum << ")]";
- return buf.str();
- }
+ std::string to_string() const;
+
+ friend std::istream& operator>>(
+ std::istream &is,
+ IcmpHeader &header
+ );
+ friend std::ostream& operator<<(
+ std::ostream &os,
+ const IcmpHeader &header
+ );
protected:
uint8_t type;
uint16_t checksum;
};
-
#endif
// (created using vim -- the world's best text editor)
bool write(std::ostream &os) const;
std::string to_string() const;
+
+ friend std::istream& operator>>(
+ std::istream &is,
+ IcmpPacket &packet
+ );
+ friend std::ostream& operator<<(
+ std::ostream &os,
+ const IcmpPacket &packet
+ );
+
+
};
typedef boost::shared_ptr<IcmpPacket> IcmpPacketItem;
add_executable(test_icmpv4header
test_icmpv4header.cpp
${CMAKE_SOURCE_DIR}/src/boost_assert_handler.cpp
- ${CMAKE_SOURCE_DIR}/src/icmp/icmpv4header.cpp
- ${CMAKE_SOURCE_DIR}/src/icmp/icmpmessage.cpp
- ${CMAKE_SOURCE_DIR}/src/icmp/icmpdestinationunreachablemessage.cpp
- ${CMAKE_SOURCE_DIR}/src/icmp/icmpechoreplymessage.cpp
- ${CMAKE_SOURCE_DIR}/src/icmp/icmpechorequestmessage.cpp
- ${CMAKE_SOURCE_DIR}/src/icmp/icmpgenericmessage.cpp
+ ${CMAKE_SOURCE_DIR}/src/icmp/icmpdata.cpp
+ ${CMAKE_SOURCE_DIR}/src/icmp/icmpheader.cpp
${CMAKE_SOURCE_DIR}/src/host/messagepayload.cpp
)
add_executable(test_icmpv6header
test_icmpv6header.cpp
${CMAKE_SOURCE_DIR}/src/boost_assert_handler.cpp
- ${CMAKE_SOURCE_DIR}/src/icmp/icmpv6header.cpp
- ${CMAKE_SOURCE_DIR}/src/icmp/icmpmessage.cpp
- ${CMAKE_SOURCE_DIR}/src/icmp/icmpdestinationunreachablemessage.cpp
- ${CMAKE_SOURCE_DIR}/src/icmp/icmpechoreplymessage.cpp
- ${CMAKE_SOURCE_DIR}/src/icmp/icmpechorequestmessage.cpp
- ${CMAKE_SOURCE_DIR}/src/icmp/icmpgenericmessage.cpp
+ ${CMAKE_SOURCE_DIR}/src/icmp/icmpdata.cpp
+ ${CMAKE_SOURCE_DIR}/src/icmp/icmpheader.cpp
${CMAKE_SOURCE_DIR}/src/host/messagepayload.cpp
)