Skip to content

Commit

Permalink
Merge pull request #4 from chengyuhui/no-pid
Browse files Browse the repository at this point in the history
Add `iterate_sockets_info_without_pids` to linux
  • Loading branch information
ohadravid authored Nov 18, 2020
2 parents aa2ca45 + 9d03aad commit 70f05a4
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/integrations/linux/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ use libc::*;
pub fn iterate_sockets_info(
af_flags: AddressFamilyFlags,
proto_flags: ProtocolFlags,
) -> Result<impl Iterator<Item = Result<SocketInfo, Error>>, Error> {
Ok(attach_pids(iterate_sockets_info_without_pids(
af_flags,
proto_flags,
)?))
}

/// Iterate through sockets information without attaching PID.
pub fn iterate_sockets_info_without_pids(
af_flags: AddressFamilyFlags,
proto_flags: ProtocolFlags,
) -> Result<impl Iterator<Item = Result<SocketInfo, Error>>, Error> {
let ipv4 = af_flags.contains(AddressFamilyFlags::IPV4);
let ipv6 = af_flags.contains(AddressFamilyFlags::IPV6);
Expand All @@ -32,7 +43,7 @@ pub fn iterate_sockets_info(
}
}
}
Ok(attach_pids(iterators.into_iter().flatten()))
Ok(iterators.into_iter().flatten())
}

fn attach_pids(
Expand Down

0 comments on commit 70f05a4

Please sign in to comment.