summaryrefslogtreecommitdiffstats
path: root/src/os/shared.rs
diff options
context:
space:
mode:
authorEduardo Broto <ebroto@tutanota.com>2019-12-10 22:53:48 +0100
committerEduardo Broto <ebroto@tutanota.com>2019-12-20 20:23:51 +0100
commit596889dbd3fa6cea2ce559bfd025fd3c2763056a (patch)
tree848a95da75459cda862935ef7dc097bb8388dd4b /src/os/shared.rs
parent408ec397c81bb99d6727f01d5dc058e814012714 (diff)
feat(interfaces): listen on all interfaces by default
Specifying an interface is now optional. The interface is shown in the connections table.
Diffstat (limited to 'src/os/shared.rs')
-rw-r--r--src/os/shared.rs32
1 files changed, 22 insertions, 10 deletions
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,