diff options
author | Kelvin Zhang <zhangxp1998@gmail.com> | 2020-01-07 16:48:06 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-07 16:48:06 -0500 |
commit | 5826f04ca64071f304286e646c1b262154202b74 (patch) | |
tree | 3a9b7f27adfedc52b85051ec1f8cd05fd2e3dbc6 /src/tests/fakes | |
parent | 73ac4dce7a399658369e5e4e59bc9dd69e572183 (diff) | |
parent | 471fd861d5799b14f819e388246bf8a564ca98a6 (diff) |
Merge pull request #82 from zhangxp1998/udp
Fix bug that non-connected Udp sockets aren't displayed
Diffstat (limited to 'src/tests/fakes')
-rw-r--r-- | src/tests/fakes/fake_input.rs | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/src/tests/fakes/fake_input.rs b/src/tests/fakes/fake_input.rs index a7ce894..92042df 100644 --- a/src/tests/fakes/fake_input.rs +++ b/src/tests/fakes/fake_input.rs @@ -16,6 +16,7 @@ use crate::{ Connection, Protocol, }, os::OnSigWinch, + OpenSockets, }; pub struct KeyboardEvents { @@ -85,11 +86,13 @@ impl DataLinkReceiver for NetworkFrames { } } -pub fn get_open_sockets() -> HashMap<Connection, String> { +pub fn get_open_sockets() -> OpenSockets { let mut open_sockets = HashMap::new(); + let local_ip = IpAddr::V4(Ipv4Addr::new(10, 0, 0, 2)); open_sockets.insert( Connection::new( SocketAddr::new(IpAddr::V4(Ipv4Addr::new(1, 1, 1, 1)), 12345), + local_ip, 443, Protocol::Tcp, ) @@ -99,7 +102,8 @@ pub fn get_open_sockets() -> HashMap<Connection, String> { open_sockets.insert( Connection::new( SocketAddr::new(IpAddr::V4(Ipv4Addr::new(2, 2, 2, 2)), 54321), - 443, + local_ip, + 4434, Protocol::Tcp, ) .unwrap(), @@ -108,7 +112,8 @@ pub fn get_open_sockets() -> HashMap<Connection, String> { open_sockets.insert( Connection::new( SocketAddr::new(IpAddr::V4(Ipv4Addr::new(3, 3, 3, 3)), 1337), - 443, + local_ip, + 4435, Protocol::Tcp, ) .unwrap(), @@ -117,7 +122,8 @@ pub fn get_open_sockets() -> HashMap<Connection, String> { open_sockets.insert( Connection::new( SocketAddr::new(IpAddr::V4(Ipv4Addr::new(4, 4, 4, 4)), 1337), - 443, + local_ip, + 4432, Protocol::Tcp, ) .unwrap(), @@ -126,13 +132,24 @@ pub fn get_open_sockets() -> HashMap<Connection, String> { open_sockets.insert( Connection::new( SocketAddr::new(IpAddr::V4(Ipv4Addr::new(1, 1, 1, 1)), 12346), + local_ip, 443, Protocol::Tcp, ) .unwrap(), - String::from("3"), + String::from("1"), ); - open_sockets + let mut local_socket_to_procs = HashMap::new(); + let mut connections = std::vec::Vec::new(); + for (connection, process_name) in open_sockets { + local_socket_to_procs.insert(connection.local_socket, process_name); + connections.push(connection); + } + + OpenSockets { + sockets_to_procs: local_socket_to_procs, + connections, + } } pub fn get_interfaces() -> Vec<NetworkInterface> { |