Skip to content

Commit a10636b

Browse files
committed
fix: send ETH_P_ALL in htons format
1 parent 67f7d46 commit a10636b

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/sys/socket/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,12 @@ 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+
const fn htons_i32(v: i32) -> i32 {
123+
(v as u16).to_be() as i32
124+
}
125+
120126
/// Constants used in [`socket`](fn.socket.html) and [`socketpair`](fn.socketpair.html)
121127
/// to specify the protocol to use.
122128
#[repr(i32)]
@@ -217,7 +223,7 @@ pub enum SockProtocol {
217223
// The protocol number is fed into the socket syscall in network byte order.
218224
#[cfg(any(target_os = "android", target_os = "linux"))]
219225
#[cfg_attr(docsrs, doc(cfg(all())))]
220-
EthAll = libc::ETH_P_ALL.to_be(),
226+
EthAll = htons_i32(libc::ETH_P_ALL),
221227
}
222228

223229
#[cfg(any(target_os = "linux"))]

0 commit comments

Comments
 (0)