Removed the address resolution from the pinger.
authorGuilherme Maciel Ferreira <guilherme.maciel.ferreira@intra2net.com>
Mon, 4 Apr 2011 10:14:30 +0000 (12:14 +0200)
committerGuilherme Maciel Ferreira <guilherme.maciel.ferreira@intra2net.com>
Mon, 4 Apr 2011 10:14:30 +0000 (12:14 +0200)
- There is a special  class to translate DNS to IP, thus makes no sense to keep this feature here, which simplify this class.

src/ping/boostpinger.cpp
src/ping/boostpinger.h

index f48f49c..ca1c921 100644 (file)
@@ -26,7 +26,6 @@ BoostPinger::BoostPinger(
         const int echo_reply_timeout_in_sec
 ) :
     IoService( io_serv ),
-    Resolver( io_serv ),
     DestinationEndpoint(),
     Socket( io_serv, icmp::v4() ),
     Timer( io_serv ),
@@ -44,22 +43,24 @@ BoostPinger::~BoostPinger()
 }
 
 /**
- * Pings a given destination address.
+ * Ping a destination address from an available local source.
  *
- * @param destination The address of the host where to ping.
+ * @param destination_ip The address of the host to ping.
  *
  * @return true if the ping was successfully performed, or false if the ping
- * was not replied due timeout.
+ * was not replied due a timeout.
  *
  * @note This method is synchronous, i.e. this method blocks and returns only
  * after the ping requested has finished or timed-out.
  */
-bool BoostPinger::ping( const string &destination )
+bool BoostPinger::ping( const string &destination_ip )
 {
-    BOOST_ASSERT( !destination.empty() );
+    BOOST_ASSERT( !destination_ip.empty() );
 
-    icmp::resolver::query query( icmp::v4(), destination, "" );
-    DestinationEndpoint = *Resolver.resolve( query );
+    int port = 0;
+    address destination_address = ip::address::from_string( destination_ip );
+    icmp::endpoint destination_endpoint( destination_address, port );
+    DestinationEndpoint = destination_endpoint;
 
     start_pinger();
 
index 9b383b0..1ce974f 100644 (file)
@@ -22,7 +22,7 @@ public:
     );
     virtual ~BoostPinger();
 
-    bool ping( const std::string &destination );
+    bool ping( const std::string &destination_ip );
 
 private:
     enum PingStatus
@@ -56,7 +56,6 @@ private:
 
 private:
     boost::asio::io_service &IoService;
-    boost::asio::ip::icmp::resolver Resolver;
     boost::asio::ip::icmp::endpoint DestinationEndpoint;
     boost::asio::ip::icmp::socket Socket;
     boost::asio::deadline_timer Timer;