Skip to content

Commit

Permalink
simple example to try get all listeners (linux)
Browse files Browse the repository at this point in the history
  • Loading branch information
GyulyVGC committed Mar 4, 2024
1 parent 993d25a commit a1f9341
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 27 deletions.
53 changes: 27 additions & 26 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
use std::net::IpAddr;
use std::str::FromStr;

use listeners::hi_cross;

fn main() {
let print_title = |title: &str| {
let n_repeat = 40 - title.len() / 2;
let repeat_str = "=".repeat(n_repeat);
println!("\n{repeat_str} {title} {repeat_str}");
};

print_title("get_all()");
for listener in listeners::get_all() {
println!("{listener}");
}

let ip = IpAddr::from_str(
&std::env::args()
.nth(1)
.expect("Expected IP address as argument to program"),
)
.expect("The provided IP address is not valid");

hi_cross();

print_title(&format!("get_for_nullnet({ip})"));
for pname in listeners::get_for_nullnet(ip) {
println!("{pname}");
}
}

// fn main() {
// let print_title = |title: &str| {
// let n_repeat = 40 - title.len() / 2;
// let repeat_str = "=".repeat(n_repeat);
// println!("\n{repeat_str} {title} {repeat_str}");
// };
//
// print_title("get_all()");
// for listener in listeners::get_all() {
// println!("{listener}");
// }
//
// let ip = IpAddr::from_str(
// &std::env::args()
// .nth(1)
// .expect("Expected IP address as argument to program"),
// )
// .expect("The provided IP address is not valid");
//
// hi_cross();
//
// print_title(&format!("get_for_nullnet({ip})"));
// for pname in listeners::get_for_nullnet(ip) {
// println!("{pname}");
// }
// }
9 changes: 8 additions & 1 deletion src/platform/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@ static KERNEL: Lazy<Option<String>> = Lazy::new(|| {
.ok()
});

pub(crate) fn hi() {}
pub(crate) fn hi() {
let processes = get_all_processes();
for p in processes {
println!("{} {:?}", p.pid, p.root);
}
// let socket_inode_process_map = build_inode_process_map(processes);
//
}

fn get_all_processes() -> Vec<Process> {
procfs::process::all_processes().unwrap();
Expand Down

0 comments on commit a1f9341

Please sign in to comment.