From a4c872dd589b7fd49864011534240c9cccb97294 Mon Sep 17 00:00:00 2001 From: Guilherme Maciel Ferreira Date: Sun, 13 Nov 2011 22:10:30 -0200 Subject: [PATCH] TCP pinger IP version is chosen by the pinger factory --- src/host/pingerfactory.cpp | 13 +++++++++++-- src/tcp/tcppinger.cpp | 14 ++++++++++++-- src/tcp/tcppinger.h | 1 + 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/host/pingerfactory.cpp b/src/host/pingerfactory.cpp index 7669d2e..fb85587 100644 --- a/src/host/pingerfactory.cpp +++ b/src/host/pingerfactory.cpp @@ -20,6 +20,8 @@ #include "host/pingerfactory.h" +#include + #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 PingerFactory::createPinger( ); case PingProtocol_TCP: return shared_ptr( - 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" ); diff --git a/src/tcp/tcppinger.cpp b/src/tcp/tcppinger.cpp index 7ad30bc..aeb4234 100644 --- a/src/tcp/tcppinger.cpp +++ b/src/tcp/tcppinger.cpp @@ -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(); diff --git a/src/tcp/tcppinger.h b/src/tcp/tcppinger.h index 40b05ec..e625114 100644 --- a/src/tcp/tcppinger.h +++ b/src/tcp/tcppinger.h @@ -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 ); -- 1.7.1