using namespace std;
using boost::shared_ptr;
using boost::asio::io_service;
+using boost::asio::ip::icmp;
//-----------------------------------------------------------------------------
// PingerFactory
{
case PingProtocol_ICMP:
return shared_ptr<Pinger>(
- new IcmpPinger( io_serv, network_interface, ping_reply_timeout_in_sec )
+ new IcmpPinger( io_serv, icmp::v4(), network_interface, ping_reply_timeout_in_sec )
+ );
+ case PingProtocol_ICMPv6:
+ return shared_ptr<Pinger>(
+ new IcmpPinger( io_serv, icmp::v6(), network_interface, ping_reply_timeout_in_sec )
);
case PingProtocol_TCP:
return shared_ptr<Pinger>(
new TcpPinger( io_serv, network_interface, ping_reply_timeout_in_sec )
);
default:
- BOOST_ASSERT( false );
+ BOOST_ASSERT( !"Try to create a pinger from an invalid protocol" );
return shared_ptr<Pinger>();
}
}
enum PingProtocol
{
PingProtocol_First = 0,
- PingProtocol_ICMP = 0,
+ PingProtocol_ICMP = PingProtocol_First,
+ PingProtocol_ICMPv6,
PingProtocol_TCP,
PingProtocol_Last = PingProtocol_TCP
};
#include "icmp/icmpv6packet.h"
using namespace std;
+using boost::asio::ip::icmp;
using I2n::Logger::GlobalLogger;
//-----------------------------------------------------------------------------
// IcmpPacketFactory
//-----------------------------------------------------------------------------
+/**
+ * @brief
+ */
IcmpPacketItem IcmpPacketFactory::create_icmp_packet(
- const IpVersion version,
+ const icmp::socket::protocol_type &protocol,
istream &is
)
{
- BOOST_ASSERT( (IP_VERSION_4 == version) || (IP_VERSION_6 == version) );
+ BOOST_ASSERT( (icmp::v4() == protocol) || (icmp::v6() == protocol) );
IcmpPacketItem icmp_packet;
- switch ( version )
+ if ( icmp::v4() == protocol )
+ {
+ icmp_packet.reset( new Icmpv4Packet() );
+ }
+ else if ( icmp::v6() == protocol )
{
- case IP_VERSION_4:
- icmp_packet.reset(new Icmpv4Packet());
- break;
- case IP_VERSION_6:
- icmp_packet.reset(new Icmpv6Packet());
- break;
- default:
- BOOST_ASSERT( !"Invalid ICMP Packet Type." );
- break;
+ icmp_packet.reset( new Icmpv6Packet() );
+ }
+ else
+ {
+ BOOST_ASSERT( !"Invalid ICMP Packet Type." );
}
if ( !icmp_packet->read( is ) )
return icmp_packet;
}
+/**
+ * @brief
+ */
IcmpPacketItem IcmpPacketFactory::create_icmp_packet_echo_request(
- const IpVersion version,
+ const icmp::socket::protocol_type &protocol,
const uint16_t identifier,
const uint16_t sequence_number
)
{
- BOOST_ASSERT( (IP_VERSION_4 == version) || (IP_VERSION_6 == version) );
+ BOOST_ASSERT( (icmp::v4() == protocol) || (icmp::v6() == protocol) );
IcmpPacketItem icmp_packet;
- switch (version)
+ if ( icmp::v4() == protocol )
{
- case IP_VERSION_4:
- icmp_packet = create_icmpv4_packet_echo_request( identifier, sequence_number );
- break;
- case IP_VERSION_6:
- icmp_packet = create_icmpv6_packet_echo_request( identifier, sequence_number );
- break;
- default:
- BOOST_ASSERT( !"Invalid ICMP Packet Type." );
- break;
+ icmp_packet = create_icmpv4_packet_echo_request( identifier, sequence_number );
+ }
+ else if ( icmp::v6() == protocol )
+ {
+ icmp_packet = create_icmpv6_packet_echo_request( identifier, sequence_number );
+ }
+ else
+ {
+ BOOST_ASSERT( !"Invalid ICMP Packet Type." );
}
return icmp_packet;
}
+/**
+ * @brief
+ */
IcmpPacketItem IcmpPacketFactory::create_icmpv4_packet_echo_request(
const uint16_t identifier,
const uint16_t sequence_number
return icmp_packet;
}
+/**
+ * @brief
+ */
IcmpPacketItem IcmpPacketFactory::create_icmpv6_packet_echo_request(
const uint16_t identifier,
const uint16_t sequence_number
#include <iostream>
+#include <boost/asio.hpp>
+
#include "icmp/icmppacket.h"
-#include "ip/ipversion.h"
//-----------------------------------------------------------------------------
// IcmpPacketFactory
{
public:
static IcmpPacketItem create_icmp_packet(
- const IpVersion version,
+ const boost::asio::ip::icmp::socket::protocol_type &protocol,
std::istream &is
);
static IcmpPacketItem create_icmp_packet_echo_request(
- const IpVersion type,
+ const boost::asio::ip::icmp::socket::protocol_type &protocol,
const uint16_t identifier,
const uint16_t sequence_number
);
#include <logfunc.hpp>
#include "icmp/icmppacketfactory.h"
-#include "ip/ipversion.h"
using namespace std;
using boost::asio::const_buffers_1;
*/
IcmpPinger::IcmpPinger(
io_service &io_serv,
+ const icmp::socket::protocol_type &protocol,
const string &source_network_interface,
const int echo_reply_timeout_in_sec
) :
IoService( io_serv ),
DestinationEndpoint(),
- Socket( IoService, icmp::v4() ),
+ Socket( IoService, protocol ),
NetInterface( source_network_interface, Socket ),
IcmpPacketReceiveTimer( IoService ),
Identifier( 0 ),
++SequenceNumber;
IcmpPacketItem icmp_packet_echo_request = IcmpPacketFactory::create_icmp_packet_echo_request(
- IP_VERSION_4, Identifier, SequenceNumber );
+ icmp::v4(), Identifier, SequenceNumber );
BOOST_ASSERT( PingerStatus == PingStatus_NotSent );
send_echo_request( icmp_packet_echo_request );
}
// Decode the reply packet.
- IcmpPacketItem icmp_packet = IcmpPacketFactory::create_icmp_packet( IP_VERSION_4, is );
+ IcmpPacketItem icmp_packet = IcmpPacketFactory::create_icmp_packet( icmp::v4(), is );
if ( !icmp_packet )
{
GlobalLogger.notice() << "Warning: ignoring broken ICMP packet"
public:
IcmpPinger(
boost::asio::io_service &io_serv,
+ const boost::asio::ip::icmp::socket::protocol_type &protocol,
const std::string &source_network_interface,
const int echo_reply_timeout_in_sec
);
+++ /dev/null
-/*
-The software in this package is distributed under the GNU General
-Public License version 2 (with a special exception described below).
-
-A copy of GNU General Public License (GPL) is included in this distribution,
-in the file COPYING.GPL.
-
-As a special exception, if other files instantiate templates or use macros
-or inline functions from this file, or you compile this file and link it
-with other works to produce a work based on this file, this file
-does not by itself cause the resulting work to be covered
-by the GNU General Public License.
-
-However the source code for this file must still be made available
-in accordance with section (3) of the GNU General Public License.
-
-This exception does not invalidate any other reasons why a work based
-on this file might be covered by the GNU General Public License.
-*/
-
-#ifndef IP_VERSION_H
-#define IP_VERSION_H
-
-enum IpVersion
-{
- IP_VERSION_4,
- IP_VERSION_6
-};
-
-#endif // IP_VERSION_H
void init_logger()
{
- I2n::Logger::enable_syslog( I2n::Logger::Facility::User ); //lint !e1786
- I2n::Logger::set_log_level( default_log_level ); //lint !e534
+ I2n::Logger::enable_syslog( I2n::Logger::Facility::User ); //lint !e1786
+ I2n::Logger::set_log_level( default_log_level ); //lint !e534
}
void init_pingers(
PingSchedulerList *scheduler_list
)
{
- PingProtocol protocol = configuration->get_ping_protocol();
+ PingProtocol ping_protocol = configuration->get_ping_protocol();
string local_interface = configuration->get_source_network_interface();
string nameserver = configuration->get_nameserver();
int ping_fail_limit = configuration->get_ping_fail_limit();
local_interface,
destination_address,
destination_port,
- protocol,
+ ping_protocol,
ping_interval_in_sec,
ping_fail_limit,
nameserver,