Skip to content

Commit

Permalink
Merge pull request #2 from SubconsciousCompute/deps_upgrade
Browse files Browse the repository at this point in the history
Deps upgrade
  • Loading branch information
dilawar authored Nov 1, 2024
2 parents 23aeb92 + dfa5183 commit cb7171c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 14 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ Cross-platform library to retrieve network sockets information.

[dependencies]
libc = "0.2"
bitflags = "1.0"
bitflags = "1.3"
thiserror = "1"

[target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies]
num-derive = "0.3"
num-traits = "0.2.8"
byteorder = "1.3.2"
num-traits = "0.2.19"
byteorder = "1.5.0"
2 changes: 1 addition & 1 deletion src/integrations/linux/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ fn attach_pids(
.remove(&socket_info.inode)
.unwrap_or_default()
.iter()
.map(|x| *x)
.copied()
.collect(),
..socket_info
})
Expand Down
4 changes: 2 additions & 2 deletions src/integrations/linux/ffi/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ macro_rules! NLMSG_LENGTH {

macro_rules! NLMSG_DATA {
($nlh:expr) => {
($nlh as *const u8).offset(NLMSG_LENGTH!(0) as isize)
($nlh as *const u8).add(NLMSG_LENGTH!(0))
};
}

Expand Down Expand Up @@ -64,6 +64,6 @@ macro_rules! RTA_LENGTH {

macro_rules! RTA_DATA {
($rta:expr) => {
($rta as *const u8).offset(RTA_LENGTH!(0) as isize)
($rta as *const u8).add(RTA_LENGTH!(0))
};
}
15 changes: 7 additions & 8 deletions src/integrations/linux/netlink_iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use crate::integrations::linux::ffi::*;
use crate::types::error::*;
use crate::types::*;
use libc::*;
use std;
use std::io;
use std::mem::size_of;
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
Expand Down Expand Up @@ -31,7 +30,7 @@ pub struct NetlinkIterator {

impl NetlinkIterator {
pub unsafe fn new(family: __u8, protocol: __u8) -> Result<Self, Error> {
let socket = socket(AF_NETLINK as i32, SOCK_DGRAM, NETLINK_INET_DIAG);
let socket = socket(AF_NETLINK, SOCK_DGRAM, NETLINK_INET_DIAG);

if socket == -1 {
return Result::Err(Error::OsError(io::Error::last_os_error()));
Expand All @@ -41,7 +40,7 @@ impl NetlinkIterator {
Ok(NetlinkIterator {
protocol,
socket,
recv_buf: [0u8; SOCKET_BUFFER_SIZE as usize],
recv_buf: [0u8; SOCKET_BUFFER_SIZE],
nlh: std::ptr::null(),
numbytes: 0,
nlmsg_ok: false,
Expand All @@ -61,17 +60,17 @@ impl Iterator for NetlinkIterator {
}
self.nlmsg_ok = NLMSG_OK!(self.nlh, self.numbytes);
if self.nlmsg_ok {
if (&*self.nlh).nlmsg_type == NLMSG_DONE as u16 {
if (*self.nlh).nlmsg_type == NLMSG_DONE as u16 {
return None;
}
if (&*self.nlh).nlmsg_type == NLMSG_ERROR as u16 {
if (*self.nlh).nlmsg_type == NLMSG_ERROR as u16 {
// TODO: parse error code from msg properly
// https://www.infradead.org/~tgr/libnl/doc/core.html#core_errmsg
return Some(Result::Err(Error::NetLinkError));
}
let diag_msg = NLMSG_DATA!(self.nlh) as *const inet_diag_msg;
let rtalen =
(&*self.nlh).nlmsg_len as usize - NLMSG_LENGTH!(size_of::<inet_diag_msg>());
(*self.nlh).nlmsg_len as usize - NLMSG_LENGTH!(size_of::<inet_diag_msg>());
let socket_info = parse_diag_msg(&*diag_msg, self.protocol, rtalen);
self.nlh = NLMSG_NEXT!(self.nlh, self.numbytes);
return Some(socket_info);
Expand Down Expand Up @@ -188,8 +187,8 @@ unsafe fn parse_tcp_state(diag_msg: &inet_diag_msg, rtalen: usize) -> TcpState {
let mut len = rtalen as isize;
let mut attr = (diag_msg as *const inet_diag_msg).offset(1) as *const rtattr;
while RTA_OK!(attr, len) {
if (&*attr).rta_type == INET_DIAG_INFO as u16 {
let tcpi = &*(RTA_DATA!(attr) as *const tcp_info);
if (*attr).rta_type == INET_DIAG_INFO as u16 {
let tcpi = &*(RTA_DATA!(attr) as *const libc::tcp_info);
return TcpState::from(tcpi.tcpi_state);
}
attr = RTA_NEXT!(attr, len);
Expand Down

0 comments on commit cb7171c

Please sign in to comment.