Skip to content

Use Bool (1 byte) for IPV6_V6ONLY on Windows #593

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion src/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1935,7 +1935,7 @@ impl Socket {
/// [`set_only_v6`]: Socket::set_only_v6
pub fn only_v6(&self) -> io::Result<bool> {
unsafe {
getsockopt::<c_int>(self.as_raw(), sys::IPPROTO_IPV6, sys::IPV6_V6ONLY)
getsockopt::<Bool>(self.as_raw(), sys::IPPROTO_IPV6, sys::IPV6_V6ONLY)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the docs it's a DWORD that only takes the values 0 or 1.

Copy link
Collaborator Author

@Thomasdezeeuw Thomasdezeeuw Jul 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Windows docs are wrong a couple of places. For example for TCP_NODELAY, it says it's "DWORD (Boolean)", source: https://learn.microsoft.com/en-us/windows/win32/winsock/ipproto-tcp-socket-options. But it's actually a 1 byte boolean:

getsockopt::<Bool>(self.as_raw(), sys::IPPROTO_TCP, sys::TCP_NODELAY)

pub(crate) type Bool = windows_sys::Win32::Foundation::BOOLEAN;

https://docs.rs/windows-sys/0.59.0/windows_sys/Win32/Foundation/type.BOOLEAN.html

In this case, I think it's actually correct though and it's the 4 byte boolean version (https://docs.rs/windows-sys/0.59.0/windows_sys/Win32/Foundation/type.BOOL.html, yup we have BOOLEAN and BOOL and they're different types 🙂)

.map(|only_v6| only_v6 != 0)
}
}
Expand Down
Loading