set( CMAKE_VERBOSE_MAKEFILE OFF )
# add definitions, compiler switches, etc.
-add_definitions( -Werror -Wall -Wextra -O2 )
+add_definitions(
+ -Werror -Wall -Wextra -Weffc++ -O2 -DVERSION_STRING=${VERSION_STRING}
+)
# more build in the source folder
add_subdirectory( src )
#include "ipv4_header.h"
#include "boostpinger.h"
+namespace posix_time = boost::posix_time;
+
//-----------------------------------------------------------------------------
// BoostPinger
//-----------------------------------------------------------------------------
BoostPinger::BoostPinger(
boost::asio::io_service& io_service
) :
- resolver( io_service ), timer( io_service ), sequence_number( 0 ),
- num_replies( 0 ), socket( io_service, icmp::v4() )
+ resolver( io_service ),
+ destination_endpoint(),
+ socket( io_service, icmp::v4() ),
+ timer( io_service ),
+ sequence_number( 0 ),
+ time_sent( posix_time::microsec_clock::universal_time() ),
+ reply_buffer( 0 ),
+ num_replies( 0 )
{
#if 0
try
void BoostPinger::ping( const Host &host )
{
- std::string destination = host.getIp();
+ std::string destination = host.get_ip();
// TODO what if it is an DNS?
+ // TODO what about ping multiple hosts?
icmp::resolver::query query( icmp::v4(), destination, "" );
destination_endpoint = *resolver.resolve( query );
void BoostPinger::handle_timeout()
{
- if (num_replies == 0)
+ if ( num_replies == 0 )
std::cout << "Request timed out" << std::endl;
// Requests must be sent no less than one second apart.
// Wait for a reply. We prepare the buffer to receive up to 64KB.
socket.async_receive(
reply_buffer.prepare( 65536 ),
- boost::bind( &BoostPinger::handle_receive, this, _2 ) );
+ boost::bind( &BoostPinger::handle_receive, this, _2 )
+ );
}
void BoostPinger::handle_receive( std::size_t length )
// We can receive all ICMP packets received by the host, so we need to
// filter out only the echo replies that match the our identifier and
// expected sequence number.
- if (is && icmp_hdr.type() == IcmpHeader::EchoReply
+ if ( is && icmp_hdr.type() == IcmpHeader::EchoReply
&& icmp_hdr.identifier() == get_identifier()
- && icmp_hdr.sequence_number() == sequence_number)
+ && icmp_hdr.sequence_number() == sequence_number )
{
// If this is the first reply, interrupt the five second timeout.
- if (num_replies++ == 0)
+ if ( num_replies++ == 0 )
timer.cancel();
// Print out some information about the reply packet.
<< ipv4_hdr.source_address() << ": icmp_seq="
<< icmp_hdr.sequence_number() << ", ttl="
<< ipv4_hdr.time_to_live() << ", time="
- << (now - time_sent).total_milliseconds() << " ms"
- << std::endl;
+ << (now - time_sent).total_milliseconds() << " ms" << std::endl;
}
start_receive();
using boost::asio::ip::icmp;
using boost::asio::deadline_timer;
-namespace posix_time = boost::posix_time;
-
//-----------------------------------------------------------------------------
// BoostPinger
//-----------------------------------------------------------------------------
static uint16_t get_identifier();
+private:
icmp::resolver resolver;
icmp::endpoint destination_endpoint;
icmp::socket socket;
deadline_timer timer;
uint16_t sequence_number;
- posix_time::ptime time_sent;
+ boost::posix_time::ptime time_sent;
boost::asio::streambuf reply_buffer;
std::size_t num_replies;
#include "host.h"
-Host::Host( std::string address )
+Host::Host( std::string address ) :
+ ip( "" ),
+ dns( address ),
+ port( 0 ),
+ interval( 0 ),
+ options()
{
}
{
}
-std::string Host::getDns() const
+std::string Host::get_dns() const
{
return dns;
}
-void Host::setDns( std::string dns )
+void Host::set_dns( std::string dns )
{
this->dns = dns;
}
-uint32_t Host::getInterval() const
+uint32_t Host::get_interval() const
{
return interval;
}
-void Host::setInterval( uint32_t interval )
+void Host::set_interval( uint32_t interval )
{
this->interval = interval;
}
-std::string Host::getIp() const
+std::string Host::get_ip() const
{
return ip;
}
-void Host::setIp( std::string ip )
+void Host::set_ip( std::string ip )
{
this->ip = ip;
}
-std::vector<std::string> Host::getOptions() const
+std::vector<std::string> Host::get_options() const
{
return options;
}
-void Host::setOptions( std::vector<std::string> options )
+void Host::set_options( std::vector<std::string> options )
{
this->options = options;
}
-uint16_t Host::getPort() const
+uint16_t Host::get_port() const
{
return port;
}
-void Host::setPort( uint16_t port )
+void Host::set_port( uint16_t port )
{
this->port = port;
}
Host( std::string address );
virtual ~Host();
- std::string getDns() const;
- void setDns( std::string dns );
+ std::string get_dns() const;
+ void set_dns( std::string dns );
- uint32_t getInterval() const;
- void setInterval( uint32_t interval );
+ uint32_t get_interval() const;
+ void set_interval( uint32_t interval );
- std::string getIp() const;
- void setIp( std::string ip );
+ std::string get_ip() const;
+ void set_ip( std::string ip );
- std::vector<std::string> getOptions() const;
- void setOptions( std::vector<std::string> options );
+ std::vector<std::string> get_options() const;
+ void set_options( std::vector<std::string> options );
- uint16_t getPort() const;
- void setPort( uint16_t port );
+ uint16_t get_port() const;
+ void set_port( uint16_t port );
private:
std::string ip;
-#include "configurationreader.h"
-
#include "pingcheck.h"
PingCheck::PingCheck() :
- configuration( NULL )
+ configuration( NULL ),
+ ping_managers()
{
+}
+PingCheck::PingCheck( const PingCheck& ) :
+ configuration( NULL ),
+ ping_managers()
+{
}
PingCheck::~PingCheck()
{
}
-void PingCheck::read_configuration()
+PingCheck& PingCheck::operator=( const PingCheck& )
{
- // sends the program command line to be parsed by the configuration reader
- // check if it reads correctly
-
- //
- //
- //
- //
- //
- //
- //
- //
- //
- //
- //
+ return *this;
}
-void PingCheck::init_ping_managers()
+void PingCheck::init_ping_managers() const
{
// starts N ping managers with a host and an interval, this was read in configuration
// for each host in configuration
{
public:
PingCheck();
+ PingCheck( const PingCheck& other );
virtual ~PingCheck();
- void read_configuration();
- void init_ping_managers();
+ PingCheck& operator=( const PingCheck& other );
+
+ void init_ping_managers() const;
private:
Configuration *configuration;
#include "pingmanager.h"
-PingManager::PingManager()
+PingManager::PingManager() :
+ pinger( NULL ),
+ interval( 0 ),
+ host( NULL )
{
+}
+PingManager::PingManager( const PingManager& ) :
+ pinger( NULL ),
+ interval( 0 ),
+ host( NULL )
+{
}
PingManager::~PingManager()
{
}
-void PingManager::ping()
+PingManager& PingManager::operator=( const PingManager& )
+{
+ return *this;
+}
+
+void PingManager::ping() const
{
}
{
public:
PingManager();
+ PingManager( const PingManager& );
virtual ~PingManager();
- void ping();
+ PingManager& operator=( const PingManager& );
+
+ void ping() const;
private:
Pinger *pinger;