Skip to content

Allow Windows >= Vista to listen on dual-stack #34

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
14 changes: 11 additions & 3 deletions Socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,9 +404,17 @@ bool Socket::Bind(unsigned short port)
name.sin_port = htons(port);
addr = reinterpret_cast<sockaddr*>(&name);
len = sizeof(name);
}
else
{
} else {
#ifdef _WIN32
// attempt to listen on dual-stack instead of v6-only
// don't fail if this can't be set, just listen on v6-only
// this option only available on Vista and later
// ref: https://learn.microsoft.com/en-us/windows/win32/winsock/dual-stack-sockets
DWORD flag = 0; // defaults to 1
if (0 != setsockopt((ZSOCKET)m_socket, IPPROTO_IPV6, IPV6_V6ONLY, (const char *)&flag, sizeof(DWORD)))
LogWarning("Can't enable dual-stack socket, listening on IPv6 only\n");
#endif

memset(&name6, 0, sizeof(name6));

//Set port number
Expand Down