diff options
author | Eduardo Broto <ebroto@tutanota.com> | 2019-12-10 22:53:48 +0100 |
---|---|---|
committer | Eduardo Broto <ebroto@tutanota.com> | 2019-12-20 20:23:51 +0100 |
commit | 596889dbd3fa6cea2ce559bfd025fd3c2763056a (patch) | |
tree | 848a95da75459cda862935ef7dc097bb8388dd4b | |
parent | 408ec397c81bb99d6727f01d5dc058e814012714 (diff) |
feat(interfaces): listen on all interfaces by default
Specifying an interface is now optional.
The interface is shown in the connections table.
-rw-r--r-- | src/display/components/table.rs | 2 | ||||
-rw-r--r-- | src/display/ui.rs | 6 | ||||
-rw-r--r-- | src/display/ui_state.rs | 28 | ||||
-rw-r--r-- | src/main.rs | 23 | ||||
-rw-r--r-- | src/network/connection.rs | 4 | ||||
-rw-r--r-- | src/network/sniffer.rs | 3 | ||||
-rw-r--r-- | src/network/utilization.rs | 22 | ||||
-rw-r--r-- | src/os/shared.rs | 32 | ||||
-rw-r--r-- | src/tests/cases/raw_mode.rs | 122 | ||||
-rw-r--r-- | src/tests/cases/ui.rs | 192 | ||||
-rw-r--r-- | 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 74e207a..aef914e 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 3fcb092..fd137bc 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 a027ff4..d374c01 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<Connection, String>, - network_utilization: Utilization, + mut network_utilization: Utilization, ) -> Self { let mut processes: BTreeMap<String, NetworkData> = BTreeMap::new(); let mut remote_addresses: BTreeMap<Ipv4Addr, NetworkData> = 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 9022cfa..34cc09c 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<String>, #[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<dyn DataLinkReceiver>, + pub network_interfaces: Vec<NetworkInterface>, + pub network_frames: Vec<Box<dyn DataLinkReceiver>>, pub get_open_sockets: fn() -> HashMap<Connection, String>, pub keyboard_events: Box<dyn Iterator<Item = Event> + Send>, pub dns_client: Option<dns::Client>, @@ -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::<Vec<Sniffer>>(); + 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 f931d54..bd42525 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<Ipv4Addr, String>) pub fn display_connection_string( connection: &Connection, ip_to_host: &HashMap<Ipv4Addr, String>, + 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 3ec6886..7b2d0b0 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 cb0f12b..6cd732f 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<Connection, TotalBandwidth>, + pub connections: HashMap<Connection, ConnectionInfo>, } 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 8947ecb..3a9aeee 100644 --- a/src/os/shared.rs +++ b/src/os/shared.rs @@ -34,11 +34,11 @@ fn get_datalink_channel( interface: &NetworkInterface, ) -> Result<Box<dyn DataLinkReceiver>, 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<dyn FnMut(String) + Send> { }) } -pub fn get_input(interface_name: &str, resolve: bool) -> Result<OsInputOutput, failure::Error> { - 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<String>, + resolve: bool, +) -> Result<OsInputOutput, failure::Error> { + 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::<Result<Vec<_>, _>>()?; + + 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<OsInputOutput, f }; Ok(OsInputOutput { - network_interface, + network_interfaces, network_frames, get_open_sockets, keyboard_events, diff --git a/src/tests/cases/raw_mode.rs b/src/tests/cases/raw_mode.rs index f0989ca..54cea9e 100644 --- a/src/tests/cases/raw_mode.rs +++ b/src/tests/cases/raw_mode.rs @@ -1,5 +1,5 @@ use crate::tests::fakes::{ - create_fake_dns_client, create_fake_on_winch, get_interface, get_open_sockets, KeyboardEvents, + create_fake_dns_client, create_fake_on_winch, get_interfaces, get_open_sockets, KeyboardEvents, NetworkFrames, TestBackend, }; @@ -65,13 +65,13 @@ fn one_packet_of_traffic() { None, // sleep Some(Event::Key(Key::Ctrl('c'))), ])); - let network_frames = NetworkFrames::new(vec![Some(build_tcp_packet( + let network_frames = vec![NetworkFrames::new(vec![Some(build_tcp_packet( "10.0.0.2", "1.1.1.1", 443, 12345, b"I am a fake tcp packet", - ))]); + ))])]; let terminal_width = Arc::new(Mutex::new(190)); let terminal_height = Arc::new(Mutex::new(50)); @@ -84,7 +84,7 @@ fn one_packet_of_traffic() { terminal_width, terminal_height, ); - let network_interface = get_interface(); + let network_interfaces = get_interfaces(); let dns_client = create_fake_dns_client(HashMap::new()); let on_winch = create_fake_on_winch(false); let cleanup = Box::new(|| {}); @@ -98,7 +98,7 @@ fn one_packet_of_traffic() { }); let os_input = OsInputOutput { - network_interface, + network_interfaces, network_frames, get_open_sockets, keyboard_events, @@ -108,7 +108,7 @@ fn one_packet_of_traffic() { write_to_stdout, }; let opts = Opt { - interface: String::from("interface_name"), + interface: Some(String::from("interface_name")), raw: true, no_resolve: false, }; @@ -125,7 +125,7 @@ fn bi_directional_traffic() { None, // sleep Some(Event::Key(Key::Ctrl('c'))), ])); - let network_frames = NetworkFrames::new(vec![ + let network_frames = vec![NetworkFrames::new(vec![ Some(build_tcp_packet( "10.0.0.2", "1.1.1.1", @@ -140,7 +140,7 @@ fn bi_directional_traffic() { 443, b"I am a fake tcp download packet", )), - ]); + ])]; let terminal_width = Arc::new(Mutex::new(190)); let terminal_height = Arc::new(Mutex::new(50)); @@ -153,7 +153,7 @@ fn bi_directional_traffic() { terminal_width, terminal_height, ); - let network_interface = get_interface(); + let network_interfaces = get_interfaces(); let dns_client = create_fake_dns_client(HashMap::new()); let on_winch = create_fake_on_winch(false); let cleanup = Box::new(|| {}); @@ -167,7 +167,7 @@ fn bi_directional_traffic() { }); let os_input = OsInputOutput { - network_interface, + network_interfaces, network_frames, get_open_sockets, keyboard_events, @@ -177,7 +177,7 @@ fn bi_directional_traffic() { write_to_stdout, }; let opts = Opt { - interface: String::from("interface_name"), + interface: Some(String::from("interface_name")), raw: true, no_resolve: false, }; @@ -194,7 +194,7 @@ fn multiple_packets_of_traffic_from_different_connections() { None, // sleep Some(Event::Key(Key::Ctrl('c'))), ])); - let network_frames = NetworkFrames::new(vec![ + let network_frames = vec![NetworkFrames::new(vec![ Some(build_tcp_packet( "1.1.1.1", "10.0.0.2", @@ -209,7 +209,7 @@ fn multiple_packets_of_traffic_from_different_connections() { 443, b"I come from 2.2.2.2", )), - ]); + ])]; let terminal_width = Arc::new(Mutex::new(190)); let terminal_height = Arc::new(Mutex::new(50)); @@ -224,7 +224,7 @@ fn multiple_packets_of_traffic_from_different_connections() { ); let on_winch = create_fake_on_winch(false); let cleanup = Box::new(|| {}); - let network_interface = get_interface(); + let network_interfaces = get_interfaces(); let dns_client = create_fake_dns_client(HashMap::new()); let stdout = Arc::new(Mutex::new(Vec::new())); let write_to_stdout = Box::new({ @@ -236,7 +236,7 @@ fn multiple_packets_of_traffic_from_different_connections() { }); let os_input = OsInputOutput { - network_interface, + network_interfaces, network_frames, get_open_sockets, on_winch, @@ -246,7 +246,7 @@ fn multiple_packets_of_traffic_from_different_connections() { write_to_stdout, }; let opts = Opt { - interface: String::from("interface_name"), + interface: Some(String::from("interface_name")), raw: true, no_resolve: false, }; @@ -263,7 +263,7 @@ fn multiple_packets_of_traffic_from_single_connection() { None, // sleep Some(Event::Key(Key::Ctrl('c'))), ])); - let network_frames = NetworkFrames::new(vec![ + let network_frames = vec![NetworkFrames::new(vec![ Some(build_tcp_packet( "1.1.1.1", "10.0.0.2", @@ -278,7 +278,7 @@ fn multiple_packets_of_traffic_from_single_connection() { 443, b"I've come from 1.1.1.1 too!", )), - ]); + ])]; let terminal_width = Arc::new(Mutex::new(190)); let terminal_height = Arc::new(Mutex::new(50)); @@ -291,7 +291,7 @@ fn multiple_packets_of_traffic_from_single_connection() { terminal_width, terminal_height, ); - let network_interface = get_interface(); + let network_interfaces = get_interfaces(); let dns_client = create_fake_dns_client(HashMap::new()); let on_winch = create_fake_on_winch(false); let cleanup = Box::new(|| {}); @@ -305,7 +305,7 @@ fn multiple_packets_of_traffic_from_single_connection() { }); let os_input = OsInputOutput { - network_interface, + network_interfaces, network_frames, get_open_sockets, keyboard_events, @@ -315,7 +315,7 @@ fn multiple_packets_of_traffic_from_single_connection() { write_to_stdout, }; let opts = Opt { - interface: String::from("interface_name"), + interface: Some(String::from("interface_name")), raw: true, no_resolve: false, }; @@ -332,7 +332,7 @@ fn one_process_with_multiple_connections() { None, // sleep Some(Event::Key(Key::Ctrl('c'))), ])); - let network_frames = NetworkFrames::new(vec![ + let network_frames = vec![NetworkFrames::new(vec![ Some(build_tcp_packet( "1.1.1.1", "10.0.0.2", @@ -347,7 +347,7 @@ fn one_process_with_multiple_connections() { 443, b"Funny that, I'm from 3.3.3.3", )), - ]); + ])]; let terminal_width = Arc::new(Mutex::new(190)); let terminal_height = Arc::new(Mutex::new(50)); @@ -360,7 +360,7 @@ fn one_process_with_multiple_connections() { terminal_width, terminal_height, ); - let network_interface = get_interface(); + let network_interfaces = get_interfaces(); let dns_client = create_fake_dns_client(HashMap::new()); let on_winch = create_fake_on_winch(false); let cleanup = Box::new(|| {}); @@ -374,7 +374,7 @@ fn one_process_with_multiple_connections() { }); let os_input = OsInputOutput { - network_interface, + network_interfaces, network_frames, get_open_sockets, keyboard_events, @@ -384,7 +384,7 @@ fn one_process_with_multiple_connections() { write_to_stdout, }; let opts = Opt { - interface: String::from("interface_name"), + interface: Some(String::from("interface_name")), raw: true, no_resolve: false, }; @@ -401,7 +401,7 @@ fn multiple_processes_with_multiple_connections() { None, // sleep Some(Event::Key(Key::Ctrl('c'))), ])); - let network_frames = NetworkFrames::new(vec![ + let network_frames = vec![NetworkFrames::new(vec![ Some(build_tcp_packet( "1.1.1.1", "10.0.0.2", @@ -430,7 +430,7 @@ fn multiple_processes_with_multiple_connections() { 443, b"I'm partial to 4.4.4.4", )), - ]); + ])]; let terminal_width = Arc::new(Mutex::new(190)); let terminal_height = Arc::new(Mutex::new(50)); @@ -443,7 +443,7 @@ fn multiple_processes_with_multiple_connections() { terminal_width, terminal_height, ); - let network_interface = get_interface(); + let network_interfaces = get_interfaces(); let dns_client = create_fake_dns_client(HashMap::new()); let on_winch = create_fake_on_winch(false); let cleanup = Box::new(|| {}); @@ -457,7 +457,7 @@ fn multiple_processes_with_multiple_connections() { }); let os_input = OsInputOutput { - network_interface, + network_interfaces, network_frames, get_open_sockets, keyboard_events, @@ -467,7 +467,7 @@ fn multiple_processes_with_multiple_connections() { write_to_stdout, }; let opts = Opt { - interface: String::from("interface_name"), + interface: Some(String::from("interface_name")), raw: true, no_resolve: false, }; @@ -484,7 +484,7 @@ fn multiple_connections_from_remote_address() { None, // sleep Some(Event::Key(Key::Ctrl('c'))), ])); - let network_frames = NetworkFrames::new(vec![ + let network_frames = vec![NetworkFrames::new(vec![ Some(build_tcp_packet( "1.1.1.1", "10.0.0.2", @@ -499,7 +499,7 @@ fn multiple_connections_from_remote_address() { 443, b"Me too, but on a different port", )), - ]); + ])]; let terminal_width = Arc::new(Mutex::new(190)); let terminal_height = Arc::new(Mutex::new(50)); @@ -512,7 +512,7 @@ fn multiple_connections_from_remote_address() { terminal_width, terminal_height, ); - let network_interface = get_interface(); + let network_interfaces = get_interfaces(); let dns_client = create_fake_dns_client(HashMap::new()); let on_winch = create_fake_on_winch(false); let cleanup = Box::new(|| {}); @@ -526,7 +526,7 @@ fn multiple_connections_from_remote_address() { }); let os_input = OsInputOutput { - network_interface, + network_interfaces, network_frames, get_open_sockets, keyboard_events, @@ -536,7 +536,7 @@ fn multiple_connections_from_remote_address() { write_to_stdout, }; let opts = Opt { - interface: String::from("interface_name"), + interface: Some(String::from("interface_name")), raw: true, no_resolve: false, }; @@ -554,7 +554,7 @@ fn sustained_traffic_from_one_process() { None, // sleep Some(Event::Key(Key::Ctrl('c'))), ])); - let network_frames = NetworkFrames::new(vec![ + let network_frames = vec![NetworkFrames::new(vec![ Some(build_tcp_packet( "1.1.1.1", "10.0.0.2", @@ -570,7 +570,7 @@ fn sustained_traffic_from_one_process() { 443, b"Same here, but one second later", )), - ]); + ])]; let terminal_width = Arc::new(Mutex::new(190)); let terminal_height = Arc::new(Mutex::new(50)); @@ -583,7 +583,7 @@ fn sustained_traffic_from_one_process() { terminal_width, terminal_height, ); - let network_interface = get_interface(); + let network_interfaces = get_interfaces(); let dns_client = create_fake_dns_client(HashMap::new()); let on_winch = create_fake_on_winch(false); let cleanup = Box::new(|| {}); @@ -597,7 +597,7 @@ fn sustained_traffic_from_one_process() { }); let os_input = OsInputOutput { - network_interface, + network_interfaces, network_frames, get_open_sockets, keyboard_events, @@ -607,7 +607,7 @@ fn sustained_traffic_from_one_process() { write_to_stdout, }; let opts = Opt { - interface: String::from("interface_name"), + interface: Some(String::from("interface_name")), raw: true, no_resolve: false, }; @@ -625,7 +625,7 @@ fn sustained_traffic_from_multiple_processes() { None, // sleep Some(Event::Key(Key::Ctrl('c'))), ])); - let network_frames = NetworkFrames::new(vec![ + let network_frames = vec![NetworkFrames::new(vec![ Some(build_tcp_packet( "1.1.1.1", "10.0.0.2", @@ -655,7 +655,7 @@ fn sustained_traffic_from_multiple_processes() { 443, b"I come 3.3.3.3 one second later", )), - ]); + ])]; let terminal_width = Arc::new(Mutex::new(190)); let terminal_height = Arc::new(Mutex::new(50)); @@ -668,7 +668,7 @@ fn sustained_traffic_from_multiple_processes() { terminal_width, terminal_height, ); - let network_interface = get_interface(); + let network_interfaces = get_interfaces(); let dns_client = create_fake_dns_client(HashMap::new()); let on_winch = create_fake_on_winch(false); let cleanup = Box::new(|| {}); @@ -682,7 +682,7 @@ fn sustained_traffic_from_multiple_processes() { }); let os_input = OsInputOutput { - network_interface, + network_interfaces, network_frames, get_open_sockets, keyboard_events, @@ -692,7 +692,7 @@ fn sustained_traffic_from_multiple_processes() { write_to_stdout, }; let opts = Opt { - interface: String::from("interface_name"), + interface: Some(String::from("interface_name")), raw: true, no_resolve: false, }; @@ -710,7 +710,7 @@ fn sustained_traffic_from_multiple_processes_bi_directional() { None, // sleep Some(Event::Key(Key::Ctrl('c'))), ])); - let network_frames = NetworkFrames::new(vec![ + let network_frames = vec![NetworkFrames::new(vec![ Some(build_tcp_packet( "10.0.0.2", "3.3.3.3", @@ -768,7 +768,7 @@ fn sustained_traffic_from_multiple_processes_bi_directional() { 12345, b"10.0.0.2 forever!", )), - ]); + ])]; let terminal_width = Arc::new(Mutex::new(190)); let terminal_height = Arc::new(Mutex::new(50)); @@ -781,7 +781,7 @@ fn sustained_traffic_from_multiple_processes_bi_directional() { terminal_width, terminal_height, ); - let network_interface = get_interface(); + let network_interfaces = get_interfaces(); let dns_client = create_fake_dns_client(HashMap::new()); let on_winch = create_fake_on_winch(false); let cleanup = Box::new(|| {}); @@ -795,7 +795,7 @@ fn sustained_traffic_from_multiple_processes_bi_directional() { }); let os_input = OsInputOutput { - network_interface, + network_interfaces, network_frames, get_open_sockets, keyboard_events, @@ -805,7 +805,7 @@ fn sustained_traffic_from_multiple_processes_bi_directional() { write_to_stdout, }; let opts = Opt { - interface: String::from("interface_name"), + interface: Some(String::from("interface_name")), raw: true, no_resolve: false, }; @@ -823,7 +823,7 @@ fn traffic_with_host_names() { None, // sleep Some(Event::Key(Key::Ctrl('c'))), ])); - let network_frames = NetworkFrames::new(vec![ + let network_frames = vec![NetworkFrames::new(vec![ Some(build_tcp_packet( "10.0.0.2", "3.3.3.3", @@ -881,7 +881,7 @@ fn traffic_with_host_names() { 12345, b"10.0.0.2 forever!", )), - ]); + ])]; let terminal_width = Arc::new(Mutex::new(190)); let terminal_height = Arc::new(Mutex::new(50)); @@ -894,7 +894,7 @@ fn traffic_with_host_names() { terminal_width, terminal_height, ); - let network_interface = get_interface(); + let network_interfaces = get_interfaces(); let mut ips_to_hostnames = HashMap::new(); ips_to_hostnames.insert( IpAddr::V4("1.1.1.1".parse().unwrap()), @@ -921,7 +921,7 @@ fn traffic_with_host_names() { }); let os_input = OsInputOutput { - network_interface, + network_interfaces, network_frames, get_open_sockets, keyboard_events, @@ -931,7 +931,7 @@ fn traffic_with_host_names() { write_to_stdout, }; let opts = Opt { - interface: String::from("interface_name"), + interface: Some(String::from("interface_name")), raw: true, no_resolve: false, }; @@ -949,7 +949,7 @@ fn no_resolve_mode() { None, // sleep Some(Event::Key(Key::Ctrl('c'))), ])); - let network_frames = NetworkFrames::new(vec![ + let network_frames = vec![NetworkFrames::new(vec![ Some(build_tcp_packet( "10.0.0.2", "3.3.3.3", @@ -1007,7 +1007,7 @@ fn no_resolve_mode() { 12345, b"10.0.0.2 forever!", )), - ]); + ])]; let terminal_width = Arc::new(Mutex::new(190)); let terminal_height = Arc::new(Mutex::new(50)); @@ -1020,7 +1020,7 @@ fn no_resolve_mode() { terminal_width, terminal_height, ); - let network_interface = get_interface(); + let network_interfaces = get_interfaces(); let mut ips_to_hostnames = HashMap::new(); ips_to_hostnames.insert( IpAddr::V4("1.1.1.1".parse().unwrap()), @@ -1047,7 +1047,7 @@ fn no_resolve_mode() { }); let os_input = OsInputOutput { - network_interface, + network_interfaces, network_frames, get_open_sockets, keyboard_events, @@ -1057,7 +1057,7 @@ fn no_resolve_mode() { write_to_stdout, }; let opts = Opt { - interface: String::from("interface_name"), + interface: Some(String::from("interface_name")), raw: true, no_resolve: true, }; diff --git a/src/tests/cases/ui.rs b/src/tests/cases/ui.rs index f2f5374..78f4f73 100644 --- a/src/tests/cases/ui.rs +++ b/src/tests/cases/ui.rs @@ -1,6 +1,6 @@ use crate::tests::fakes::TerminalEvent::*; use crate::tests::fakes::{ - create_fake_dns_client, create_fake_on_winch, get_interface, get_open_sockets, KeyboardEvents, + create_fake_dns_client, create_fake_on_winch, get_interfaces, get_open_sockets, KeyboardEvents, NetworkFrames, TestBackend, }; @@ -55,9 +55,9 @@ fn basic_startup() { None, // sleep Some(Event::Key(Key::Ctrl('c'))), ])); - let network_frames = NetworkFrames::new(vec![ + let network_frames = vec![NetworkFrames::new(vec![ None, // sleep - ]); + ])]; let terminal_width = Arc::new(Mutex::new(190)); let terminal_height = Arc::new(Mutex::new(50)); @@ -70,14 +70,14 @@ fn basic_startup() { terminal_width, terminal_height, ); - let network_interface = get_interface(); + let network_interfaces = get_interfaces(); let dns_client = create_fake_dns_client(HashMap::new()); let on_winch = create_fake_on_winch(false); let cleanup = Box::new(|| {}); let write_to_stdout = Box::new({ move |_output: String| {} }); let os_input = OsInputOutput { - network_interface, + network_interfaces, network_frames, get_open_sockets, keyboard_events, @@ -87,7 +87,7 @@ fn basic_startup() { write_to_stdout, }; let opts = Opt { - interface: String::from("interface_name"), + interface: Some(String::from("interface_name")), raw: false, no_ |