It is working, and can be configurated, the ICMP ping over IPv6
authorGuilherme Maciel Ferreira <guilherme.maciel.ferreira@gmail.com>
Fri, 18 Nov 2011 02:00:21 +0000 (00:00 -0200)
committerGuilherme Maciel Ferreira <guilherme.maciel.ferreira@gmail.com>
Fri, 18 Nov 2011 02:00:21 +0000 (00:00 -0200)
src/host/pingprotocol.cpp
src/icmp/icmppinger.cpp
src/icmp/icmppinger.h

index 79ff9c5..548e157 100644 (file)
@@ -34,6 +34,7 @@ PingProtocol get_ping_protocol_from_string( string protocol_string )
 
     // TODO move to an init method
     protocol_string_map[ "ICMP" ] = PingProtocol_ICMP;
+    protocol_string_map[ "ICMPv6" ] = PingProtocol_ICMPv6;
     protocol_string_map[ "TCP" ] = PingProtocol_TCP;
 
     return protocol_string_map[ protocol_string ];
index f03057f..d2bb4db 100644 (file)
@@ -39,6 +39,12 @@ using I2n::Logger::GlobalLogger;
 
 /**
  * @brief Parameterized constructor.
+ *
+ * @param io_serv The @c io_service object to control this object.
+ * @param protocol The network layer protocol to use.
+ * @param source_network_interface The network interface name from where to
+ * send the packets.
+ * @param echo_reply_timeout_in_sec The amount of time to wait for a reply.
  */
 IcmpPinger::IcmpPinger(
         io_service &io_serv,
@@ -48,7 +54,8 @@ IcmpPinger::IcmpPinger(
 ) :
     IoService( io_serv ),
     DestinationEndpoint(),
-    Socket( IoService, protocol ),
+    Protocol( protocol ),
+    Socket( IoService, Protocol ),
     NetInterface( source_network_interface, Socket ),
     IcmpPacketReceiveTimer( IoService ),
     Identifier( 0 ),
@@ -123,7 +130,7 @@ void IcmpPinger::start_send()
     ++SequenceNumber;
 
     IcmpPacketItem icmp_packet_echo_request = IcmpPacketFactory::create_icmp_packet_echo_request(
-            icmp::v4(), Identifier, SequenceNumber );
+            Protocol, Identifier, SequenceNumber );
 
     BOOST_ASSERT( PingerStatus == PingStatus_NotSent );
     send_echo_request( icmp_packet_echo_request );
@@ -232,7 +239,7 @@ void IcmpPinger::handle_receive_icmp_packet( const size_t &bytes_transferred )
         }
 
         // Decode the reply packet.
-        IcmpPacketItem icmp_packet = IcmpPacketFactory::create_icmp_packet( icmp::v4(), is );
+        IcmpPacketItem icmp_packet = IcmpPacketFactory::create_icmp_packet( Protocol, is );
         if ( !icmp_packet )
         {
             GlobalLogger.notice() << "Warning: ignoring broken ICMP packet"
index 57b5edb..bb0f17f 100644 (file)
@@ -60,6 +60,8 @@ private:
     boost::asio::io_service &IoService;
     /// The destination host
     boost::asio::ip::icmp::endpoint DestinationEndpoint;
+    /// Network layer protocol used to ping, IPv4 or IPv6
+    boost::asio::ip::icmp::socket::protocol_type Protocol;
     /// The socket object
     boost::asio::ip::icmp::socket Socket;
     /// This object represents the network interface