Skip to content

Commit f9b33b0

Browse files
committed
Use transmute instead of u32::from_ne_bytes to support older Rust
1 parent d07960f commit f9b33b0

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/socket.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,15 @@ fn addr2raw(addr: &SocketAddr) -> (SocketAddrCRepr, c::socklen_t) {
104104
match *addr {
105105
SocketAddr::V4(addr) => {
106106
// `s_addr` is stored as BE on all machine and the array is in BE order.
107-
// So the native endian conversion method is used so that it's never swapped.
107+
// So just transmuting the octects to the `u32` representation works.
108108
#[cfg(unix)]
109109
let sin_addr = c::in_addr {
110-
s_addr: u32::from_ne_bytes(addr.ip().octets()),
110+
s_addr: unsafe { mem::transmute::<_, u32>(addr.ip().octets()) },
111111
};
112112
#[cfg(windows)]
113113
let sin_addr = unsafe {
114114
let mut s_un = mem::zeroed::<c::in_addr_S_un>();
115-
*s_un.S_addr_mut() = u32::from_ne_bytes(addr.ip().octets());
115+
*s_un.S_addr_mut() = mem::transmute::<_, u32>(addr.ip().octets());
116116
c::IN_ADDR { S_un: s_un }
117117
};
118118

0 commit comments

Comments
 (0)