Skip to content

Commit f3bf1b9

Browse files
committed
fix: send ETH_P_ALL in htons format
1 parent b2318f9 commit f3bf1b9

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/sys/socket/mod.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,13 @@ impl TryFrom<i32> for SockType {
117117
}
118118
}
119119

120+
/// htons_i32 converts the lower 16 bits of the value into network order and
121+
/// returns it as an i32. e.g. 0x0000ABCD => 0x0000CDAB
122+
#[cfg(any(target_os = "android", target_os = "linux"))]
123+
const fn htons_i32(v: i32) -> i32 {
124+
(v as u16).to_be() as i32
125+
}
126+
120127
/// Constants used in [`socket`](fn.socket.html) and [`socketpair`](fn.socketpair.html)
121128
/// to specify the protocol to use.
122129
#[repr(i32)]
@@ -217,7 +224,7 @@ pub enum SockProtocol {
217224
// The protocol number is fed into the socket syscall in network byte order.
218225
#[cfg(any(target_os = "android", target_os = "linux"))]
219226
#[cfg_attr(docsrs, doc(cfg(all())))]
220-
EthAll = libc::ETH_P_ALL.to_be(),
227+
EthAll = htons_i32(libc::ETH_P_ALL),
221228
/// The Controller Area Network raw socket protocol
222229
/// ([ref](https://docs.kernel.org/networking/can.html#how-to-use-socketcan))
223230
#[cfg(target_os = "linux")]

0 commit comments

Comments
 (0)