Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/mio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ impl Source for Socket {
}
}

#[cfg(target_endian = "little")]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While disabling this test module on big-endian systems makes the test suite pass, it hides an underlying issue and reduces test coverage. The problem is that the hardcoded netlink message in request_neighbour_dump is little-endian specific, which causes the test to fail on big-endian architectures.

A better approach would be to make the test endian-agnostic by constructing the message at runtime. This would fix the test on big-endian systems and restore test coverage.

Here is a suggested implementation for request_neighbour_dump that should work on all platforms:

fn request_neighbour_dump(socket: &mut Socket) -> std::io::Result<()> {
    let mut buf = [0u8; 28];
    // nl_msglen = 28
    buf[0..4].copy_from_slice(&28u32.to_ne_bytes());
    // nl_msgtype = 30 (RTM_GETNEIGH)
    buf[4..6].copy_from_slice(&30u16.to_ne_bytes());
    // nl_msgflags = NLM_F_REQUEST | NLM_F_DUMP = 0x0301
    buf[6..8].copy_from_slice(&0x0301u16.to_ne_bytes());
    // The rest is zeroed out, which is fine for seq, pid, and payload for this request.
    socket.send(&buf[..], 0)?;

    Ok(())
}

With this change, you can remove the #[cfg(target_endian = "little")] attribute.

#[cfg(test)]
mod tests {
use super::*;
Expand Down
12 changes: 6 additions & 6 deletions src/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ impl Socket {
libc::SOL_NETLINK,
libc::NETLINK_PKTINFO,
)?;
Ok(res == 1)
Ok(res != 0)
}

pub fn add_membership(&self, group: u32) -> Result<()> {
Expand Down Expand Up @@ -473,7 +473,7 @@ impl Socket {
libc::SOL_NETLINK,
libc::NETLINK_BROADCAST_ERROR,
)?;
Ok(res == 1)
Ok(res != 0)
}

/// `NETLINK_NO_ENOBUFS` (since Linux 2.6.30). This flag can be used by
Expand All @@ -494,7 +494,7 @@ impl Socket {
libc::SOL_NETLINK,
libc::NETLINK_NO_ENOBUFS,
)?;
Ok(res == 1)
Ok(res != 0)
}

/// `NETLINK_LISTEN_ALL_NSID` (since Linux 4.2). When set, this socket will
Expand All @@ -518,7 +518,7 @@ impl Socket {
libc::SOL_NETLINK,
libc::NETLINK_LISTEN_ALL_NSID,
)?;
Ok(res == 1)
Ok(res != 0)
}

/// `NETLINK_CAP_ACK` (since Linux 4.2). The kernel may fail to allocate the
Expand All @@ -543,7 +543,7 @@ impl Socket {
libc::SOL_NETLINK,
libc::NETLINK_CAP_ACK,
)?;
Ok(res == 1)
Ok(res != 0)
}

/// `NETLINK_EXT_ACK`
Expand All @@ -565,7 +565,7 @@ impl Socket {
libc::SOL_NETLINK,
libc::NETLINK_EXT_ACK,
)?;
Ok(res == 1)
Ok(res != 0)
}

/// Sets socket receive buffer in bytes.
Expand Down