Skip to content

Commit

Permalink
Support IPv6 port
Browse files Browse the repository at this point in the history
  • Loading branch information
dalance committed Feb 1, 2019
1 parent 8c82e90 commit e99a21b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/columns/tcp_port.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub struct TcpPort {
raw_contents: HashMap<i32, String>,
max_width: usize,
tcp_entry: Vec<TcpNetEntry>,
tcp6_entry: Vec<TcpNetEntry>,
}

impl TcpPort {
Expand All @@ -24,6 +25,7 @@ impl TcpPort {
header,
unit,
tcp_entry: procfs::tcp().unwrap(),
tcp6_entry: procfs::tcp6().unwrap(),
}
}
}
Expand All @@ -47,13 +49,16 @@ impl Column for TcpPort {
}
let mut ports = Vec::new();
for sock in &socks {
let entry = self.tcp_entry.iter().find(|&x| x.inode == *sock);
let mut tcp_iter = self.tcp_entry.iter().chain(self.tcp6_entry.iter());
let entry = tcp_iter.find(|&x| x.inode == *sock);
if let Some(entry) = entry {
if entry.state == TcpState::Listen {
ports.push(entry.local_address.port());
}
}
}
ports.sort();
ports.dedup();
let fmt_content = format!("{:?}", ports);
let raw_content = fmt_content.clone();

Expand Down
7 changes: 6 additions & 1 deletion src/columns/udp_port.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub struct UdpPort {
raw_contents: HashMap<i32, String>,
max_width: usize,
udp_entry: Vec<UdpNetEntry>,
udp6_entry: Vec<UdpNetEntry>,
}

impl UdpPort {
Expand All @@ -24,6 +25,7 @@ impl UdpPort {
header,
unit,
udp_entry: procfs::udp().unwrap(),
udp6_entry: procfs::udp6().unwrap(),
}
}
}
Expand All @@ -47,11 +49,14 @@ impl Column for UdpPort {
}
let mut ports = Vec::new();
for sock in &socks {
let entry = self.udp_entry.iter().find(|&x| x.inode == *sock);
let mut udp_iter = self.udp_entry.iter().chain(self.udp6_entry.iter());
let entry = udp_iter.find(|&x| x.inode == *sock);
if let Some(entry) = entry {
ports.push(entry.local_address.port());
}
}
ports.sort();
ports.dedup();
let fmt_content = format!("{:?}", ports);
let raw_content = fmt_content.clone();

Expand Down

0 comments on commit e99a21b

Please sign in to comment.