Ephemeral source port calculation moved to a method(), mirroring the destination...
authorGuilherme Maciel Ferreira <guilherme.maciel.ferreira@gmail.com>
Sun, 6 Nov 2011 21:47:24 +0000 (19:47 -0200)
committerGuilherme Maciel Ferreira <guilherme.maciel.ferreira@gmail.com>
Sun, 6 Nov 2011 21:47:24 +0000 (19:47 -0200)
src/tcp/tcppinger.cpp
src/tcp/tcppinger.h

index 1e9cc19..e055890 100644 (file)
@@ -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<uint16_t>( ( 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<uint16_t>( ( 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,
index 8ce101c..e7aa8b3 100644 (file)
@@ -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;