diff --git a/src/main.rs b/src/main.rs index a23c5a6..71f975a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,10 +3,10 @@ use std::collections::HashSet; use std::fmt::{Display, Formatter, Write}; use std::{fmt, fs}; use std::fs::{read_to_string, ReadDir}; -use std::os::unix::fs::MetadataExt; use std::path::PathBuf; use crate::socket::socket::{Id, Tcp_Socket}; + type inode = u64; type pid = u64; @@ -118,11 +118,9 @@ pub fn format_output(combination : socket::socket::Combination, sockets : &Vec max_loc_ip_len) { curr_loc_ip_len } else { max_loc_ip_len }; max_loc_port_len = if (curr_loc_port_len > max_loc_port_len) { curr_loc_port_len } else { max_loc_port_len }; max_rem_ip_len = if (curr_rem_ip_len > max_rem_ip_len) { curr_rem_ip_len } else { max_rem_ip_len }; max_rem_port_len = if (curr_rem_port_len > max_rem_port_len) { curr_rem_port_len } else { max_rem_port_len }; max_state_len = if(curr_state_len > max_state_len) { curr_state_len } else { max_state_len }; - - - - if combination == socket::socket::Combination::tnp{ - + + if combination == socket::socket::Combination::tnap{ + // max_real_uid_len = if (curr_uid_) } }); max_loc_ip_len = max_loc_ip_len + 3; max_loc_port_len = max_loc_port_len + 3; max_rem_ip_len = max_rem_ip_len + 3; match combination { - socket::socket::Combination::tn => { - ret_str.push_str(&format!("{:>max_state_len$} {:>max_loc_ip_len$}:{:max_rem_ip_len$}:{: { + ret_str.push_str(&format!("{:>max_state_len$} {:>max_loc_ip_len$}:{:max_rem_ip_len$}:{:max_state_len$} {:>max_loc_ip_len$}:{:max_rem_ip_len$}:{: { + socket::socket::Combination::tnap => { } } - ret_str } @@ -190,7 +186,6 @@ fn get_all_tcp_sockets(pid_pattern : &Regex, socket_patt : &Regex) -> Vec String { let mut ret_str = String::from(""); match combination { - Combination::tnp => { + Combination::tnap => { //state rem_ip:rem_port loc_ip:loc_port real|effective-uid real|effective-gid pids(.,.,.,.) - ret_str.push_str(&self.clone().to_string(Combination::tn)); + ret_str.push_str(&self.clone().to_string(Combination::tna)); ret_str.push(' '); ret_str.push_str(&self.user.real.to_string()); ret_str.push('|'); @@ -278,7 +278,7 @@ pub mod socket { ret_str } - Combination::tn => { + Combination::tna => { //state rem_ip:rem_port loc_ip:loc_port ret_str.push_str(&self.state.to_string()); ret_str.push(' '); @@ -375,8 +375,8 @@ mod tests { #[test] fn test_to_string() -> () { let sockets = init_sockets(); - assert_eq!("93.83.160.12:21345 0.0.0.0:*\n", sockets[0].clone().to_string(Combination::tn)); - assert_eq!("195.201.90.97:8843 0.0.0.0:443\n", sockets[1].clone().to_string(Combination::tn)); - assert_eq!("255.255.255.255:193193 0.0.0.0:8080\n", sockets[2].clone().to_string(Combination::tn)); + assert_eq!("93.83.160.12:21345 0.0.0.0:*\n", sockets[0].clone().to_string(Combination::tna)); + assert_eq!("195.201.90.97:8843 0.0.0.0:443\n", sockets[1].clone().to_string(Combination::tna)); + assert_eq!("255.255.255.255:193193 0.0.0.0:8080\n", sockets[2].clone().to_string(Combination::tna)); } }