Skip to content

Commit 8041f49

Browse files
committed
Fix musl support
1 parent c2031bb commit 8041f49

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "netstat2"
3-
version = "0.8.0"
3+
version = "0.8.1"
44
authors = ["Ohad Ravid <ohad.rv@gmail.com>", "ivxvm <ivxvm@protonmail.com>"]
55
edition = "2018"
66
license = "MIT OR Apache-2.0"

src/integrations/linux/netlink_iterator.rs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@ use std::io;
77
use std::mem::size_of;
88
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
99

10+
#[cfg(target_env = "musl")]
11+
#[repr(C)]
12+
pub struct nlmsghdr {
13+
pub nlmsg_len: u32,
14+
pub nlmsg_type: u16,
15+
pub nlmsg_flags: u16,
16+
pub nlmsg_seq: u32,
17+
pub nlmsg_pid: u32,
18+
}
19+
1020
const TCPF_ALL: __u32 = 0xFFF;
1121
const SOCKET_BUFFER_SIZE: size_t = 8192;
1222

@@ -104,15 +114,13 @@ unsafe fn send_diag_msg(sockfd: c_int, family: __u8, protocol: __u8) -> Result<(
104114
iov_len: size_of::<inet_diag_req_v2>() as size_t,
105115
},
106116
];
107-
let msg = msghdr {
108-
msg_name: &mut sa as *mut _ as *mut c_void,
109-
msg_namelen: size_of::<sockaddr_nl>() as c_uint,
110-
msg_iov: &mut iov[0],
111-
msg_iovlen: 2,
112-
msg_control: std::ptr::null_mut(),
113-
msg_controllen: 0,
114-
msg_flags: 0,
115-
};
117+
118+
let mut msg: msghdr = std::mem::zeroed();
119+
msg.msg_name = &mut sa as *mut _ as *mut _;
120+
msg.msg_namelen = size_of::<sockaddr_nl>() as c_uint;
121+
msg.msg_iov = &mut iov[0];
122+
msg.msg_iovlen = 2;
123+
116124
match sendmsg(sockfd, &msg, 0) {
117125
-1 => Result::Err(Error::OsError(io::Error::last_os_error())),
118126
_ => Result::Ok(()),

0 commit comments

Comments
 (0)