Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1932,10 +1932,13 @@ impl Socket {
///
/// [`set_only_v6`]: Socket::set_only_v6
pub fn only_v6(&self) -> io::Result<bool> {
#[cfg(not(windows))]
unsafe {
getsockopt::<c_int>(self.as_raw(), sys::IPPROTO_IPV6, sys::IPV6_V6ONLY)
getsockopt::<Bool>(self.as_raw(), sys::IPPROTO_IPV6, sys::IPV6_V6ONLY)
.map(|only_v6| only_v6 != 0)
}
#[cfg(windows)]
sys::only_v6(self.as_raw())
}

/// Set the value for the `IPV6_V6ONLY` option on this socket.
Expand Down
20 changes: 20 additions & 0 deletions src/sys/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,26 @@ pub(crate) fn to_mreqn(
}
}

pub(crate) fn only_v6(socket: RawSocket) -> io::Result<bool> {
let mut optval: c_int = 0; // input must be 4 bytes (DWORD)
let mut optlen = mem::size_of_val(&optval) as c_int;
syscall!(
getsockopt(
socket,
IPPROTO_IPV6 as i32,
IPV6_V6ONLY,
ptr::from_mut(&mut optval).cast(),
&mut optlen,
),
PartialEq::eq,
SOCKET_ERROR
)
.map(|_| {
// optlen may be 1, which won't match the input size of optval
optval != 0
})
}

#[cfg(feature = "all")]
pub(crate) fn original_dst_v4(socket: RawSocket) -> io::Result<SockAddr> {
unsafe {
Expand Down