#include "icmpchecksumcalculator.h"
#include "icmpdata.h"
#include "icmpheader.h"
+#include "icmppacket.h"
#include "ipv4header.h"
#include "boostpinger.h"
//-----------------------------------------------------------------------------
BoostPinger::BoostPinger(
- boost::asio::io_service &io_service
+ boost::asio::io_service &io_service,
+ const uint echo_reply_timeout_in_sec
) :
IoService( io_service ),
Resolver( io_service ),
ReplyBuffer(),
RepliesCount( 0 ),
TimesToPingTotal( 0 ),
+ EchoReplyTimeoutInSec( echo_reply_timeout_in_sec ),
MinTimesToPing( 1 ),
MaxTimesToPing( numeric_limits<uint>::max() )
{
{
}
-/*
- * TODO document that this method blocks (is synchronous)
+/**
+ * Pings a given destination address
+ *
+ * @param destination The address of the host where to ping.
+ *
+ * @param times_to_ping The amount of times the destination host will be pinged.
+ *
+ * @note This method is synchronous, i.e. this method blocks and returns only
+ * after the amount of pings requested has finished or timed out.
*/
void BoostPinger::ping(
const string &destination,
{
// Wait up to N seconds for a reply.
RepliesCount = 0;
- const uint echo_reply_timeout_in_sec = 5; // TODO configurable: this is the timeout to WAIT FOR the ping before considering a timeout
- Timer.expires_at( TimeSent + seconds( echo_reply_timeout_in_sec ) );
+ Timer.expires_at( TimeSent + seconds( EchoReplyTimeoutInSec ) );
Timer.async_wait( boost::bind( &BoostPinger::handle_timeout, this ) );
}
uint time = (now - TimeSent).total_milliseconds();
cout << bytes_received << " bytes "
- << "from " << source_address
- << ": icmp_seq=" << sequence_number
- << " ttl=" << ttl
- << " time=" << time << " ms" << endl;
+ << "from " << source_address
+ << ": icmp_seq=" << sequence_number
+ << " ttl=" << ttl
+ << " time=" << time << " ms" << endl;
}
uint16_t BoostPinger::get_identifier() const
#define BOOSTPINGER_H
#include <boost/asio.hpp>
-
-#include "icmppacket.h"
#include "pinger.h"
+class IcmpPacket;
+
//-----------------------------------------------------------------------------
// BoostPinger
//-----------------------------------------------------------------------------
class BoostPinger : public Pinger
{
public:
- BoostPinger( boost::asio::io_service &io_service );
+ BoostPinger(
+ boost::asio::io_service &io_service,
+ const uint echo_reply_timeout_in_sec
+ );
virtual ~BoostPinger();
void ping(
boost::asio::streambuf ReplyBuffer;
uint RepliesCount;
uint TimesToPingTotal;
+ uint EchoReplyTimeoutInSec;
const uint MinTimesToPing;
const uint MaxTimesToPing;
{
BOOST_ASSERT( !destination.empty() );
- uint times_to_ping = 1; // TODO configurable: this must be automatically selected
+ uint echo_reply_timeout_in_sec = 5; // TODO configurable: this is the timeout to WAIT FOR the ping before considering a timeout
boost::asio::io_service io_service;
- BoostPinger pinger( io_service );
+ BoostPinger pinger( io_service, echo_reply_timeout_in_sec );
+ uint times_to_ping = 1; // TODO configurable: this must be automatically selected
pinger.ping( destination, times_to_ping );
update_ping_statistics();