Using Boost.Asio address objects instead of primitive integer types
authorGuilherme Maciel Ferreira <guilherme.maciel.ferreira@gmail.com>
Sat, 12 Nov 2011 18:25:54 +0000 (16:25 -0200)
committerGuilherme Maciel Ferreira <guilherme.maciel.ferreira@gmail.com>
Sat, 12 Nov 2011 18:26:37 +0000 (16:26 -0200)
- This allows switching to 128 bits IPv6 address

src/tcp/tcppinger.cpp
src/tcp/tcppinger.h

index 73a453c..7ad30bc 100644 (file)
@@ -38,7 +38,6 @@ on this file might be covered by the GNU General Public License.
 
 #include <logfunc.hpp>
 
-#include "ip/ipversion.h"
 #include "tcp/tcpsegmentfactory.h"
 
 using namespace std;
@@ -123,17 +122,14 @@ void TcpPinger::ping(
     start_receive();
 }
 
-uint32_t TcpPinger::get_source_address()
+address TcpPinger::get_source_address()
 {
-    return NetInterface.get_address();
+    return NetInterface.get_address( tcp_raw_protocol::v4() );
 }
 
-uint32_t TcpPinger::get_destination_address() const
+address TcpPinger::get_destination_address() const
 {
-    const sockaddr_in *destination_sockaddr = reinterpret_cast<const sockaddr_in *>( DestinationEndpoint.data() );
-    uint32_t destination_ipv4_address = htonl( destination_sockaddr->sin_addr.s_addr );
-
-    return destination_ipv4_address;
+    return DestinationEndpoint.address();
 }
 
 uint16_t TcpPinger::get_source_port() const
@@ -167,12 +163,13 @@ void TcpPinger::start_send()
     ++SequenceNumber;
 
     // Create an TCP header for an ACK request.
-    uint32_t source_address = get_source_address();
-    uint32_t destination_address = get_destination_address();
+    address source_address = get_source_address();
+    address destination_address = get_destination_address();
     uint16_t source_port = get_source_port();
     uint16_t destination_port = get_destination_port();
     TcpSegmentItem tcp_segment = TcpSegmentFactory::create_tcp_segment_ack_request(
-            IP_VERSION_4, source_address, destination_address,
+            tcp_raw_protocol::v4(),
+            source_address, destination_address,
             source_port, destination_port, SequenceNumber );
 
     send_ack_request( tcp_segment );
@@ -273,7 +270,7 @@ void TcpPinger::handle_receive_tcp_segment( const size_t &bytes_transferred )
         }
 
         // Decode the reply segment.
-        TcpSegmentItem tcp_segment = TcpSegmentFactory::create_tcp_segment( IP_VERSION_4, is );
+        TcpSegmentItem tcp_segment = TcpSegmentFactory::create_tcp_segment( tcp_raw_protocol::v4(), is );
 
         // Filter out only the TCP reset (RST) replies. Note that the sequence
         // number from RST does not match the sent ACK's sequence number.
index f85fc15..40b05ec 100644 (file)
@@ -56,8 +56,8 @@ public:
     );
 
 private:
-    uint32_t get_source_address();
-    uint32_t get_destination_address() const;
+    boost::asio::ip::address get_source_address();
+    boost::asio::ip::address get_destination_address() const;
 
     uint16_t get_source_port() const;
     uint16_t get_destination_port() const;