Skip to content

Commit 0260ee5

Browse files
committed
Winapi unions are a mess
1 parent e8c5da0 commit 0260ee5

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/sys/windows/tcp.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::os::windows::io::FromRawSocket;
77
use std::os::windows::raw::SOCKET as StdSocket; // winapi uses usize, stdlib uses u32/u64.
88

99
use winapi::ctypes::{c_char, c_int, c_ushort};
10-
use winapi::shared::ws2def::{SOCKADDR_STORAGE, AF_INET, SOCKADDR_IN};
10+
use winapi::shared::ws2def::{SOCKADDR_STORAGE, AF_INET, AF_INET6, SOCKADDR_IN};
1111
use winapi::shared::ws2ipdef::SOCKADDR_IN6;
1212

1313
use winapi::shared::minwindef::{BOOL, TRUE, FALSE};
@@ -120,12 +120,12 @@ pub(crate) fn get_localaddr(socket: TcpSocket) -> io::Result<SocketAddr> {
120120
_ => {
121121
if storage.ss_family as c_int == AF_INET {
122122
let addr: &SOCKADDR_IN = &*(&storage as *const _ as *const SOCKADDR_IN);
123-
let ip = Ipv4Addr::from(addr.sin_addr.s_addr.to_ne_bytes());
123+
let ip = Ipv4Addr::from(unsafe { addr.sin_addr.S_un.S_un_b() });
124124
let port = u16::from_be(addr.sin_port);
125125
Ok(SocketAddr::V4(SocketAddrV4::new(ip, port)))
126126
} else if storage.ss_family as c_int == AF_INET6 {
127127
let addr: &SOCKADDR_IN6 = &*(storage as *const _ as *const SOCKADDR_IN6);
128-
let ip = Ipv6Addr::from(addr.sin6_addr.s6_addr);
128+
let ip = Ipv6Addr::from(unsafe { addr.sin6_addr.u.Byte() });
129129
let port = u16::from_be(addr.sin6_port);
130130
let scope_id = unsafe { *addr.u.sin6_scope_id() };
131131
Ok(SocketAddr::V6(SocketAddrV6::new(ip, port, addr.sin6_flowinfo, scope_id)))

0 commit comments

Comments
 (0)