From 865e078acab21dc3a0a70781365bf44b2813e14b Mon Sep 17 00:00:00 2001 From: Guilherme Maciel Ferreira Date: Sat, 12 Nov 2011 16:25:54 -0200 Subject: [PATCH] Using Boost.Asio address objects instead of primitive integer types - This allows switching to 128 bits IPv6 address --- src/tcp/tcppinger.cpp | 21 +++++++++------------ src/tcp/tcppinger.h | 4 ++-- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/tcp/tcppinger.cpp b/src/tcp/tcppinger.cpp index 73a453c..7ad30bc 100644 --- a/src/tcp/tcppinger.cpp +++ b/src/tcp/tcppinger.cpp @@ -38,7 +38,6 @@ on this file might be covered by the GNU General Public License. #include -#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( 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. diff --git a/src/tcp/tcppinger.h b/src/tcp/tcppinger.h index f85fc15..40b05ec 100644 --- a/src/tcp/tcppinger.h +++ b/src/tcp/tcppinger.h @@ -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; -- 1.7.1