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

Closed
wants to merge 1 commit into from

Conversation

Thomasdezeeuw
Copy link
Collaborator

Closes #564

@Thomasdezeeuw
Copy link
Collaborator Author

Already tested here:

socket2/tests/socket.rs

Lines 1471 to 1472 in 0c9efe1

#[cfg(any(windows, target_os = "freebsd", target_os = "cygwin"))]
test!(IPv6 only_v6, set_only_v6(false));

So not sure how this slipped through 🤔

@@ -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 🙂)

Copy link
Collaborator

Choose a reason for hiding this comment

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

yup we have BOOLEAN and BOOL and they're different types 🙂

😂

@Thomasdezeeuw
Copy link
Collaborator Author

Since this is clearly incorrect, see failing test, I'm closing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

only_v6 panic on windows
2 participants