@@ -129,29 +129,27 @@ impl From<libc::tcp_info> for TcpStats {
129129 fn from ( info : libc:: tcp_info ) -> Self {
130130 // On Linux, tcpi_snd_cwnd is in segments; convert to bytes using snd_mss.
131131 let cwnd = info. tcpi_snd_cwnd . saturating_mul ( info. tcpi_snd_mss ) ;
132- // The advertised receive window space is already in bytes.
132+ // Local advertised receive window ( bytes) .
133133 let rwnd = info. tcpi_rcv_space ;
134- let snd_wnd = info. tcpi_snd_wnd ;
135134
136135 // RTT fields are reported in microseconds.
137136 let last_rtt = Duration :: from_micros ( info. tcpi_rtt as u64 ) ;
138- let smoothed_rtt = Duration :: from_micros ( info. tcpi_rtt as u64 ) ; // best approximation available
137+ let smoothed_rtt = Duration :: from_micros ( info. tcpi_rtt as u64 ) ;
139138 let rtt_var = Duration :: from_micros ( info. tcpi_rttvar as u64 ) ;
140139
141- // Volumes; tcpi_bytes_acked/received are bytes, retrans_bytes is bytes .
142- let tx_bytes = info. tcpi_bytes_acked ;
143- let rx_bytes = info. tcpi_bytes_received ;
140+ // Volumes: approximate using segment counts * MSS .
141+ let tx_bytes = ( info. tcpi_segs_out as u64 ) . saturating_mul ( info . tcpi_snd_mss as u64 ) ;
142+ let rx_bytes = ( info. tcpi_segs_in as u64 ) . saturating_mul ( info . tcpi_rcv_mss as u64 ) ;
144143
145144 // Retransmissions
146- let retransmitted_bytes = info. tcpi_retrans_bytes ;
147145 let retransmitted_packets = info. tcpi_total_retrans as u64 ;
146+ let retransmitted_bytes = retransmitted_packets. saturating_mul ( info. tcpi_snd_mss as u64 ) ;
148147 // RTO is in microseconds.
149148 let rto = Duration :: from_micros ( info. tcpi_rto as u64 ) ;
150149
151150 Self {
152151 cwnd,
153152 rwnd,
154- snd_wnd,
155153 last_rtt,
156154 smoothed_rtt,
157155 rtt_var,
0 commit comments