List all open TCP connections Rust

Viewed 72

Is there any Rust Lib or Libc primitive to get a list of all open TCP connections on the machine? I don’t want to bind to a Linux binary by running a Linux command such as ss or netstat.

1 Answers

As @user2722968 pointed out, you can use it like this:

use procfs::net::tcp;

fn main() {
    for entry in tcp().unwrap().iter() {
        println!("{:?}", entry);
    }
}
Related