this->ConfigFileName = config_file_name;
}
-std::size_t Configuration::get_limit_to_notify() const
+uint Configuration::get_limit_to_notify() const
{
return LimitToNotify;
}
-void Configuration::set_limit_to_notify( const std::size_t limit_to_notify )
+void Configuration::set_limit_to_notify( const uint limit_to_notify )
{
BOOST_ASSERT( ( MinLimitToNotify <= limit_to_notify ) && ( limit_to_notify <= MaxLimitToNotify) );
std::string get_config_file_name() const;
void set_config_file_name( const std::string &config_file_name );
- std::size_t get_limit_to_notify() const;
- void set_limit_to_notify( const std::size_t limit_to_notify );
+ uint get_limit_to_notify() const;
+ void set_limit_to_notify( const uint limit_to_notify );
std::vector<HostItem> get_hosts() const;
void set_hosts( const std::vector<HostItem> &hosts_list );
private:
std::string ConfigFileName;
- std::size_t LimitToNotify;
+ uint LimitToNotify;
std::vector<HostItem> Hosts;
- const std::size_t MinLimitToNotify;
- const std::size_t MaxLimitToNotify;
+ const uint MinLimitToNotify;
+ const uint MaxLimitToNotify;
};
{
options_description options( "Configuration" );
options.add_options()
- ( LimitToNotifyCmdStr.c_str(), value<size_t>()->default_value( DefaultLimitToNotify ), LimitToNotifyCmdDesc.c_str() )
+ ( LimitToNotifyCmdStr.c_str(), value<uint>()->default_value( DefaultLimitToNotify ), LimitToNotifyCmdDesc.c_str() )
( HostNameCmdStr.c_str(), value< vector<string> >(), HostNameCmdDesc.c_str() )
- ( HostIntervalCmdStr.c_str(), value< vector<size_t> >(), HostIntervalCmdDesc.c_str() )
+ ( HostIntervalCmdStr.c_str(), value< vector<uint> >(), HostIntervalCmdDesc.c_str() )
;
return options;
if ( vm.count( LimitToNotifyCmdStr ) )
{
- size_t limit_to_notify = vm[ LimitToNotifyCmdStr ].as<size_t> ();
+ uint limit_to_notify = vm[ LimitToNotifyCmdStr ].as<uint> ();
Config.set_limit_to_notify( limit_to_notify );
cout << LimitToNotifyCmdStr << "=" << limit_to_notify << endl;
}
- size_t hosts_names_total = 0;
+ uint hosts_names_total = 0;
if ( vm.count( HostNameCmdStr ) )
{
vector<HostItem> hosts_list;
hosts_names_total = hosts_names.size();
}
- size_t hosts_interval_total = 0;
+ uint hosts_interval_total = 0;
if ( vm.count( HostIntervalCmdStr ) )
{
vector<HostItem> hosts_list = Config.get_hosts();
vector<HostItem>::iterator hosts_it = hosts_list.begin();
- vector<size_t> hosts_intervals = vm[ HostIntervalCmdStr ].as< vector<size_t> > ();
- BOOST_FOREACH( size_t host_interval, hosts_intervals )
+ vector<uint> hosts_intervals = vm[ HostIntervalCmdStr ].as< vector<uint> > ();
+ BOOST_FOREACH( uint host_interval, hosts_intervals )
{
HostItem host_item = *hosts_it;
host_item->set_interval( host_interval );
const std::string DefaultConfigFileName;
const std::string ConfigFileCmdStr;
const std::string ConfigFileCmdDesc;
- const std::size_t DefaultLimitToNotify;
+ const uint DefaultLimitToNotify;
const std::string LimitToNotifyCmdStr;
const std::string LimitToNotifyCmdDesc;
const std::string HostNameCmdStr;
const std::string HostNameCmdDesc;
- const std::size_t DefaultHostInterval;
+ const uint DefaultHostInterval;
const std::string HostIntervalCmdStr;
const std::string HostIntervalCmdDesc;
RepliesCount( 0 ),
TimesToPingTotal( 0 ),
MinTimesToPing( 0 ),
- MaxTimesToPing( numeric_limits<size_t>::max() )
+ MaxTimesToPing( numeric_limits<uint>::max() )
{
}
void BoostPinger::ping(
const string &destination,
- const size_t times_to_ping
+ const uint times_to_ping
)
{
BOOST_ASSERT( !destination.empty() );
{
IcmpPacket icmp_echo_request_packet = create_echo_request_packet();
- size_t times_already_pinged = SequenceNumber;
+ uint times_already_pinged = SequenceNumber;
if ( times_already_pinged <= TimesToPingTotal )
{
send_echo_request( icmp_echo_request_packet );
// Wait up to five seconds for a reply.
RepliesCount = 0;
- Timer.expires_at( TimeSent + seconds( 5 ) );
+ Timer.expires_at( TimeSent + seconds( 5 ) ); // TODO configurable:
Timer.async_wait( boost::bind( &BoostPinger::handle_timeout, this ) );
}
);
}
-void BoostPinger::handle_receive( const size_t &length )
+void BoostPinger::handle_receive( const size_t &bytes_transferred )
{
// The actual number of bytes received is committed to the buffer so that we
// can extract it using a std::istream object.
- ReplyBuffer.commit( length );
+ ReplyBuffer.commit( bytes_transferred );
// Decode the reply packet.
istream is( &ReplyBuffer );
++RepliesCount;
// Print out some information about the reply packet.
- print_echo_reply( icmp_packet, length );
+ print_echo_reply( icmp_packet, bytes_transferred );
}
start_receive();
void BoostPinger::print_echo_reply(
const IcmpPacket &icmp_packet,
- const size_t &length
+ const size_t &bytes_transferred
)
{
Ipv4Header ipv4_hdr = icmp_packet.get_ip_header();
IcmpHeader icmp_hdr = icmp_packet.get_icmp_header();
- size_t bytes_received = length - ipv4_hdr.get_header_length();
+ size_t bytes_received = bytes_transferred - ipv4_hdr.get_header_length();
string source_address = ipv4_hdr.get_source_address().to_string();
- size_t sequence_number = icmp_hdr.get_sequence_number();
- size_t ttl = ipv4_hdr.get_time_to_live();
+ uint sequence_number = icmp_hdr.get_sequence_number();
+ uint ttl = ipv4_hdr.get_time_to_live();
ptime now = microsec_clock::universal_time();
- size_t time = (now - TimeSent).total_milliseconds();
+ uint time = (now - TimeSent).total_milliseconds();
cout << bytes_received << " bytes "
<< "from " << source_address
void ping(
const std::string &destination,
- const std::size_t times_to_ping
+ const uint times_to_ping
);
private:
void handle_timeout();
void start_receive();
- void handle_receive( const std::size_t &length );
+ void handle_receive( const std::size_t &bytes_transferred );
void print_echo_reply(
const IcmpPacket &icmp_packet,
- const std::size_t &length
+ const std::size_t &bytes_transferred
);
uint16_t get_identifier();
uint16_t SequenceNumber;
boost::posix_time::ptime TimeSent;
boost::asio::streambuf ReplyBuffer;
- std::size_t RepliesCount;
- std::size_t TimesToPingTotal;
+ uint RepliesCount;
+ uint TimesToPingTotal;
- const std::size_t MinTimesToPing;
- const std::size_t MaxTimesToPing;
+ const uint MinTimesToPing;
+ const uint MaxTimesToPing;
};
this->Port = port;
}
-std::size_t Host::get_interval() const
+uint Host::get_interval() const
{
return Interval;
}
-void Host::set_interval( const std::size_t interval )
+void Host::set_interval( const uint interval )
{
- BOOST_ASSERT( ( 0 < interval ) && ( interval < std::numeric_limits<std::size_t>::max() ) );
+ BOOST_ASSERT( ( 0 < interval ) && ( interval < std::numeric_limits<uint>::max() ) );
this->Interval = interval;
}
uint16_t get_port() const;
void set_port( const uint16_t port );
- std::size_t get_interval() const;
- void set_interval( const std::size_t interval );
+ uint get_interval() const;
+ void set_interval( const uint interval );
std::vector<std::string> get_options() const;
void set_options( const std::vector<std::string> &options );
private:
std::string Address;
uint16_t Port;
- std::size_t Interval;
+ uint Interval;
std::vector<std::string> Options;
};
void PingCheck::start_pinging()
{
string destination = Host_.get_address();
- size_t ping_set_total = 3; // TODO configurable:
- size_t ping_set_count = 0;
+ uint ping_set_total = 3; // TODO configurable:
+ uint ping_set_count = 0;
while ( ping_set_count < ping_set_total )
{
ping_and_wait( destination );
void PingCheck::ping( const string &destination ) throw ( exception& )
{
- size_t times_to_ping = 3; // TODO configurable: this must be automatically selected
+ uint times_to_ping = 3; // TODO configurable: this must be automatically selected
boost::asio::io_service io_service;
BoostPinger pinger( io_service );
pinger.ping( destination, times_to_ping );
{
boost::asio::io_service io_service;
deadline_timer timer( io_service );
- size_t interval = Host_.get_interval(); // TODO configurable:
+ uint interval = Host_.get_interval(); // TODO configurable:
timer.expires_from_now( boost::posix_time::seconds( interval ) );
timer.wait();
}
#ifndef PINGER_H
#define PINGER_H
+#include <sys/types.h>
#include <string>
//-----------------------------------------------------------------------------
virtual void ping(
const std::string &destination,
- const std::size_t times_to_ping
+ const uint times_to_ping
) = 0;
};