TCP pinger IP version is chosen by the pinger factory
authorGuilherme Maciel Ferreira <guilherme.maciel.ferreira@gmail.com>
Mon, 14 Nov 2011 00:10:30 +0000 (22:10 -0200)
committerGuilherme Maciel Ferreira <guilherme.maciel.ferreira@gmail.com>
Mon, 14 Nov 2011 00:10:30 +0000 (22:10 -0200)
src/host/pingerfactory.cpp
src/tcp/tcppinger.cpp
src/tcp/tcppinger.h

index 7669d2e..fb85587 100644 (file)
@@ -20,6 +20,8 @@
 
 #include "host/pingerfactory.h"
 
+#include <boost/asio/ip/tcp_raw_protocol.hpp>
+
 #include "icmp/icmppinger.h"
 #include "tcp/tcppinger.h"
 
@@ -27,15 +29,22 @@ using namespace std;
 using boost::shared_ptr;
 using boost::asio::io_service;
 using boost::asio::ip::icmp;
+using boost::asio::ip::tcp_raw_protocol;
 
 //-----------------------------------------------------------------------------
 // PingerFactory
 //-----------------------------------------------------------------------------
 
+/**
+ * @brief Default constructor.
+ */
 PingerFactory::PingerFactory()
 {
 }
 
+/**
+ * @brief Destructor.
+ */
 PingerFactory::~PingerFactory()
 {
 }
@@ -44,7 +53,7 @@ PingerFactory::~PingerFactory()
  * @brief Create a Pinger object suitable to the given protocol.
  *
  * @param protocol One of the available ping protocols.
- * @param io_serv The io_service object.
+ * @param io_serv The @c io_service object.
  * @param network_interface The network interface name from where the ping
  * packet will be sent.
  * @return a Pinger object to able to ping using the given protocol.
@@ -73,7 +82,7 @@ shared_ptr<Pinger> PingerFactory::createPinger(
         );
     case PingProtocol_TCP:
         return shared_ptr<Pinger>(
-                new TcpPinger( io_serv, network_interface, ping_reply_timeout_in_sec )
+                new TcpPinger( io_serv, tcp_raw_protocol::v4(), network_interface, ping_reply_timeout_in_sec )
         );
     default:
         BOOST_ASSERT( !"Try to create a pinger from an invalid protocol" );
index 7ad30bc..aeb4234 100644 (file)
@@ -56,14 +56,24 @@ using I2n::Logger::GlobalLogger;
 // TcpPinger
 //-----------------------------------------------------------------------------
 
+/**
+ * @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 segments.
+ * @param echo_reply_timeout_in_sec The amount of time to wait for a reply.
+ */
 TcpPinger::TcpPinger(
         io_service &io_serv,
+        const tcp_raw_protocol::socket::protocol_type &protocol,
         const string &source_network_interface_name,
         const int rst_reply_timeout_in_sec
 ) :
     IoService( io_serv ),
     DestinationEndpoint(),
-    Socket( IoService, tcp_raw_protocol::v4() ),
+    Socket( IoService, protocol ),
     NetInterface( source_network_interface_name, Socket ),
     TcpSegmentReceiveTimer( IoService ),
     Identifier( 0 ),
@@ -162,7 +172,7 @@ void TcpPinger::start_send()
 {
     ++SequenceNumber;
 
-    // Create an TCP header for an ACK request.
+    // Create a TCP header for an ACK request.
     address source_address = get_source_address();
     address destination_address = get_destination_address();
     uint16_t source_port = get_source_port();
index 40b05ec..e625114 100644 (file)
@@ -44,6 +44,7 @@ class TcpPinger : public Pinger
 public:
     TcpPinger(
             boost::asio::io_service &io_service,
+            const boost::asio::ip::tcp_raw_protocol::socket::protocol_type &protocol,
             const std::string &source_network_interface_name,
             const int rst_reply_timeout_in_sec
     );