#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/date_time/posix_time/posix_time_types.hpp>
+#include <boost/uuid/uuid.hpp>
+#include <boost/uuid/uuid_generators.hpp>
+
#include <logfunc.hpp>
#include "icmp/icmpchecksumcalculator.h"
DestinationEndpoint(),
Socket( io_serv, icmp::v4() ),
IcmpPacketReceiveTimer( io_serv ),
+ Identifier(0),
SequenceNumber( 0 ),
TimeSent( microsec_clock::universal_time() ),
ReplyBuffer(),
"with the local interface." << ::strerror( errno ) << endl;
}
+ // Create "unique" identifier
+ boost::uuids::random_generator random_gen;
+ boost::uuids::uuid random_tag = random_gen();
+
+ BOOST_ASSERT(sizeof(Identifier) <= random_tag.size());
+ memcpy(&Identifier, random_tag.data, sizeof(Identifier));
}
BoostPinger::~BoostPinger()
IcmpType type = IcmpType_EchoRequest;
uint8_t code = 0;
- uint16_t identifier = get_identifier();
IcmpChecksumCalculator calculator( icmp_data.begin(), icmp_data.end() );
uint16_t checksum = calculator.compute(
- type, code, identifier, sequence_number
+ type, code, Identifier, sequence_number
);
IcmpHeader icmp_header(
- type, code, checksum, identifier, sequence_number
+ type, code, checksum, Identifier, sequence_number
);
return IcmpPacket( icmp_header, icmp_data );
// expected sequence number, and destination host address (receive just the
// ICMP packets from the host we had ping).
if ( icmp_packet.match(
- IcmpType_EchoReply, get_identifier(), SequenceNumber,
+ IcmpType_EchoReply, Identifier, SequenceNumber,
DestinationEndpoint.address()
) )
{
set_ping_status( PingStatus_SuccessReply );
}
else if ( icmp_packet.match(
- IcmpType_DestinationUnreachable, get_identifier(), SequenceNumber,
+ IcmpType_DestinationUnreachable, Identifier, SequenceNumber,
DestinationEndpoint.address()
) )
{
PingerStatus = ping_status;
}
-uint16_t BoostPinger::get_identifier() const
-{
- return static_cast<uint16_t> ( ::getpid() );
-}
-
/**
* Avoid the socket to drop to another network interface if the destination
* is unreachable through the binded interface. Packets are sent only from