);
}
-void BoostPinger::schedule_next_echo_request()
-{
- // Requests must be sent no less than one second apart.
- const int echo_request_interval_in_sec = 1;
- (void) IcmpPacketReceiveTimer.expires_at(
- TimeSent + seconds( echo_request_interval_in_sec )
- );
- IcmpPacketReceiveTimer.async_wait(
- boost::bind( &BoostPinger::start_send, this )
- );
-}
-
void BoostPinger::start_receive()
{
// Discard any data already in the buffer.
void BoostPinger::handle_timeout_icmp_packet()
{
- if ( RepliesCount == 0 )
+ // Check reply count as the timer handler
+ // is also called by Timer.cancel();
+ if (RepliesCount == 0)
{
- print_request_timeout();
+ GlobalLogger.info() << "Request timed out" << endl;
set_ping_status( PingStatus_FailureTimeout );
}
-
- schedule_next_echo_request();
}
void BoostPinger::handle_receive_icmp_packet( const size_t &bytes_transferred )
istream is( &ReplyBuffer );
if ( !is )
+ {
+ GlobalLogger.error() << "can't handle ReplyBuffer" << endl;
return;
+ }
// Decode the reply packet.
IcmpPacket icmp_packet;
- is >> icmp_packet;
+ if (!(is >> icmp_packet))
+ {
+ GlobalLogger.error() << "ignoring broken ICMP packet" << endl;
+ return;
+ }
// 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,
// ICMP packets from the host we had ping).
if ( icmp_packet.match(
IcmpType_EchoReply, Identifier, SequenceNumber,
- DestinationEndpoint.address()
- ) )
+ DestinationEndpoint.address())
+ )
{
- // If this is the first reply, interrupt the echo reply timeout.
- if ( RepliesCount == 0 )
- {
- (void) IcmpPacketReceiveTimer.cancel();
- }
-
++RepliesCount;
print_echo_reply( icmp_packet, bytes_transferred );
DestinationEndpoint.address()
) )
{
- // If this is the first reply, interrupt the echo reply timeout.
- if ( RepliesCount == 0 )
- {
- (void) IcmpPacketReceiveTimer.cancel();
- }
-
++RepliesCount;
-
print_destination_unreachable( icmp_packet );
set_ping_status( PingStatus_FailureDestinationUnreachable );
+ } else
+ {
+ GlobalLogger.notice() << "unknown ICMP reply" << endl;
}
- start_receive();
-}
-
-void BoostPinger::print_request_timeout() const
-{
- GlobalLogger.info() << "Request timed out" << endl;
+ IcmpPacketReceiveTimer.cancel();
}
void BoostPinger::print_echo_reply(
IcmpPacket create_echo_request( const uint16_t sequence_number ) const;
void send_echo_request( const IcmpPacket &icmp_packet );
void schedule_timeout_echo_reply();
- void schedule_next_echo_request();
void start_receive();
void handle_timeout_icmp_packet();
void handle_receive_icmp_packet( const std::size_t &bytes_transferred );
- void print_request_timeout() const;
void print_echo_reply(
const IcmpPacket &icmp_packet,
const std::size_t &bytes_transferred