ReplyReceived( false ),
EchoReplyTimeoutInSec( echo_reply_timeout_in_sec ),
PingerStatus( PingStatus_NotSent ),
- PingDoneCallback()
+ PingDoneCallback(),
+ LogPrefix("IcmpPinger")
{
// Create "unique" identifier
boost::uuids::random_generator random_gen;
BOOST_ASSERT( sizeof(Identifier) <= random_tag.size() );
memcpy( &Identifier, random_tag.data, sizeof(Identifier) );
+
+ LogPrefix = "IPing(no IP yet): ";
}
/**
void IcmpPinger::stop_pinging()
{
- GlobalLogger.debug()
- << DestinationEndpoint.address().to_string()
- << ": stop_pinging" << endl;
+ GlobalLogger.debug() << LogPrefix << "stop_pinging" << endl;
- GlobalLogger.debug()
- << DestinationEndpoint.address().to_string()
- << ": cancel timer" << endl;
+ GlobalLogger.debug() << LogPrefix << "cancel timer" << endl;
IcmpPacketReceiveTimer.cancel();
- GlobalLogger.debug()
- << DestinationEndpoint.address().to_string()
- << ": unregister" << endl;
+ GlobalLogger.debug() << LogPrefix << "unregister" << endl;
IcmpPingerItem icmp_item = boost::static_pointer_cast<IcmpPinger>( get_myself().lock() );
if ( icmp_item )
PacketDistributor->unregister_pinger( icmp_item );
} else
{
- GlobalLogger.warning()
- << DestinationEndpoint.address().to_string()
- << ": weak pointer to pinger broken is empty. Huh?" << endl;
+ GlobalLogger.warning() << LogPrefix
+ << "weak pointer to pinger broken is empty. Huh?" << endl;
}
}
{
uint16_t port = 0;
DestinationEndpoint = icmp::endpoint( destination_ip, port );
+
+ // update LogPrefix
+ std::stringstream temp;
+ temp << "IPing(" << DestinationEndpoint.address().to_string() << "): ";
+ LogPrefix = temp.str();
}
bool IcmpPinger::start_send()
ostream os( &request_buffer );
if ( !icmp_packet->write( os ) )
{
- GlobalLogger.error()
- << DestinationEndpoint.address().to_string()
- << ": fail writing ping data." << endl;
+ GlobalLogger.error() << LogPrefix << "fail writing ping data." << endl;
}
TimeSent = microsec_clock::universal_time();
size_t bytes_sent = 0;
try
{
- GlobalLogger.info()
- << DestinationEndpoint.address().to_string()
- << ": sending ping" << endl;
+ GlobalLogger.info() << LogPrefix << "sending ping" << endl;
const_buffers_1 data = request_buffer.data();
// Block until send the data
bytes_sent = PacketDistributor->get_socket()->send_to( data, DestinationEndpoint );
if ( bytes_sent != buffer_size( data ) )
{
- GlobalLogger.error()
- << DestinationEndpoint.address().to_string()
- << ": fail sending ping data." << endl;
+ GlobalLogger.error() << LogPrefix << "fail sending ping data."
+ << endl;
}
}
catch ( const exception &ex )
{
- GlobalLogger.error()
- << DestinationEndpoint.address().to_string()
- << ": fail sending ping data. " << ex.what() << endl;
+ GlobalLogger.error() << LogPrefix << "fail sending ping data. "
+ << ex.what() << endl;
}
ReplyReceived = false;
if ( error == boost::asio::error::operation_aborted )
{
if (! ReplyReceived)
- GlobalLogger.notice() << "Timer waiting for ICMP echo reply was cancelled!" << endl;
- // otherwise probably called by IcmpPacketReceiveTimer.cancel in handle_receive_icmp_packet!
+ GlobalLogger.notice() << LogPrefix
+ << "Timer waiting for ICMP echo reply was cancelled!"
+ << endl;
+ // otherwise probably called by IcmpPacketReceiveTimer.cancel in
+ // handle_receive_icmp_packet!
}
else
- GlobalLogger.notice() << "Error " << error << " waiting for ICMP echo reply!" << endl;
+ GlobalLogger.notice() << LogPrefix << "Error " << error
+ << " waiting for ICMP echo reply!" << endl;
// Still continue with rest of function, so PingStatus is updated and Callback executed
// when timer was cancelled
// is also called by Timer.cancel();
if ( !ReplyReceived )
{
- GlobalLogger.info()
- << DestinationEndpoint.address().to_string()
- << ": Request timed out" << endl;
+ GlobalLogger.info() << LogPrefix << "Request timed out" << endl;
set_ping_status( PingStatus_FailureTimeout );
}
Identifier, SequenceNumber,
DestinationEndpoint.address() ) )
{
- GlobalLogger.info()
- << DestinationEndpoint.address().to_string()
- << ": Received reply" << endl;
+ GlobalLogger.info() << LogPrefix << "Received reply" << endl;
ReplyReceived = true;
does_match = true;
Identifier, SequenceNumber,
DestinationEndpoint.address() ) )
{
- GlobalLogger.info()
- << DestinationEndpoint.address().to_string()
- << ": Received destination unreachable" << endl;
+ GlobalLogger.info() << LogPrefix
+ << "Received destination unreachable" << endl;
ReplyReceived = true;
does_match = true;
Identifier, SequenceNumber,
DestinationEndpoint.address() ) )
{
- GlobalLogger.info()
- << DestinationEndpoint.address().to_string()
- << ": Received time exceeded" << endl;
+ GlobalLogger.info() << LogPrefix
+ << "Received time exceeded" << endl;
ReplyReceived = true;
does_match = true;
}
else
{
- GlobalLogger.debug()
- << DestinationEndpoint.address().to_string()
- << ": Received packet that does not match or has wrong seq.nr"
+ GlobalLogger.debug() << LogPrefix
+ << "Received packet that does not match or has wrong seq.nr"
<< endl;
}
}
catch ( std::exception &exc)
{
- GlobalLogger.warning()
- << DestinationEndpoint.address().to_string()
- << ": Caught exception in packet interpretation: " << exc.what()
+ GlobalLogger.warning() << LogPrefix
+ << "Caught exception in packet interpretation: " << exc.what()
<< std::endl;
if ( IcmpPacketFactory::PacketDumpMode == DUMP_ALWAYS ||
IcmpPacketFactory::PacketDumpMode == DUMP_IF_ERROR )
}
catch ( ... )
{
- GlobalLogger.warning()
- << DestinationEndpoint.address().to_string()
- << ": Caught unspecified exception in packet interpretation!"
+ GlobalLogger.warning() << LogPrefix
+ << "Caught unspecified exception in packet interpretation!"
<< std::endl;
if ( IcmpPacketFactory::PacketDumpMode == DUMP_ALWAYS ||
IcmpPacketFactory::PacketDumpMode == DUMP_IF_ERROR )