File tree Expand file tree Collapse file tree 1 file changed +3
-3
lines changed Expand file tree Collapse file tree 1 file changed +3
-3
lines changed Original file line number Diff line number Diff line change @@ -104,15 +104,15 @@ fn addr2raw(addr: &SocketAddr) -> (SocketAddrCRepr, c::socklen_t) {
104
104
match * addr {
105
105
SocketAddr :: V4 ( addr) => {
106
106
// `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 .
108
108
#[ cfg( unix) ]
109
109
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 ( ) ) } ,
111
111
} ;
112
112
#[ cfg( windows) ]
113
113
let sin_addr = unsafe {
114
114
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 ( ) ) ;
116
116
c:: IN_ADDR { S_un : s_un }
117
117
} ;
118
118
You can’t perform that action at this time.
0 commit comments