summaryrefslogtreecommitdiffstats
path: root/src/os/lsof.rs
blob: f6d1e3f6519f00ac8169fbd6c268d4e05f25fd36 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
use std::collections::HashMap;

use crate::{network::LocalSocket, os::lsof_utils::get_connections, OpenSockets};

pub(crate) fn get_open_sockets() -> OpenSockets {
    let mut open_sockets = HashMap::new();

    let connections = get_connections();

    for raw_connection in connections {
        open_sockets.insert(
            LocalSocket {
                ip: raw_connection.get_local_ip(),
                port: raw_connection.get_local_port(),
                protocol: raw_connection.get_protocol(),
            },
            raw_connection.process_name.clone(),
        );
    }

    OpenSockets {
        sockets_to_procs: open_sockets,
    }
}