From 596889dbd3fa6cea2ce559bfd025fd3c2763056a Mon Sep 17 00:00:00 2001 From: Eduardo Broto Date: Tue, 10 Dec 2019 22:53:48 +0100 Subject: [PATCH 1/6] feat(interfaces): listen on all interfaces by default Specifying an interface is now optional. The interface is shown in the connections table. --- src/display/components/table.rs | 2 +- src/display/ui.rs | 6 +- src/display/ui_state.rs | 28 ++--- src/main.rs | 23 ++-- src/network/connection.rs | 4 +- src/network/sniffer.rs | 3 + src/network/utilization.rs | 22 ++-- src/os/shared.rs | 32 ++++-- src/tests/cases/raw_mode.rs | 122 ++++++++++---------- src/tests/cases/ui.rs | 192 ++++++++++++++++---------------- src/tests/fakes/fake_input.rs | 8 +- 11 files changed, 235 insertions(+), 207 deletions(-) diff --git a/src/display/components/table.rs b/src/display/components/table.rs index 74e207abb..aef914e01 100644 --- a/src/display/components/table.rs +++ b/src/display/components/table.rs @@ -64,7 +64,7 @@ impl<'a> Table<'a> { .iter() .map(|(connection, connection_data)| { vec![ - display_connection_string(&connection, &ip_to_host), + display_connection_string(&connection, &ip_to_host, &connection_data.interface), connection_data.process_name.to_string(), display_upload_and_download(*connection_data), ] diff --git a/src/display/ui.rs b/src/display/ui.rs index 3fcb092f5..fd137bce3 100644 --- a/src/display/ui.rs +++ b/src/display/ui.rs @@ -53,7 +53,11 @@ where write_to_stdout(format!( "connection: <{}> {} up/down Bps: {}/{} process: \"{}\"", timestamp, - display_connection_string(connection, ip_to_host), + display_connection_string( + connection, + ip_to_host, + &connection_network_data.interface + ), connection_network_data.total_bytes_uploaded, connection_network_data.total_bytes_downloaded, connection_network_data.process_name diff --git a/src/display/ui_state.rs b/src/display/ui_state.rs index a027ff450..d374c01cf 100644 --- a/src/display/ui_state.rs +++ b/src/display/ui_state.rs @@ -20,6 +20,7 @@ pub struct ConnectionData { pub total_bytes_downloaded: u128, pub total_bytes_uploaded: u128, pub process_name: String, + pub interface: String, } impl Bandwidth for ConnectionData { @@ -52,7 +53,7 @@ pub struct UIState { impl UIState { pub fn new( connections_to_procs: HashMap, - network_utilization: Utilization, + mut network_utilization: Utilization, ) -> Self { let mut processes: BTreeMap = BTreeMap::new(); let mut remote_addresses: BTreeMap = BTreeMap::new(); @@ -60,32 +61,27 @@ impl UIState { let mut total_bytes_downloaded: u128 = 0; let mut total_bytes_uploaded: u128 = 0; for (connection, process_name) in connections_to_procs { - if let Some(connection_bandwidth_utilization) = - network_utilization.connections.get(&connection) - { + if let Some(connection_info) = network_utilization.connections.remove(&connection) { let data_for_remote_address = remote_addresses .entry(connection.remote_socket.ip) .or_default(); let connection_data = connections.entry(connection).or_default(); let data_for_process = processes.entry(process_name.clone()).or_default(); - data_for_process.total_bytes_downloaded += - &connection_bandwidth_utilization.total_bytes_downloaded; - data_for_process.total_bytes_uploaded += - &connection_bandwidth_utilization.total_bytes_uploaded; + data_for_process.total_bytes_downloaded += connection_info.total_bytes_downloaded; + data_for_process.total_bytes_uploaded += connection_info.total_bytes_uploaded; data_for_process.connection_count += 1; - connection_data.total_bytes_downloaded += - &connection_bandwidth_utilization.total_bytes_downloaded; - connection_data.total_bytes_uploaded += - &connection_bandwidth_utilization.total_bytes_uploaded; + connection_data.total_bytes_downloaded += connection_info.total_bytes_downloaded; + connection_data.total_bytes_uploaded += connection_info.total_bytes_uploaded; connection_data.process_name = process_name; + connection_data.interface = connection_info.interface; data_for_remote_address.total_bytes_downloaded += - connection_bandwidth_utilization.total_bytes_downloaded; + connection_info.total_bytes_downloaded; data_for_remote_address.total_bytes_uploaded += - connection_bandwidth_utilization.total_bytes_uploaded; + connection_info.total_bytes_uploaded; data_for_remote_address.connection_count += 1; - total_bytes_downloaded += connection_bandwidth_utilization.total_bytes_downloaded; - total_bytes_uploaded += connection_bandwidth_utilization.total_bytes_uploaded; + total_bytes_downloaded += connection_info.total_bytes_downloaded; + total_bytes_uploaded += connection_info.total_bytes_uploaded; } } UIState { diff --git a/src/main.rs b/src/main.rs index 9022cfa80..34cc09c14 100644 --- a/src/main.rs +++ b/src/main.rs @@ -36,7 +36,7 @@ use structopt::StructOpt; pub struct Opt { #[structopt(short, long)] /// The network interface to listen on, eg. eth0 - interface: String, + interface: Option, #[structopt(short, long)] /// Machine friendlier output raw: bool, @@ -78,8 +78,8 @@ fn try_main() -> Result<(), failure::Error> { } pub struct OsInputOutput { - pub network_interface: NetworkInterface, - pub network_frames: Box, + pub network_interfaces: Vec, + pub network_frames: Vec>, pub get_open_sockets: fn() -> HashMap, pub keyboard_events: Box + Send>, pub dns_client: Option, @@ -105,7 +105,13 @@ where let raw_mode = opts.raw; - let mut sniffer = Sniffer::new(os_input.network_interface, os_input.network_frames); + let mut sniffers = os_input + .network_interfaces + .into_iter() + .zip(os_input.network_frames.into_iter()) + .map(|(iface, frames)| Sniffer::new(iface, frames)) + .collect::>(); + let network_utilization = Arc::new(Mutex::new(Utilization::new())); let ui = Arc::new(Mutex::new(Ui::new(terminal_backend))); @@ -196,10 +202,13 @@ where active_threads.push( thread::Builder::new() .name("sniffing_handler".to_string()) - .spawn(move || { - while running.load(Ordering::Acquire) { + .spawn(move || 'sniffing: loop { + for sniffer in sniffers.iter_mut() { if let Some(segment) = sniffer.next() { - network_utilization.lock().unwrap().update(&segment) + network_utilization.lock().unwrap().update(segment); + } + if !running.load(Ordering::Acquire) { + break 'sniffing; } } }) diff --git a/src/network/connection.rs b/src/network/connection.rs index f931d548f..bd42525ea 100644 --- a/src/network/connection.rs +++ b/src/network/connection.rs @@ -52,9 +52,11 @@ pub fn display_ip_or_host(ip: Ipv4Addr, ip_to_host: &HashMap) pub fn display_connection_string( connection: &Connection, ip_to_host: &HashMap, + interface: &str, ) -> String { format!( - ":{} => {}:{} ({})", + "<{}>:{} => {}:{} ({})", + interface, connection.local_port, display_ip_or_host(connection.remote_socket.ip, ip_to_host), connection.remote_socket.port, diff --git a/src/network/sniffer.rs b/src/network/sniffer.rs index 3ec6886d5..7b2d0b0ab 100644 --- a/src/network/sniffer.rs +++ b/src/network/sniffer.rs @@ -14,6 +14,7 @@ use ::std::net::{IpAddr, SocketAddr}; use crate::network::{Connection, Protocol}; pub struct Segment { + pub interface: String, pub connection: Connection, pub direction: Direction, pub data_length: u128, @@ -81,6 +82,7 @@ impl Sniffer { } _ => return None, }; + let interface = self.network_interface.name.clone(); let direction = Direction::new(&self.network_interface.ips, &ip_packet); let from = SocketAddr::new(IpAddr::V4(ip_packet.get_source()), source_port); let to = SocketAddr::new(IpAddr::V4(ip_packet.get_destination()), destination_port); @@ -90,6 +92,7 @@ impl Sniffer { Direction::Upload => Connection::new(to, source_port, protocol)?, }; Some(Segment { + interface, connection, data_length, direction, diff --git a/src/network/utilization.rs b/src/network/utilization.rs index cb0f12bde..6cd732f8f 100644 --- a/src/network/utilization.rs +++ b/src/network/utilization.rs @@ -3,14 +3,15 @@ use crate::network::{Connection, Direction, Segment}; use ::std::collections::HashMap; #[derive(Clone)] -pub struct TotalBandwidth { +pub struct ConnectionInfo { + pub interface: String, pub total_bytes_downloaded: u128, pub total_bytes_uploaded: u128, } #[derive(Clone)] pub struct Utilization { - pub connections: HashMap, + pub connections: HashMap, } impl Utilization { @@ -23,14 +24,15 @@ impl Utilization { self.connections.clear(); clone } - pub fn update(&mut self, seg: &Segment) { - let total_bandwidth = - self.connections - .entry(seg.connection.clone()) - .or_insert(TotalBandwidth { - total_bytes_downloaded: 0, - total_bytes_uploaded: 0, - }); + pub fn update(&mut self, seg: Segment) { + let total_bandwidth = self + .connections + .entry(seg.connection) + .or_insert(ConnectionInfo { + interface: seg.interface, + total_bytes_downloaded: 0, + total_bytes_uploaded: 0, + }); match seg.direction { Direction::Download => { total_bandwidth.total_bytes_downloaded += seg.data_length; diff --git a/src/os/shared.rs b/src/os/shared.rs index 8947ecb01..3a9aeee3e 100644 --- a/src/os/shared.rs +++ b/src/os/shared.rs @@ -34,11 +34,11 @@ fn get_datalink_channel( interface: &NetworkInterface, ) -> Result, failure::Error> { let mut config = Config::default(); - config.read_timeout = Some(time::Duration::new(0, 1)); + config.read_timeout = Some(time::Duration::new(0, 2_000_000)); match datalink::channel(interface, config) { Ok(Ethernet(_tx, rx)) => Ok(rx), Ok(_) => failure::bail!("Unknown interface type"), - Err(e) => failure::bail!("Failed to listen to network interface: {}", e), + Err(e) => failure::bail!("Failed to listen on network interface: {}", e), } } @@ -76,15 +76,27 @@ fn create_write_to_stdout() -> Box { }) } -pub fn get_input(interface_name: &str, resolve: bool) -> Result { - let keyboard_events = Box::new(KeyboardEvents); - let network_interface = match get_interface(interface_name) { - Some(interface) => interface, - None => { - failure::bail!("Cannot find interface {}", interface_name); +pub fn get_input( + interface_name: &Option, + resolve: bool, +) -> Result { + let network_interfaces = if let Some(name) = interface_name { + match get_interface(&name) { + Some(interface) => vec![interface], + None => { + failure::bail!("Cannot find interface {}", name); + } } + } else { + datalink::interfaces() }; - let network_frames = get_datalink_channel(&network_interface)?; + + let network_frames = network_interfaces + .iter() + .map(|iface| get_datalink_channel(iface)) + .collect::, _>>()?; + + let keyboard_events = Box::new(KeyboardEvents); let write_to_stdout = create_write_to_stdout(); let (on_winch, cleanup) = sigwinch(); let dns_client = if resolve { @@ -96,7 +108,7 @@ pub fn get_input(interface_name: &str, resolve: bool) -> Result>>) -> Box { + pub fn new(packets: Vec>>) -> Box { Box::new(NetworkFrames { packets, current_index: 0, @@ -135,14 +135,14 @@ pub fn get_open_sockets() -> HashMap { open_sockets } -pub fn get_interface() -> NetworkInterface { - NetworkInterface { +pub fn get_interfaces() -> Vec { + vec![NetworkInterface { name: String::from("interface_name"), index: 42, mac: None, ips: vec![IpNetwork::V4("10.0.0.2".parse().unwrap())], flags: 42, - } + }] } pub fn create_fake_on_winch(should_send_winch_event: bool) -> Box { From 9fa4a155580eb9c25e4957ed828b96e847fe6e83 Mon Sep 17 00:00:00 2001 From: Eduardo Broto Date: Tue, 10 Dec 2019 22:57:03 +0100 Subject: [PATCH 2/6] test(interfaces): update snapshots to expect the interface name --- .../cases/snapshots/raw_mode__bi_directional_traffic.snap | 2 +- ...aw_mode__multiple_connections_from_remote_address.snap | 4 ++-- ...ple_packets_of_traffic_from_different_connections.snap | 4 ++-- ...ultiple_packets_of_traffic_from_single_connection.snap | 2 +- ...ode__multiple_processes_with_multiple_connections.snap | 8 ++++---- src/tests/cases/snapshots/raw_mode__no_resolve_mode.snap | 8 ++++---- .../cases/snapshots/raw_mode__one_packet_of_traffic.snap | 2 +- .../raw_mode__one_process_with_multiple_connections.snap | 4 ++-- ...w_mode__sustained_traffic_from_multiple_processes.snap | 8 ++++---- ...ed_traffic_from_multiple_processes_bi_directional.snap | 8 ++++---- .../raw_mode__sustained_traffic_from_one_process.snap | 4 ++-- .../snapshots/raw_mode__traffic_with_host_names.snap | 8 ++++---- .../cases/snapshots/ui__bi_directional_traffic-2.snap | 2 +- .../ui__layout_full_width_under_30_height-2.snap | 8 ++++---- .../ui__layout_under_120_width_full_height-2.snap | 8 ++++---- .../ui__layout_under_150_width_full_height-2.snap | 8 ++++---- .../ui__layout_under_150_width_under_30_height-2.snap | 8 ++++---- .../ui__multiple_connections_from_remote_address-2.snap | 4 ++-- ...e_packets_of_traffic_from_different_connections-2.snap | 4 ++-- ...tiple_packets_of_traffic_from_single_connection-2.snap | 2 +- ...i__multiple_processes_with_multiple_connections-2.snap | 8 ++++---- src/tests/cases/snapshots/ui__no_resolve_mode-2.snap | 4 ++-- src/tests/cases/snapshots/ui__no_resolve_mode.snap | 4 ++-- .../cases/snapshots/ui__one_packet_of_traffic-2.snap | 2 +- .../ui__one_process_with_multiple_connections-2.snap | 4 ++-- .../ui__sustained_traffic_from_multiple_processes.snap | 4 ++-- ..._traffic_from_multiple_processes_bi_directional-2.snap | 4 ++-- ...ed_traffic_from_multiple_processes_bi_directional.snap | 4 ++-- .../snapshots/ui__sustained_traffic_from_one_process.snap | 2 +- .../cases/snapshots/ui__traffic_with_host_names-2.snap | 4 ++-- .../cases/snapshots/ui__traffic_with_host_names.snap | 4 ++-- .../cases/snapshots/ui__traffic_with_winch_event-3.snap | 2 +- 32 files changed, 76 insertions(+), 76 deletions(-) diff --git a/src/tests/cases/snapshots/raw_mode__bi_directional_traffic.snap b/src/tests/cases/snapshots/raw_mode__bi_directional_traffic.snap index 1acbf9337..c85c6f909 100644 --- a/src/tests/cases/snapshots/raw_mode__bi_directional_traffic.snap +++ b/src/tests/cases/snapshots/raw_mode__bi_directional_traffic.snap @@ -3,6 +3,6 @@ source: src/tests/cases/raw_mode.rs expression: formatted --- process: "1" up/down Bps: 49/51 connections: 1 -connection: :443 => 1.1.1.1:12345 (tcp) up/down Bps: 49/51 process: "1" +connection: :443 => 1.1.1.1:12345 (tcp) up/down Bps: 49/51 process: "1" remote_address: 1.1.1.1 up/down Bps: 49/51 connections: 1 diff --git a/src/tests/cases/snapshots/raw_mode__multiple_connections_from_remote_address.snap b/src/tests/cases/snapshots/raw_mode__multiple_connections_from_remote_address.snap index 9fb82d0e7..254216512 100644 --- a/src/tests/cases/snapshots/raw_mode__multiple_connections_from_remote_address.snap +++ b/src/tests/cases/snapshots/raw_mode__multiple_connections_from_remote_address.snap @@ -4,7 +4,7 @@ expression: formatted --- process: "1" up/down Bps: 0/44 connections: 1 process: "3" up/down Bps: 0/51 connections: 1 -connection: :443 => 1.1.1.1:12345 (tcp) up/down Bps: 0/44 process: "1" -connection: :443 => 1.1.1.1:12346 (tcp) up/down Bps: 0/51 process: "3" +connection: :443 => 1.1.1.1:12345 (tcp) up/down Bps: 0/44 process: "1" +connection: :443 => 1.1.1.1:12346 (tcp) up/down Bps: 0/51 process: "3" remote_address: 1.1.1.1 up/down Bps: 0/95 connections: 2 diff --git a/src/tests/cases/snapshots/raw_mode__multiple_packets_of_traffic_from_different_connections.snap b/src/tests/cases/snapshots/raw_mode__multiple_packets_of_traffic_from_different_connections.snap index 89ea24ead..b897a0a95 100644 --- a/src/tests/cases/snapshots/raw_mode__multiple_packets_of_traffic_from_different_connections.snap +++ b/src/tests/cases/snapshots/raw_mode__multiple_packets_of_traffic_from_different_connections.snap @@ -4,8 +4,8 @@ expression: formatted --- process: "1" up/down Bps: 0/44 connections: 1 process: "4" up/down Bps: 0/39 connections: 1 -connection: :443 => 1.1.1.1:12345 (tcp) up/down Bps: 0/44 process: "1" -connection: :443 => 2.2.2.2:54321 (tcp) up/down Bps: 0/39 process: "4" +connection: :443 => 1.1.1.1:12345 (tcp) up/down Bps: 0/44 process: "1" +connection: :443 => 2.2.2.2:54321 (tcp) up/down Bps: 0/39 process: "4" remote_address: 1.1.1.1 up/down Bps: 0/44 connections: 1 remote_address: 2.2.2.2 up/down Bps: 0/39 connections: 1 diff --git a/src/tests/cases/snapshots/raw_mode__multiple_packets_of_traffic_from_single_connection.snap b/src/tests/cases/snapshots/raw_mode__multiple_packets_of_traffic_from_single_connection.snap index d87cfb5e6..cbbdc0a1b 100644 --- a/src/tests/cases/snapshots/raw_mode__multiple_packets_of_traffic_from_single_connection.snap +++ b/src/tests/cases/snapshots/raw_mode__multiple_packets_of_traffic_from_single_connection.snap @@ -3,6 +3,6 @@ source: src/tests/cases/raw_mode.rs expression: formatted --- process: "1" up/down Bps: 0/91 connections: 1 -connection: :443 => 1.1.1.1:12345 (tcp) up/down Bps: 0/91 process: "1" +connection: :443 => 1.1.1.1:12345 (tcp) up/down Bps: 0/91 process: "1" remote_address: 1.1.1.1 up/down Bps: 0/91 connections: 1 diff --git a/src/tests/cases/snapshots/raw_mode__multiple_processes_with_multiple_connections.snap b/src/tests/cases/snapshots/raw_mode__multiple_processes_with_multiple_connections.snap index 59c2a8636..15476f0c0 100644 --- a/src/tests/cases/snapshots/raw_mode__multiple_processes_with_multiple_connections.snap +++ b/src/tests/cases/snapshots/raw_mode__multiple_processes_with_multiple_connections.snap @@ -6,10 +6,10 @@ process: "1" up/down Bps: 0/44 connections: 1 process: "2" up/down Bps: 0/42 connections: 1 process: "4" up/down Bps: 0/53 connections: 1 process: "5" up/down Bps: 0/45 connections: 1 -connection: :443 => 1.1.1.1:12345 (tcp) up/down Bps: 0/44 process: "1" -connection: :443 => 2.2.2.2:54321 (tcp) up/down Bps: 0/53 process: "4" -connection: :443 => 3.3.3.3:1337 (tcp) up/down Bps: 0/45 process: "5" -connection: :443 => 4.4.4.4:1337 (tcp) up/down Bps: 0/42 process: "2" +connection: :443 => 1.1.1.1:12345 (tcp) up/down Bps: 0/44 process: "1" +connection: :443 => 2.2.2.2:54321 (tcp) up/down Bps: 0/53 process: "4" +connection: :443 => 3.3.3.3:1337 (tcp) up/down Bps: 0/45 process: "5" +connection: :443 => 4.4.4.4:1337 (tcp) up/down Bps: 0/42 process: "2" remote_address: 1.1.1.1 up/down Bps: 0/44 connections: 1 remote_address: 2.2.2.2 up/down Bps: 0/53 connections: 1 remote_address: 3.3.3.3 up/down Bps: 0/45 connections: 1 diff --git a/src/tests/cases/snapshots/raw_mode__no_resolve_mode.snap b/src/tests/cases/snapshots/raw_mode__no_resolve_mode.snap index f51ce55b5..87ca81980 100644 --- a/src/tests/cases/snapshots/raw_mode__no_resolve_mode.snap +++ b/src/tests/cases/snapshots/raw_mode__no_resolve_mode.snap @@ -4,14 +4,14 @@ expression: formatted --- process: "1" up/down Bps: 57/61 connections: 1 process: "5" up/down Bps: 34/37 connections: 1 -connection: :443 => 1.1.1.1:12345 (tcp) up/down Bps: 57/61 process: "1" -connection: :443 => 3.3.3.3:1337 (tcp) up/down Bps: 34/37 process: "5" +connection: :443 => 1.1.1.1:12345 (tcp) up/down Bps: 57/61 process: "1" +connection: :443 => 3.3.3.3:1337 (tcp) up/down Bps: 34/37 process: "5" remote_address: 1.1.1.1 up/down Bps: 57/61 connections: 1 remote_address: 3.3.3.3 up/down Bps: 34/37 connections: 1 process: "1" up/down Bps: 37/36 connections: 1 process: "5" up/down Bps: 32/46 connections: 1 -connection: :443 => 1.1.1.1:12345 (tcp) up/down Bps: 37/36 process: "1" -connection: :443 => 3.3.3.3:1337 (tcp) up/down Bps: 32/46 process: "5" +connection: :443 => 1.1.1.1:12345 (tcp) up/down Bps: 37/36 process: "1" +connection: :443 => 3.3.3.3:1337 (tcp) up/down Bps: 32/46 process: "5" remote_address: 1.1.1.1 up/down Bps: 37/36 connections: 1 remote_address: 3.3.3.3 up/down Bps: 32/46 connections: 1 diff --git a/src/tests/cases/snapshots/raw_mode__one_packet_of_traffic.snap b/src/tests/cases/snapshots/raw_mode__one_packet_of_traffic.snap index 4241a92e7..f5b78d93f 100644 --- a/src/tests/cases/snapshots/raw_mode__one_packet_of_traffic.snap +++ b/src/tests/cases/snapshots/raw_mode__one_packet_of_traffic.snap @@ -3,6 +3,6 @@ source: src/tests/cases/raw_mode.rs expression: formatted --- process: "1" up/down Bps: 42/0 connections: 1 -connection: :443 => 1.1.1.1:12345 (tcp) up/down Bps: 42/0 process: "1" +connection: :443 => 1.1.1.1:12345 (tcp) up/down Bps: 42/0 process: "1" remote_address: 1.1.1.1 up/down Bps: 42/0 connections: 1 diff --git a/src/tests/cases/snapshots/raw_mode__one_process_with_multiple_connections.snap b/src/tests/cases/snapshots/raw_mode__one_process_with_multiple_connections.snap index 37105ac24..1e9cfba5d 100644 --- a/src/tests/cases/snapshots/raw_mode__one_process_with_multiple_connections.snap +++ b/src/tests/cases/snapshots/raw_mode__one_process_with_multiple_connections.snap @@ -4,8 +4,8 @@ expression: formatted --- process: "1" up/down Bps: 0/44 connections: 1 process: "5" up/down Bps: 0/48 connections: 1 -connection: :443 => 1.1.1.1:12345 (tcp) up/down Bps: 0/44 process: "1" -connection: :443 => 3.3.3.3:1337 (tcp) up/down Bps: 0/48 process: "5" +connection: :443 => 1.1.1.1:12345 (tcp) up/down Bps: 0/44 process: "1" +connection: :443 => 3.3.3.3:1337 (tcp) up/down Bps: 0/48 process: "5" remote_address: 1.1.1.1 up/down Bps: 0/44 connections: 1 remote_address: 3.3.3.3 up/down Bps: 0/48 connections: 1 diff --git a/src/tests/cases/snapshots/raw_mode__sustained_traffic_from_multiple_processes.snap b/src/tests/cases/snapshots/raw_mode__sustained_traffic_from_multiple_processes.snap index 339c1bef3..6b5dfdf7c 100644 --- a/src/tests/cases/snapshots/raw_mode__sustained_traffic_from_multiple_processes.snap +++ b/src/tests/cases/snapshots/raw_mode__sustained_traffic_from_multiple_processes.snap @@ -4,14 +4,14 @@ expression: formatted --- process: "1" up/down Bps: 0/44 connections: 1 process: "5" up/down Bps: 0/39 connections: 1 -connection: :443 => 1.1.1.1:12345 (tcp) up/down Bps: 0/44 process: "1" -connection: :443 => 3.3.3.3:1337 (tcp) up/down Bps: 0/39 process: "5" +connection: :443 => 1.1.1.1:12345 (tcp) up/down Bps: 0/44 process: "1" +connection: :443 => 3.3.3.3:1337 (tcp) up/down Bps: 0/39 process: "5" remote_address: 1.1.1.1 up/down Bps: 0/44 connections: 1 remote_address: 3.3.3.3 up/down Bps: 0/39 connections: 1 process: "1" up/down Bps: 0/61 connections: 1 process: "5" up/down Bps: 0/51 connections: 1 -connection: :443 => 1.1.1.1:12345 (tcp) up/down Bps: 0/61 process: "1" -connection: :443 => 3.3.3.3:1337 (tcp) up/down Bps: 0/51 process: "5" +connection: :443 => 1.1.1.1:12345 (tcp) up/down Bps: 0/61 process: "1" +connection: :443 => 3.3.3.3:1337 (tcp) up/down Bps: 0/51 process: "5" remote_address: 1.1.1.1 up/down Bps: 0/61 connections: 1 remote_address: 3.3.3.3 up/down Bps: 0/51 connections: 1 diff --git a/src/tests/cases/snapshots/raw_mode__sustained_traffic_from_multiple_processes_bi_directional.snap b/src/tests/cases/snapshots/raw_mode__sustained_traffic_from_multiple_processes_bi_directional.snap index f51ce55b5..87ca81980 100644 --- a/src/tests/cases/snapshots/raw_mode__sustained_traffic_from_multiple_processes_bi_directional.snap +++ b/src/tests/cases/snapshots/raw_mode__sustained_traffic_from_multiple_processes_bi_directional.snap @@ -4,14 +4,14 @@ expression: formatted --- process: "1" up/down Bps: 57/61 connections: 1 process: "5" up/down Bps: 34/37 connections: 1 -connection: :443 => 1.1.1.1:12345 (tcp) up/down Bps: 57/61 process: "1" -connection: :443 => 3.3.3.3:1337 (tcp) up/down Bps: 34/37 process: "5" +connection: :443 => 1.1.1.1:12345 (tcp) up/down Bps: 57/61 process: "1" +connection: :443 => 3.3.3.3:1337 (tcp) up/down Bps: 34/37 process: "5" remote_address: 1.1.1.1 up/down Bps: 57/61 connections: 1 remote_address: 3.3.3.3 up/down Bps: 34/37 connections: 1 process: "1" up/down Bps: 37/36 connections: 1 process: "5" up/down Bps: 32/46 connections: 1 -connection: :443 => 1.1.1.1:12345 (tcp) up/down Bps: 37/36 process: "1" -connection: :443 => 3.3.3.3:1337 (tcp) up/down Bps: 32/46 process: "5" +connection: :443 => 1.1.1.1:12345 (tcp) up/down Bps: 37/36 process: "1" +connection: :443 => 3.3.3.3:1337 (tcp) up/down Bps: 32/46 process: "5" remote_address: 1.1.1.1 up/down Bps: 37/36 connections: 1 remote_address: 3.3.3.3 up/down Bps: 32/46 connections: 1 diff --git a/src/tests/cases/snapshots/raw_mode__sustained_traffic_from_one_process.snap b/src/tests/cases/snapshots/raw_mode__sustained_traffic_from_one_process.snap index 3acef988a..393bd1471 100644 --- a/src/tests/cases/snapshots/raw_mode__sustained_traffic_from_one_process.snap +++ b/src/tests/cases/snapshots/raw_mode__sustained_traffic_from_one_process.snap @@ -3,9 +3,9 @@ source: src/tests/cases/raw_mode.rs expression: formatted --- process: "1" up/down Bps: 0/44 connections: 1 -connection: :443 => 1.1.1.1:12345 (tcp) up/down Bps: 0/44 process: "1" +connection: :443 => 1.1.1.1:12345 (tcp) up/down Bps: 0/44 process: "1" remote_address: 1.1.1.1 up/down Bps: 0/44 connections: 1 process: "1" up/down Bps: 0/51 connections: 1 -connection: :443 => 1.1.1.1:12345 (tcp) up/down Bps: 0/51 process: "1" +connection: :443 => 1.1.1.1:12345 (tcp) up/down Bps: 0/51 process: "1" remote_address: 1.1.1.1 up/down Bps: 0/51 connections: 1 diff --git a/src/tests/cases/snapshots/raw_mode__traffic_with_host_names.snap b/src/tests/cases/snapshots/raw_mode__traffic_with_host_names.snap index 406126b2b..b6c4b851b 100644 --- a/src/tests/cases/snapshots/raw_mode__traffic_with_host_names.snap +++ b/src/tests/cases/snapshots/raw_mode__traffic_with_host_names.snap @@ -4,14 +4,14 @@ expression: formatted --- process: "1" up/down Bps: 57/61 connections: 1 process: "5" up/down Bps: 34/37 connections: 1 -connection: :443 => one.one.one.one:12345 (tcp) up/down Bps: 57/61 process: "1" -connection: :443 => three.three.three.three:1337 (tcp) up/down Bps: 34/37 process: "5" +connection: :443 => one.one.one.one:12345 (tcp) up/down Bps: 57/61 process: "1" +connection: :443 => three.three.three.three:1337 (tcp) up/down Bps: 34/37 process: "5" remote_address: one.one.one.one up/down Bps: 57/61 connections: 1 remote_address: three.three.three.three up/down Bps: 34/37 connections: 1 process: "1" up/down Bps: 37/36 connections: 1 process: "5" up/down Bps: 32/46 connections: 1 -connection: :443 => one.one.one.one:12345 (tcp) up/down Bps: 37/36 process: "1" -connection: :443 => three.three.three.three:1337 (tcp) up/down Bps: 32/46 process: "5" +connection: :443 => one.one.one.one:12345 (tcp) up/down Bps: 37/36 process: "1" +connection: :443 => three.three.three.three:1337 (tcp) up/down Bps: 32/46 process: "5" remote_address: one.one.one.one up/down Bps: 37/36 connections: 1 remote_address: three.three.three.three up/down Bps: 32/46 connections: 1 diff --git a/src/tests/cases/snapshots/ui__bi_directional_traffic-2.snap b/src/tests/cases/snapshots/ui__bi_directional_traffic-2.snap index 3826749ed..816d1bfc5 100644 --- a/src/tests/cases/snapshots/ui__bi_directional_traffic-2.snap +++ b/src/tests/cases/snapshots/ui__bi_directional_traffic-2.snap @@ -6,7 +6,7 @@ expression: "&terminal_draw_events_mirror[1]" - 1 1 49Bps/51Bps :443 => 1.1.1.1:12345 (tcp) 1 49Bps/51Bps + 1 1 49Bps/51Bps :443 => 1.1.1.1:12345 (tcp) 1 49Bps/51Bps diff --git a/src/tests/cases/snapshots/ui__layout_full_width_under_30_height-2.snap b/src/tests/cases/snapshots/ui__layout_full_width_under_30_height-2.snap index 041da7f06..97d93b100 100644 --- a/src/tests/cases/snapshots/ui__layout_full_width_under_30_height-2.snap +++ b/src/tests/cases/snapshots/ui__layout_full_width_under_30_height-2.snap @@ -6,10 +6,10 @@ expression: "&terminal_draw_events_mirror[1]" - 4 1 0Bps/53Bps :443 => 2.2.2.2:54321 (tcp) 4 0Bps/53Bps - 5 1 0Bps/45Bps :443 => 3.3.3.3:1337 (tcp) 5 0Bps/45Bps - 1 1 0Bps/44Bps :443 => 1.1.1.1:12345 (tcp) 1 0Bps/44Bps - 2 1 0Bps/42Bps :443 => 4.4.4.4:1337 (tcp) 2 0Bps/42Bps + 4 1 0Bps/53Bps :443 => 2.2.2.2:54321 (tcp) 4 0Bps/53Bps + 5 1 0Bps/45Bps :443 => 3.3.3.3:1337 (tcp) 5 0Bps/45Bps + 1 1 0Bps/44Bps :443 => 1.1.1.1:12345 (tcp) 1 0Bps/44Bps + 2 1 0Bps/42Bps :443 => 4.4.4.4:1337 (tcp) 2 0Bps/42Bps diff --git a/src/tests/cases/snapshots/ui__layout_under_120_width_full_height-2.snap b/src/tests/cases/snapshots/ui__layout_under_120_width_full_height-2.snap index c53e396c8..d9252ecb6 100644 --- a/src/tests/cases/snapshots/ui__layout_under_120_width_full_height-2.snap +++ b/src/tests/cases/snapshots/ui__layout_under_120_width_full_height-2.snap @@ -30,10 +30,10 @@ expression: "&terminal_draw_events_mirror[1]" - :443 => 2.2.2.2:54321 (tcp) 4 0Bps/53Bps - :443 => 3.3.3.3:1337 (tcp) 5 0Bps/45Bps - :443 => 1.1.1.1:12345 (tcp) 1 0Bps/44Bps - :443 => 4.4.4.4:1337 (tcp) 2 0Bps/42Bps + :443 => 2.2.2.2:54321 (tcp) 4 0Bps/53Bps + :443 => 3.3.3.3:1337 (tcp) 5 0Bps/45Bps + :443 => 1.1.1.1:12345 (tcp) 1 0Bps/44Bps + :443 => 4.4.4.4:1337 (tcp) 2 0Bps/42Bps diff --git a/src/tests/cases/snapshots/ui__layout_under_150_width_full_height-2.snap b/src/tests/cases/snapshots/ui__layout_under_150_width_full_height-2.snap index 25dc02919..c5f7297a1 100644 --- a/src/tests/cases/snapshots/ui__layout_under_150_width_full_height-2.snap +++ b/src/tests/cases/snapshots/ui__layout_under_150_width_full_height-2.snap @@ -30,10 +30,10 @@ expression: "&terminal_draw_events_mirror[1]" - :443 => 2.2.2.2:54321 (tcp) 0Bps/53Bps 2.2.2.2 0Bps/53Bps - :443 => 3.3.3.3:1337 (tcp) 0Bps/45Bps 3.3.3.3 0Bps/45Bps - :443 => 1.1.1.1:12345 (tcp) 0Bps/44Bps 1.1.1.1 0Bps/44Bps - :443 => 4.4.4.4:1337 (tcp) 0Bps/42Bps 4.4.4.4 0Bps/42Bps + :443 => 2.2.2.2:54321 (t 0Bps/53Bps 2.2.2.2 0Bps/53Bps + :443 => 3.3.3.3:1337 (tc 0Bps/45Bps 3.3.3.3 0Bps/45Bps + :443 => 1.1.1.1:12345 (t 0Bps/44Bps 1.1.1.1 0Bps/44Bps + :443 => 4.4.4.4:1337 (tc 0Bps/42Bps 4.4.4.4 0Bps/42Bps diff --git a/src/tests/cases/snapshots/ui__layout_under_150_width_under_30_height-2.snap b/src/tests/cases/snapshots/ui__layout_under_150_width_under_30_height-2.snap index f7d4db17e..c9ff385c3 100644 --- a/src/tests/cases/snapshots/ui__layout_under_150_width_under_30_height-2.snap +++ b/src/tests/cases/snapshots/ui__layout_under_150_width_under_30_height-2.snap @@ -6,10 +6,10 @@ expression: "&terminal_draw_events_mirror[1]" - 4 0Bps/53Bps :443 => 2.2.2.2:54321 (tcp) 0Bps/53Bps - 5 0Bps/45Bps :443 => 3.3.3.3:1337 (tcp) 0Bps/45Bps - 1 0Bps/44Bps :443 => 1.1.1.1:12345 (tcp) 0Bps/44Bps - 2 0Bps/42Bps :443 => 4.4.4.4:1337 (tcp) 0Bps/42Bps + 4 0Bps/53Bps :443 => 2.2.2.2:54321 (t 0Bps/53Bps + 5 0Bps/45Bps :443 => 3.3.3.3:1337 (tc 0Bps/45Bps + 1 0Bps/44Bps :443 => 1.1.1.1:12345 (t 0Bps/44Bps + 2 0Bps/42Bps :443 => 4.4.4.4:1337 (tc 0Bps/42Bps diff --git a/src/tests/cases/snapshots/ui__multiple_connections_from_remote_address-2.snap b/src/tests/cases/snapshots/ui__multiple_connections_from_remote_address-2.snap index d5717d46b..586a7cf09 100644 --- a/src/tests/cases/snapshots/ui__multiple_connections_from_remote_address-2.snap +++ b/src/tests/cases/snapshots/ui__multiple_connections_from_remote_address-2.snap @@ -6,8 +6,8 @@ expression: "&terminal_draw_events_mirror[1]" - 3 1 0Bps/51Bps :443 => 1.1.1.1:12346 (tcp) 3 0Bps/51Bps - 1 1 0Bps/44Bps :443 => 1.1.1.1:12345 (tcp) 1 0Bps/44Bps + 3 1 0Bps/51Bps :443 => 1.1.1.1:12346 (tcp) 3 0Bps/51Bps + 1 1 0Bps/44Bps :443 => 1.1.1.1:12345 (tcp) 1 0Bps/44Bps diff --git a/src/tests/cases/snapshots/ui__multiple_packets_of_traffic_from_different_connections-2.snap b/src/tests/cases/snapshots/ui__multiple_packets_of_traffic_from_different_connections-2.snap index 0d38ea6d0..343d059ba 100644 --- a/src/tests/cases/snapshots/ui__multiple_packets_of_traffic_from_different_connections-2.snap +++ b/src/tests/cases/snapshots/ui__multiple_packets_of_traffic_from_different_connections-2.snap @@ -6,8 +6,8 @@ expression: "&terminal_draw_events_mirror[1]" - 1 1 0Bps/44Bps :443 => 1.1.1.1:12345 (tcp) 1 0Bps/44Bps - 4 1 0Bps/39Bps :443 => 2.2.2.2:54321 (tcp) 4 0Bps/39Bps + 1 1 0Bps/44Bps :443 => 1.1.1.1:12345 (tcp) 1 0Bps/44Bps + 4 1 0Bps/39Bps :443 => 2.2.2.2:54321 (tcp) 4 0Bps/39Bps diff --git a/src/tests/cases/snapshots/ui__multiple_packets_of_traffic_from_single_connection-2.snap b/src/tests/cases/snapshots/ui__multiple_packets_of_traffic_from_single_connection-2.snap index bfb8b7c21..b0851617d 100644 --- a/src/tests/cases/snapshots/ui__multiple_packets_of_traffic_from_single_connection-2.snap +++ b/src/tests/cases/snapshots/ui__multiple_packets_of_traffic_from_single_connection-2.snap @@ -6,7 +6,7 @@ expression: "&terminal_draw_events_mirror[1]" - 1 1 0Bps/91Bps :443 => 1.1.1.1:12345 (tcp) 1 0Bps/91Bps + 1 1 0Bps/91Bps :443 => 1.1.1.1:12345 (tcp) 1 0Bps/91Bps diff --git a/src/tests/cases/snapshots/ui__multiple_processes_with_multiple_connections-2.snap b/src/tests/cases/snapshots/ui__multiple_processes_with_multiple_connections-2.snap index 147870985..e3c6cf48d 100644 --- a/src/tests/cases/snapshots/ui__multiple_processes_with_multiple_connections-2.snap +++ b/src/tests/cases/snapshots/ui__multiple_processes_with_multiple_connections-2.snap @@ -6,10 +6,10 @@ expression: "&terminal_draw_events_mirror[1]" - 4 1 0Bps/53Bps :443 => 2.2.2.2:54321 (tcp) 4 0Bps/53Bps - 5 1 0Bps/45Bps :443 => 3.3.3.3:1337 (tcp) 5 0Bps/45Bps - 1 1 0Bps/44Bps :443 => 1.1.1.1:12345 (tcp) 1 0Bps/44Bps - 2 1 0Bps/42Bps :443 => 4.4.4.4:1337 (tcp) 2 0Bps/42Bps + 4 1 0Bps/53Bps :443 => 2.2.2.2:54321 (tcp) 4 0Bps/53Bps + 5 1 0Bps/45Bps :443 => 3.3.3.3:1337 (tcp) 5 0Bps/45Bps + 1 1 0Bps/44Bps :443 => 1.1.1.1:12345 (tcp) 1 0Bps/44Bps + 2 1 0Bps/42Bps :443 => 4.4.4.4:1337 (tcp) 2 0Bps/42Bps diff --git a/src/tests/cases/snapshots/ui__no_resolve_mode-2.snap b/src/tests/cases/snapshots/ui__no_resolve_mode-2.snap index add0b12ba..f34cc98dc 100644 --- a/src/tests/cases/snapshots/ui__no_resolve_mode-2.snap +++ b/src/tests/cases/snapshots/ui__no_resolve_mode-2.snap @@ -6,8 +6,8 @@ expression: "&terminal_draw_events_mirror[2]" - 5 32 46 3 3 3 3 3 7 (tcp) 5 32 46 - 1 7 6 1 1 1 1 2 45 (tcp) 1 7 6 + 5 32 46 3 3 3 3 3 7 (tcp) 5 32 46 + 1 7 6 1 1 1 1 2 45 (tcp) 1 7 6 diff --git a/src/tests/cases/snapshots/ui__no_resolve_mode.snap b/src/tests/cases/snapshots/ui__no_resolve_mode.snap index cc1366c73..aed8ad111 100644 --- a/src/tests/cases/snapshots/ui__no_resolve_mode.snap +++ b/src/tests/cases/snapshots/ui__no_resolve_mode.snap @@ -6,8 +6,8 @@ expression: "&terminal_draw_events_mirror[1]" - 1 1 57Bps/61Bps :443 => 1.1.1.1:12345 (tcp) 1 57Bps/61Bps - 5 1 34Bps/37Bps :443 => 3.3.3.3:1337 (tcp) 5 34Bps/37Bps + 1 1 57Bps/61Bps :443 => 1.1.1.1:12345 (tcp) 1 57Bps/61Bps + 5 1 34Bps/37Bps :443 => 3.3.3.3:1337 (tcp) 5 34Bps/37Bps diff --git a/src/tests/cases/snapshots/ui__one_packet_of_traffic-2.snap b/src/tests/cases/snapshots/ui__one_packet_of_traffic-2.snap index cf1ed0a4a..2dc5ea0b7 100644 --- a/src/tests/cases/snapshots/ui__one_packet_of_traffic-2.snap +++ b/src/tests/cases/snapshots/ui__one_packet_of_traffic-2.snap @@ -6,7 +6,7 @@ expression: "&terminal_draw_events_mirror[1]" - 1 1 42Bps/0Bps :443 => 1.1.1.1:12345 (tcp) 1 42Bps/0Bps + 1 1 42Bps/0Bps :443 => 1.1.1.1:12345 (tcp) 1 42Bps/0Bps diff --git a/src/tests/cases/snapshots/ui__one_process_with_multiple_connections-2.snap b/src/tests/cases/snapshots/ui__one_process_with_multiple_connections-2.snap index f0f77681e..31d20344c 100644 --- a/src/tests/cases/snapshots/ui__one_process_with_multiple_connections-2.snap +++ b/src/tests/cases/snapshots/ui__one_process_with_multiple_connections-2.snap @@ -6,8 +6,8 @@ expression: "&terminal_draw_events_mirror[1]" - 5 1 0Bps/48Bps :443 => 3.3.3.3:1337 (tcp) 5 0Bps/48Bps - 1 1 0Bps/44Bps :443 => 1.1.1.1:12345 (tcp) 1 0Bps/44Bps + 5 1 0Bps/48Bps :443 => 3.3.3.3:1337 (tcp) 5 0Bps/48Bps + 1 1 0Bps/44Bps :443 => 1.1.1.1:12345 (tcp) 1 0Bps/44Bps diff --git a/src/tests/cases/snapshots/ui__sustained_traffic_from_multiple_processes.snap b/src/tests/cases/snapshots/ui__sustained_traffic_from_multiple_processes.snap index 0d78e4c65..30584be77 100644 --- a/src/tests/cases/snapshots/ui__sustained_traffic_from_multiple_processes.snap +++ b/src/tests/cases/snapshots/ui__sustained_traffic_from_multiple_processes.snap @@ -6,8 +6,8 @@ expression: "&terminal_draw_events_mirror[1]" - 1 1 0Bps/44Bps :443 => 1.1.1.1:12345 (tcp) 1 0Bps/44Bps - 5 1 0Bps/39Bps :443 => 3.3.3.3:1337 (tcp) 5 0Bps/39Bps + 1 1 0Bps/44Bps :443 => 1.1.1.1:12345 (tcp) 1 0Bps/44Bps + 5 1 0Bps/39Bps :443 => 3.3.3.3:1337 (tcp) 5 0Bps/39Bps diff --git a/src/tests/cases/snapshots/ui__sustained_traffic_from_multiple_processes_bi_directional-2.snap b/src/tests/cases/snapshots/ui__sustained_traffic_from_multiple_processes_bi_directional-2.snap index add0b12ba..f34cc98dc 100644 --- a/src/tests/cases/snapshots/ui__sustained_traffic_from_multiple_processes_bi_directional-2.snap +++ b/src/tests/cases/snapshots/ui__sustained_traffic_from_multiple_processes_bi_directional-2.snap @@ -6,8 +6,8 @@ expression: "&terminal_draw_events_mirror[2]" - 5 32 46 3 3 3 3 3 7 (tcp) 5 32 46 - 1 7 6 1 1 1 1 2 45 (tcp) 1 7 6 + 5 32 46 3 3 3 3 3 7 (tcp) 5 32 46 + 1 7 6 1 1 1 1 2 45 (tcp) 1 7 6 diff --git a/src/tests/cases/snapshots/ui__sustained_traffic_from_multiple_processes_bi_directional.snap b/src/tests/cases/snapshots/ui__sustained_traffic_from_multiple_processes_bi_directional.snap index cc1366c73..aed8ad111 100644 --- a/src/tests/cases/snapshots/ui__sustained_traffic_from_multiple_processes_bi_directional.snap +++ b/src/tests/cases/snapshots/ui__sustained_traffic_from_multiple_processes_bi_directional.snap @@ -6,8 +6,8 @@ expression: "&terminal_draw_events_mirror[1]" - 1 1 57Bps/61Bps :443 => 1.1.1.1:12345 (tcp) 1 57Bps/61Bps - 5 1 34Bps/37Bps :443 => 3.3.3.3:1337 (tcp) 5 34Bps/37Bps + 1 1 57Bps/61Bps :443 => 1.1.1.1:12345 (tcp) 1 57Bps/61Bps + 5 1 34Bps/37Bps :443 => 3.3.3.3:1337 (tcp) 5 34Bps/37Bps diff --git a/src/tests/cases/snapshots/ui__sustained_traffic_from_one_process.snap b/src/tests/cases/snapshots/ui__sustained_traffic_from_one_process.snap index 50fadcb37..70de60f23 100644 --- a/src/tests/cases/snapshots/ui__sustained_traffic_from_one_process.snap +++ b/src/tests/cases/snapshots/ui__sustained_traffic_from_one_process.snap @@ -6,7 +6,7 @@ expression: "&terminal_draw_events_mirror[1]" - 1 1 0Bps/44Bps :443 => 1.1.1.1:12345 (tcp) 1 0Bps/44Bps + 1 1 0Bps/44Bps :443 => 1.1.1.1:12345 (tcp) 1 0Bps/44Bps diff --git a/src/tests/cases/snapshots/ui__traffic_with_host_names-2.snap b/src/tests/cases/snapshots/ui__traffic_with_host_names-2.snap index ec7650f1e..d67be7cfc 100644 --- a/src/tests/cases/snapshots/ui__traffic_with_host_names-2.snap +++ b/src/tests/cases/snapshots/ui__traffic_with_host_names-2.snap @@ -6,8 +6,8 @@ expression: "&terminal_draw_events_mirror[2]" - 5 32 46 three.thre three.three:1337 (tcp) 5 32 46 - 1 7 6 one.one.on one:12345 (tcp) 1 7 6 + 5 32 46 three.thre three.three:13 5 32 46 + 1 7 6 one.one.on one:12345 (tcp 1 7 6 diff --git a/src/tests/cases/snapshots/ui__traffic_with_host_names.snap b/src/tests/cases/snapshots/ui__traffic_with_host_names.snap index 9158c4507..a509ca0fe 100644 --- a/src/tests/cases/snapshots/ui__traffic_with_host_names.snap +++ b/src/tests/cases/snapshots/ui__traffic_with_host_names.snap @@ -6,8 +6,8 @@ expression: "&terminal_draw_events_mirror[1]" - 1 1 57Bps/61Bps :443 => one.one.one.one:12345 (tcp) 1 57Bps/61Bps - 5 1 34Bps/37Bps :443 => three.three.three.three:1337 (tcp) 5 34Bps/37Bps + 1 1 57Bps/61Bps :443 => one.one.one.one:12345 (tcp 1 57Bps/61Bps + 5 1 34Bps/37Bps :443 => three.three.three.three:13 5 34Bps/37Bps diff --git a/src/tests/cases/snapshots/ui__traffic_with_winch_event-3.snap b/src/tests/cases/snapshots/ui__traffic_with_winch_event-3.snap index bc3417ce7..4f7bbb0d7 100644 --- a/src/tests/cases/snapshots/ui__traffic_with_winch_event-3.snap +++ b/src/tests/cases/snapshots/ui__traffic_with_winch_event-3.snap @@ -6,7 +6,7 @@ expression: "&terminal_draw_events_mirror[2]" - 1 1 42Bps/0Bps :443 => 1.1.1.1:12345 (tcp) 1 42Bps/0Bps + 1 1 42Bps/0Bps :443 => 1.1.1.1:12345 (tcp) 1 42Bps/0Bps From 642de57628b28558c02cddd775a4c9a022cba535 Mon Sep 17 00:00:00 2001 From: Eduardo Broto Date: Fri, 20 Dec 2019 20:27:05 +0100 Subject: [PATCH 3/6] refactor(interfaces): Rename interface to interface_name where appropriate --- src/display/components/table.rs | 6 +++++- src/display/ui.rs | 2 +- src/display/ui_state.rs | 4 ++-- src/network/connection.rs | 4 ++-- src/network/sniffer.rs | 6 +++--- src/network/utilization.rs | 4 ++-- 6 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/display/components/table.rs b/src/display/components/table.rs index aef914e01..c8b67790a 100644 --- a/src/display/components/table.rs +++ b/src/display/components/table.rs @@ -64,7 +64,11 @@ impl<'a> Table<'a> { .iter() .map(|(connection, connection_data)| { vec![ - display_connection_string(&connection, &ip_to_host, &connection_data.interface), + display_connection_string( + &connection, + &ip_to_host, + &connection_data.interface_name, + ), connection_data.process_name.to_string(), display_upload_and_download(*connection_data), ] diff --git a/src/display/ui.rs b/src/display/ui.rs index fd137bce3..e58c3e954 100644 --- a/src/display/ui.rs +++ b/src/display/ui.rs @@ -56,7 +56,7 @@ where display_connection_string( connection, ip_to_host, - &connection_network_data.interface + &connection_network_data.interface_name ), connection_network_data.total_bytes_uploaded, connection_network_data.total_bytes_downloaded, diff --git a/src/display/ui_state.rs b/src/display/ui_state.rs index d374c01cf..e5c22170a 100644 --- a/src/display/ui_state.rs +++ b/src/display/ui_state.rs @@ -20,7 +20,7 @@ pub struct ConnectionData { pub total_bytes_downloaded: u128, pub total_bytes_uploaded: u128, pub process_name: String, - pub interface: String, + pub interface_name: String, } impl Bandwidth for ConnectionData { @@ -74,7 +74,7 @@ impl UIState { connection_data.total_bytes_downloaded += connection_info.total_bytes_downloaded; connection_data.total_bytes_uploaded += connection_info.total_bytes_uploaded; connection_data.process_name = process_name; - connection_data.interface = connection_info.interface; + connection_data.interface_name = connection_info.interface_name; data_for_remote_address.total_bytes_downloaded += connection_info.total_bytes_downloaded; data_for_remote_address.total_bytes_uploaded += diff --git a/src/network/connection.rs b/src/network/connection.rs index bd42525ea..b4e0de2bb 100644 --- a/src/network/connection.rs +++ b/src/network/connection.rs @@ -52,11 +52,11 @@ pub fn display_ip_or_host(ip: Ipv4Addr, ip_to_host: &HashMap) pub fn display_connection_string( connection: &Connection, ip_to_host: &HashMap, - interface: &str, + interface_name: &str, ) -> String { format!( "<{}>:{} => {}:{} ({})", - interface, + interface_name, connection.local_port, display_ip_or_host(connection.remote_socket.ip, ip_to_host), connection.remote_socket.port, diff --git a/src/network/sniffer.rs b/src/network/sniffer.rs index 7b2d0b0ab..4c1973187 100644 --- a/src/network/sniffer.rs +++ b/src/network/sniffer.rs @@ -14,7 +14,7 @@ use ::std::net::{IpAddr, SocketAddr}; use crate::network::{Connection, Protocol}; pub struct Segment { - pub interface: String, + pub interface_name: String, pub connection: Connection, pub direction: Direction, pub data_length: u128, @@ -82,7 +82,7 @@ impl Sniffer { } _ => return None, }; - let interface = self.network_interface.name.clone(); + let interface_name = self.network_interface.name.clone(); let direction = Direction::new(&self.network_interface.ips, &ip_packet); let from = SocketAddr::new(IpAddr::V4(ip_packet.get_source()), source_port); let to = SocketAddr::new(IpAddr::V4(ip_packet.get_destination()), destination_port); @@ -92,7 +92,7 @@ impl Sniffer { Direction::Upload => Connection::new(to, source_port, protocol)?, }; Some(Segment { - interface, + interface_name, connection, data_length, direction, diff --git a/src/network/utilization.rs b/src/network/utilization.rs index 6cd732f8f..bdfbb21b5 100644 --- a/src/network/utilization.rs +++ b/src/network/utilization.rs @@ -4,7 +4,7 @@ use ::std::collections::HashMap; #[derive(Clone)] pub struct ConnectionInfo { - pub interface: String, + pub interface_name: String, pub total_bytes_downloaded: u128, pub total_bytes_uploaded: u128, } @@ -29,7 +29,7 @@ impl Utilization { .connections .entry(seg.connection) .or_insert(ConnectionInfo { - interface: seg.interface, + interface_name: seg.interface_name, total_bytes_downloaded: 0, total_bytes_uploaded: 0, }); From d2a9434f157cbcc6ecfa37988c4951563f30fbf4 Mon Sep 17 00:00:00 2001 From: Eduardo Broto Date: Fri, 20 Dec 2019 20:27:55 +0100 Subject: [PATCH 4/6] docs(interfaces): Add a comment explaining break with label syntax --- src/main.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main.rs b/src/main.rs index 34cc09c14..26d4e14af 100644 --- a/src/main.rs +++ b/src/main.rs @@ -208,6 +208,7 @@ where network_utilization.lock().unwrap().update(segment); } if !running.load(Ordering::Acquire) { + // Break from the outer loop and finish the thread break 'sniffing; } } From 6436b7d70a5947d5fa2e6232ca2f858d4f5b8827 Mon Sep 17 00:00:00 2001 From: Eduardo Broto Date: Fri, 20 Dec 2019 20:28:55 +0100 Subject: [PATCH 5/6] docs(readme): Update usage and some uses after making -i optional --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b01d71576..90f630341 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ Windows is not supported at the moment - if you'd like to contribute a windows p ### Usage ``` USAGE: - what [FLAGS] --interface + what [FLAGS] [OPTIONS] FLAGS: -h, --help Prints help information @@ -46,14 +46,14 @@ Note that since `what` sniffs network packets, it requires root privileges - so ### raw_mode `what` also supports an easier-to-parse mode that can be piped or redirected to a file. For example, try: ``` -what -i eth0 --raw | grep firefox +what --raw | grep firefox ``` ### Contributing Contributions of any kind are very welcome. If you'd like a new feature (or found a bug), please open an issue or a PR. To set up your development environment: 1. Clone the project -2. `cargo run -- -i ` (you can often find out the name with `ifconfig` or `iwconfig`). You might need root privileges to run this application, so be sure to use (for example) sudo. +2. `cargo run`, or if you prefer `cargo run -- -i ` (you can often find out the name with `ifconfig` or `iwconfig`). You might need root privileges to run this application, so be sure to use (for example) sudo. To run tests: `cargo test` From b44b646b5ef95d5b44911f70bc092bd11361e064 Mon Sep 17 00:00:00 2001 From: Eduardo Broto Date: Fri, 20 Dec 2019 21:20:13 +0100 Subject: [PATCH 6/6] style(code): fix clippy errors --- src/tests/cases/raw_mode.rs | 25 +++++++++++----------- src/tests/cases/ui.rs | 39 ++++++++++++++++++----------------- src/tests/fakes/fake_input.rs | 2 +- 3 files changed, 34 insertions(+), 32 deletions(-) diff --git a/src/tests/cases/raw_mode.rs b/src/tests/cases/raw_mode.rs index 54cea9e56..93c2afade 100644 --- a/src/tests/cases/raw_mode.rs +++ b/src/tests/cases/raw_mode.rs @@ -12,6 +12,7 @@ use ::std::net::IpAddr; use packet_builder::payload::PayloadData; use packet_builder::*; +use pnet::datalink::DataLinkReceiver; use pnet::packet::Packet; use pnet_base::MacAddr; @@ -71,7 +72,7 @@ fn one_packet_of_traffic() { 443, 12345, b"I am a fake tcp packet", - ))])]; + ))]) as Box]; let terminal_width = Arc::new(Mutex::new(190)); let terminal_height = Arc::new(Mutex::new(50)); @@ -140,7 +141,7 @@ fn bi_directional_traffic() { 443, b"I am a fake tcp download packet", )), - ])]; + ]) as Box]; let terminal_width = Arc::new(Mutex::new(190)); let terminal_height = Arc::new(Mutex::new(50)); @@ -209,7 +210,7 @@ fn multiple_packets_of_traffic_from_different_connections() { 443, b"I come from 2.2.2.2", )), - ])]; + ]) as Box]; let terminal_width = Arc::new(Mutex::new(190)); let terminal_height = Arc::new(Mutex::new(50)); @@ -278,7 +279,7 @@ fn multiple_packets_of_traffic_from_single_connection() { 443, b"I've come from 1.1.1.1 too!", )), - ])]; + ]) as Box]; let terminal_width = Arc::new(Mutex::new(190)); let terminal_height = Arc::new(Mutex::new(50)); @@ -347,7 +348,7 @@ fn one_process_with_multiple_connections() { 443, b"Funny that, I'm from 3.3.3.3", )), - ])]; + ]) as Box]; let terminal_width = Arc::new(Mutex::new(190)); let terminal_height = Arc::new(Mutex::new(50)); @@ -430,7 +431,7 @@ fn multiple_processes_with_multiple_connections() { 443, b"I'm partial to 4.4.4.4", )), - ])]; + ]) as Box]; let terminal_width = Arc::new(Mutex::new(190)); let terminal_height = Arc::new(Mutex::new(50)); @@ -499,7 +500,7 @@ fn multiple_connections_from_remote_address() { 443, b"Me too, but on a different port", )), - ])]; + ]) as Box]; let terminal_width = Arc::new(Mutex::new(190)); let terminal_height = Arc::new(Mutex::new(50)); @@ -570,7 +571,7 @@ fn sustained_traffic_from_one_process() { 443, b"Same here, but one second later", )), - ])]; + ]) as Box]; let terminal_width = Arc::new(Mutex::new(190)); let terminal_height = Arc::new(Mutex::new(50)); @@ -655,7 +656,7 @@ fn sustained_traffic_from_multiple_processes() { 443, b"I come 3.3.3.3 one second later", )), - ])]; + ]) as Box]; let terminal_width = Arc::new(Mutex::new(190)); let terminal_height = Arc::new(Mutex::new(50)); @@ -768,7 +769,7 @@ fn sustained_traffic_from_multiple_processes_bi_directional() { 12345, b"10.0.0.2 forever!", )), - ])]; + ]) as Box]; let terminal_width = Arc::new(Mutex::new(190)); let terminal_height = Arc::new(Mutex::new(50)); @@ -881,7 +882,7 @@ fn traffic_with_host_names() { 12345, b"10.0.0.2 forever!", )), - ])]; + ]) as Box]; let terminal_width = Arc::new(Mutex::new(190)); let terminal_height = Arc::new(Mutex::new(50)); @@ -1007,7 +1008,7 @@ fn no_resolve_mode() { 12345, b"10.0.0.2 forever!", )), - ])]; + ]) as Box]; let terminal_width = Arc::new(Mutex::new(190)); let terminal_height = Arc::new(Mutex::new(50)); diff --git a/src/tests/cases/ui.rs b/src/tests/cases/ui.rs index 78f4f7397..b89c28d61 100644 --- a/src/tests/cases/ui.rs +++ b/src/tests/cases/ui.rs @@ -13,6 +13,7 @@ use ::std::net::IpAddr; use packet_builder::payload::PayloadData; use packet_builder::*; +use pnet::datalink::DataLinkReceiver; use pnet::packet::Packet; use pnet_base::MacAddr; @@ -57,7 +58,7 @@ fn basic_startup() { ])); let network_frames = vec![NetworkFrames::new(vec![ None, // sleep - ])]; + ]) as Box]; let terminal_width = Arc::new(Mutex::new(190)); let terminal_height = Arc::new(Mutex::new(50)); @@ -116,7 +117,7 @@ fn one_packet_of_traffic() { 443, 12345, b"I am a fake tcp packet", - ))])]; + ))]) as Box]; let terminal_width = Arc::new(Mutex::new(190)); let terminal_height = Arc::new(Mutex::new(50)); @@ -187,7 +188,7 @@ fn bi_directional_traffic() { 443, b"I am a fake tcp download packet", )), - ])]; + ]) as Box]; let terminal_width = Arc::new(Mutex::new(190)); let terminal_height = Arc::new(Mutex::new(50)); @@ -258,7 +259,7 @@ fn multiple_packets_of_traffic_from_different_connections() { 443, b"I come from 2.2.2.2", )), - ])]; + ]) as Box]; let terminal_width = Arc::new(Mutex::new(190)); let terminal_height = Arc::new(Mutex::new(50)); @@ -329,7 +330,7 @@ fn multiple_packets_of_traffic_from_single_connection() { 443, b"I've come from 1.1.1.1 too!", )), - ])]; + ]) as Box]; let terminal_width = Arc::new(Mutex::new(190)); let terminal_height = Arc::new(Mutex::new(50)); @@ -400,7 +401,7 @@ fn one_process_with_multiple_connections() { 443, b"Funny that, I'm from 3.3.3.3", )), - ])]; + ]) as Box]; let terminal_width = Arc::new(Mutex::new(190)); let terminal_height = Arc::new(Mutex::new(50)); @@ -485,7 +486,7 @@ fn multiple_processes_with_multiple_connections() { 443, b"I'm partial to 4.4.4.4", )), - ])]; + ]) as Box]; let terminal_width = Arc::new(Mutex::new(190)); let terminal_height = Arc::new(Mutex::new(50)); @@ -556,7 +557,7 @@ fn multiple_connections_from_remote_address() { 443, b"Me too, but on a different port", )), - ])]; + ]) as Box]; let terminal_width = Arc::new(Mutex::new(190)); let terminal_height = Arc::new(Mutex::new(50)); @@ -629,7 +630,7 @@ fn sustained_traffic_from_one_process() { 443, b"Same here, but one second later", )), - ])]; + ]) as Box]; let terminal_width = Arc::new(Mutex::new(190)); let terminal_height = Arc::new(Mutex::new(50)); @@ -716,7 +717,7 @@ fn sustained_traffic_from_multiple_processes() { 443, b"I come 3.3.3.3 one second later", )), - ])]; + ]) as Box]; let terminal_width = Arc::new(Mutex::new(190)); let terminal_height = Arc::new(Mutex::new(50)); @@ -831,7 +832,7 @@ fn sustained_traffic_from_multiple_processes_bi_directional() { 12345, b"10.0.0.2 forever!", )), - ])]; + ]) as Box]; let terminal_width = Arc::new(Mutex::new(190)); let terminal_height = Arc::new(Mutex::new(50)); @@ -946,7 +947,7 @@ fn traffic_with_host_names() { 12345, b"10.0.0.2 forever!", )), - ])]; + ]) as Box]; let terminal_width = Arc::new(Mutex::new(190)); let terminal_height = Arc::new(Mutex::new(50)); @@ -1074,7 +1075,7 @@ fn no_resolve_mode() { 12345, b"10.0.0.2 forever!", )), - ])]; + ]) as Box]; let terminal_width = Arc::new(Mutex::new(190)); let terminal_height = Arc::new(Mutex::new(50)); @@ -1149,7 +1150,7 @@ fn traffic_with_winch_event() { 443, 12345, b"I am a fake tcp packet", - ))])]; + ))]) as Box]; let terminal_width = Arc::new(Mutex::new(190)); let terminal_height = Arc::new(Mutex::new(50)); @@ -1235,7 +1236,7 @@ fn layout_full_width_under_30_height() { 443, b"I'm partial to 4.4.4.4", )), - ])]; + ]) as Box]; let terminal_width = Arc::new(Mutex::new(190)); let terminal_height = Arc::new(Mutex::new(29)); @@ -1320,7 +1321,7 @@ fn layout_under_150_width_full_height() { 443, b"I'm partial to 4.4.4.4", )), - ])]; + ]) as Box]; let terminal_width = Arc::new(Mutex::new(149)); let terminal_height = Arc::new(Mutex::new(50)); @@ -1405,7 +1406,7 @@ fn layout_under_150_width_under_30_height() { 443, b"I'm partial to 4.4.4.4", )), - ])]; + ]) as Box]; let terminal_width = Arc::new(Mutex::new(149)); let terminal_height = Arc::new(Mutex::new(29)); @@ -1490,7 +1491,7 @@ fn layout_under_120_width_full_height() { 443, b"I'm partial to 4.4.4.4", )), - ])]; + ]) as Box]; let terminal_width = Arc::new(Mutex::new(119)); let terminal_height = Arc::new(Mutex::new(50)); @@ -1575,7 +1576,7 @@ fn layout_under_120_width_under_30_height() { 443, b"I'm partial to 4.4.4.4", )), - ])]; + ]) as Box]; let terminal_width = Arc::new(Mutex::new(119)); let terminal_height = Arc::new(Mutex::new(29)); diff --git a/src/tests/fakes/fake_input.rs b/src/tests/fakes/fake_input.rs index 5e02d8387..a3b84b303 100644 --- a/src/tests/fakes/fake_input.rs +++ b/src/tests/fakes/fake_input.rs @@ -50,7 +50,7 @@ pub struct NetworkFrames { } impl NetworkFrames { - pub fn new(packets: Vec>>) -> Box { + pub fn new(packets: Vec>>) -> Box { Box::new(NetworkFrames { packets, current_index: 0,