From 6f6db38802ab501f068936855aae1cdfde537842 Mon Sep 17 00:00:00 2001 From: Guilherme Maciel Ferreira Date: Sun, 6 Nov 2011 19:47:24 -0200 Subject: [PATCH] Ephemeral source port calculation moved to a method(), mirroring the destination port. --- src/tcp/tcppinger.cpp | 9 ++++++++- src/tcp/tcppinger.h | 5 +++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/tcp/tcppinger.cpp b/src/tcp/tcppinger.cpp index 1e9cc19..e055890 100644 --- a/src/tcp/tcppinger.cpp +++ b/src/tcp/tcppinger.cpp @@ -133,6 +133,13 @@ uint32_t TcpPinger::get_destination_address() const return destination_ipv4_address; } +uint16_t TcpPinger::get_source_port() const +{ + uint16_t source_port = static_cast( ( random() % 16383 ) + 49152 ); // same as random() % 65536; + + return source_port; +} + uint16_t TcpPinger::get_destination_port() const { return DestinationEndpoint.port(); @@ -157,7 +164,7 @@ void TcpPinger::start_send() ++SequenceNumber; // Create an TCP header for an ACK request. - uint16_t source_port = static_cast( ( random() % 16383 ) + 49152 ); // same as random() % 65536; + uint16_t source_port = get_source_address(); uint16_t destination_port = get_destination_port(); TcpHeader tcp_header = create_ack_request( source_port, diff --git a/src/tcp/tcppinger.h b/src/tcp/tcppinger.h index 8ce101c..e7aa8b3 100644 --- a/src/tcp/tcppinger.h +++ b/src/tcp/tcppinger.h @@ -60,6 +60,7 @@ private: uint32_t get_source_address(); uint32_t get_destination_address() const; + uint16_t get_source_port() const; uint16_t get_destination_port() const; void set_destination_endpoint( @@ -99,9 +100,9 @@ private: /// the timer of TCP segment receive, triggers the timeout to avoid infinite /// wait boost::asio::deadline_timer TcpSegmentReceiveTimer; - /// ICMP packet identifier + /// TCP packet identifier uint16_t Identifier; - /// ICMP packet sequence_number + /// TCP packet sequence_number uint16_t SequenceNumber; /// the time when the last ICMP packet was sent boost::posix_time::ptime TimeSent; -- 1.7.1