From 8d5001e7b04be29100c938fbab695dcec001cc37 Mon Sep 17 00:00:00 2001 From: Guilherme Maciel Ferreira Date: Fri, 25 Feb 2011 12:10:30 +0100 Subject: [PATCH] Renamed the ipv4_header files to ipv4header, removed the '_' to keep the project standard --- src/CMakeLists.txt | 2 +- src/ping/boostpinger.cpp | 2 +- src/ping/ipv4_header.cpp | 103 ---------------------------------------------- src/ping/ipv4_header.h | 74 --------------------------------- src/ping/ipv4header.cpp | 103 ++++++++++++++++++++++++++++++++++++++++++++++ src/ping/ipv4header.h | 74 +++++++++++++++++++++++++++++++++ 6 files changed, 179 insertions(+), 179 deletions(-) delete mode 100644 src/ping/ipv4_header.cpp delete mode 100644 src/ping/ipv4_header.h create mode 100644 src/ping/ipv4header.cpp create mode 100644 src/ping/ipv4header.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8cdd690..c3f8d76 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -12,7 +12,7 @@ set( SOURCES ping/boostpinger.cpp ping/host.cpp ping/icmpheader.cpp - ping/ipv4_header.cpp + ping/ipv4header.cpp ping/pingcheck.cpp ping/pinger.cpp ping/pingmanager.cpp diff --git a/src/ping/boostpinger.cpp b/src/ping/boostpinger.cpp index 00497c9..4968f99 100644 --- a/src/ping/boostpinger.cpp +++ b/src/ping/boostpinger.cpp @@ -10,7 +10,7 @@ #include "icmpbody.h" #include "icmpchecksumcalculator.h" #include "icmpheader.h" -#include "ipv4_header.h" +#include "ipv4header.h" #include "boostpinger.h" namespace posix_time = boost::posix_time; diff --git a/src/ping/ipv4_header.cpp b/src/ping/ipv4_header.cpp deleted file mode 100644 index 682ea8c..0000000 --- a/src/ping/ipv4_header.cpp +++ /dev/null @@ -1,103 +0,0 @@ -#include "ipv4_header.h" - -//----------------------------------------------------------------------------- -// Ipv4Header -//----------------------------------------------------------------------------- - -Ipv4Header::Ipv4Header() -{ - std::fill( Rep, Rep + sizeof(Rep), 0 ); -} - -uint8_t Ipv4Header::get_version() const -{ - return (Rep[ 0 ] >> 4) & 0xF; -} - -uint16_t Ipv4Header::get_header_length() const -{ - return (Rep[ 0 ] & 0xF) * 4; -} - -uint8_t Ipv4Header::get_type_of_service() const -{ - return Rep[ 1 ]; -} - -uint16_t Ipv4Header::get_total_length() const -{ - return decode( 2, 3 ); -} - -uint16_t Ipv4Header::get_identification() const -{ - return decode( 4, 5 ); -} - -bool Ipv4Header::dont_fragment() const -{ - return (Rep[ 6 ] & 0x40) != 0; -} - -bool Ipv4Header::have_more_fragments() const -{ - return (Rep[ 6 ] & 0x20) != 0; -} - -uint16_t Ipv4Header::get_fragment_offset() const -{ - return decode( 6, 7 ) & 0x1FFF; -} - -unsigned int Ipv4Header::get_time_to_live() const -{ - return Rep[ 8 ]; -} - -uint8_t Ipv4Header::get_protocol() const -{ - return Rep[ 9 ]; -} - -uint16_t Ipv4Header::get_header_checksum() const -{ - return decode( 10, 11 ); -} - -boost::asio::ip::address_v4 Ipv4Header::get_source_address() const -{ - boost::asio::ip::address_v4::bytes_type bytes = { { - Rep[ 12 ], - Rep[ 13 ], - Rep[ 14 ], - Rep[ 15 ] } }; - return boost::asio::ip::address_v4( bytes ); -} - -boost::asio::ip::address_v4 Ipv4Header::get_destination_address() const -{ - boost::asio::ip::address_v4::bytes_type bytes = { { - Rep[ 16 ], - Rep[ 17 ], - Rep[ 18 ], - Rep[ 19 ] } }; - return boost::asio::ip::address_v4( bytes ); -} - -std::istream& operator>>( std::istream& is, Ipv4Header& header ) -{ - is.read( reinterpret_cast ( header.Rep ), 20 ); - if ( header.get_version() != 4 ) - is.setstate( std::ios::failbit ); - std::streamsize options_length = header.get_header_length() - 20; - if ( options_length < 0 || options_length > 40 ) - is.setstate( std::ios::failbit ); - else - is.read( reinterpret_cast ( header.Rep ) + 20, options_length ); - return is; -} - -uint16_t Ipv4Header::decode( int a, int b ) const -{ - return ((Rep[ a ] << 8) + Rep[ b ]); -} diff --git a/src/ping/ipv4_header.h b/src/ping/ipv4_header.h deleted file mode 100644 index 638a08a..0000000 --- a/src/ping/ipv4_header.h +++ /dev/null @@ -1,74 +0,0 @@ -#ifndef IPV4_HEADER_HPP -#define IPV4_HEADER_HPP - -#include -#include -#include - -//----------------------------------------------------------------------------- -// Ipv4Header -//----------------------------------------------------------------------------- -// IPv4 header format: -// -// 0 8 16 31 -// +-------+-------+---------------+------------------------------+ --- -// | | | | | ^ -// |version|header | type of | total length in bytes | | -// | (4) | length| service | | | -// +-------+-------+---------------+-+-+-+------------------------+ | -// | | | | | | | -// | identification |0|D|M| fragment offset | | -// | | |F|F| | | -// +---------------+---------------+-+-+-+------------------------+ | -// | | | | | -// | time to live | protocol | header checksum | 20 bytes -// | | | | | -// +---------------+---------------+------------------------------+ | -// | | | -// | source IPv4 address | | -// | | | -// +--------------------------------------------------------------+ | -// | | | -// | destination IPv4 address | | -// | | v -// +--------------------------------------------------------------+ --- -// | | ^ -// | | | -// / options (if any) / 0 - 40 -// / / bytes -// | | | -// | | v -// +--------------------------------------------------------------+ --- -// -//----------------------------------------------------------------------------- - -class Ipv4Header -{ -public: - Ipv4Header(); - - uint8_t get_version() const; - uint16_t get_header_length() const; - uint8_t get_type_of_service() const; - uint16_t get_total_length() const; - uint16_t get_identification() const; - - bool dont_fragment() const; - bool have_more_fragments() const; - uint16_t get_fragment_offset() const; - unsigned int get_time_to_live() const; - uint8_t get_protocol() const; - uint16_t get_header_checksum() const; - - boost::asio::ip::address_v4 get_source_address() const; - boost::asio::ip::address_v4 get_destination_address() const; - - friend std::istream& operator>>( std::istream& is, Ipv4Header& header ); - -private: - uint16_t decode( int a, int b ) const; - - uint8_t Rep[ 60 ]; -}; - -#endif // IPV4_HEADER_H diff --git a/src/ping/ipv4header.cpp b/src/ping/ipv4header.cpp new file mode 100644 index 0000000..028b717 --- /dev/null +++ b/src/ping/ipv4header.cpp @@ -0,0 +1,103 @@ +#include "ipv4header.h" + +//----------------------------------------------------------------------------- +// Ipv4Header +//----------------------------------------------------------------------------- + +Ipv4Header::Ipv4Header() +{ + std::fill( Rep, Rep + sizeof(Rep), 0 ); +} + +uint8_t Ipv4Header::get_version() const +{ + return (Rep[ 0 ] >> 4) & 0xF; +} + +uint16_t Ipv4Header::get_header_length() const +{ + return (Rep[ 0 ] & 0xF) * 4; +} + +uint8_t Ipv4Header::get_type_of_service() const +{ + return Rep[ 1 ]; +} + +uint16_t Ipv4Header::get_total_length() const +{ + return decode( 2, 3 ); +} + +uint16_t Ipv4Header::get_identification() const +{ + return decode( 4, 5 ); +} + +bool Ipv4Header::dont_fragment() const +{ + return (Rep[ 6 ] & 0x40) != 0; +} + +bool Ipv4Header::have_more_fragments() const +{ + return (Rep[ 6 ] & 0x20) != 0; +} + +uint16_t Ipv4Header::get_fragment_offset() const +{ + return decode( 6, 7 ) & 0x1FFF; +} + +unsigned int Ipv4Header::get_time_to_live() const +{ + return Rep[ 8 ]; +} + +uint8_t Ipv4Header::get_protocol() const +{ + return Rep[ 9 ]; +} + +uint16_t Ipv4Header::get_header_checksum() const +{ + return decode( 10, 11 ); +} + +boost::asio::ip::address_v4 Ipv4Header::get_source_address() const +{ + boost::asio::ip::address_v4::bytes_type bytes = { { + Rep[ 12 ], + Rep[ 13 ], + Rep[ 14 ], + Rep[ 15 ] } }; + return boost::asio::ip::address_v4( bytes ); +} + +boost::asio::ip::address_v4 Ipv4Header::get_destination_address() const +{ + boost::asio::ip::address_v4::bytes_type bytes = { { + Rep[ 16 ], + Rep[ 17 ], + Rep[ 18 ], + Rep[ 19 ] } }; + return boost::asio::ip::address_v4( bytes ); +} + +std::istream& operator>>( std::istream& is, Ipv4Header& header ) +{ + is.read( reinterpret_cast ( header.Rep ), 20 ); + if ( header.get_version() != 4 ) + is.setstate( std::ios::failbit ); + std::streamsize options_length = header.get_header_length() - 20; + if ( options_length < 0 || options_length > 40 ) + is.setstate( std::ios::failbit ); + else + is.read( reinterpret_cast ( header.Rep ) + 20, options_length ); + return is; +} + +uint16_t Ipv4Header::decode( int a, int b ) const +{ + return ((Rep[ a ] << 8) + Rep[ b ]); +} diff --git a/src/ping/ipv4header.h b/src/ping/ipv4header.h new file mode 100644 index 0000000..638a08a --- /dev/null +++ b/src/ping/ipv4header.h @@ -0,0 +1,74 @@ +#ifndef IPV4_HEADER_HPP +#define IPV4_HEADER_HPP + +#include +#include +#include + +//----------------------------------------------------------------------------- +// Ipv4Header +//----------------------------------------------------------------------------- +// IPv4 header format: +// +// 0 8 16 31 +// +-------+-------+---------------+------------------------------+ --- +// | | | | | ^ +// |version|header | type of | total length in bytes | | +// | (4) | length| service | | | +// +-------+-------+---------------+-+-+-+------------------------+ | +// | | | | | | | +// | identification |0|D|M| fragment offset | | +// | | |F|F| | | +// +---------------+---------------+-+-+-+------------------------+ | +// | | | | | +// | time to live | protocol | header checksum | 20 bytes +// | | | | | +// +---------------+---------------+------------------------------+ | +// | | | +// | source IPv4 address | | +// | | | +// +--------------------------------------------------------------+ | +// | | | +// | destination IPv4 address | | +// | | v +// +--------------------------------------------------------------+ --- +// | | ^ +// | | | +// / options (if any) / 0 - 40 +// / / bytes +// | | | +// | | v +// +--------------------------------------------------------------+ --- +// +//----------------------------------------------------------------------------- + +class Ipv4Header +{ +public: + Ipv4Header(); + + uint8_t get_version() const; + uint16_t get_header_length() const; + uint8_t get_type_of_service() const; + uint16_t get_total_length() const; + uint16_t get_identification() const; + + bool dont_fragment() const; + bool have_more_fragments() const; + uint16_t get_fragment_offset() const; + unsigned int get_time_to_live() const; + uint8_t get_protocol() const; + uint16_t get_header_checksum() const; + + boost::asio::ip::address_v4 get_source_address() const; + boost::asio::ip::address_v4 get_destination_address() const; + + friend std::istream& operator>>( std::istream& is, Ipv4Header& header ); + +private: + uint16_t decode( int a, int b ) const; + + uint8_t Rep[ 60 ]; +}; + +#endif // IPV4_HEADER_H -- 1.7.1