gh-154291: Fix socket.has_dualstack_ipv6() on DragonFly BSD (GH-154292)

On DragonFly BSD setsockopt(IPPROTO_IPV6, IPV6_V6ONLY, 0) succeeds without
actually clearing the flag, so has_dualstack_ipv6() wrongly returned True.
Verify with getsockopt() that IPV6_V6ONLY was cleared.

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Serhiy StorchakaandClaude Opus 4.8 authored and GitHub committed 2026-07-20 19:59:56 +00:00
1 parent 96059f9446
commit c7bbf040e7
2 files changed
+6 -1

No files matched your search

+3 -1
View File
@@ -900,7 +900,9 @@ def has_dualstack_ipv6():
try:
with socket(AF_INET6, SOCK_STREAM) as sock:
sock.setsockopt(IPPROTO_IPV6, IPV6_V6ONLY, 0)
return True
# On some platforms (e.g. DragonFly BSD) setting IPV6_V6ONLY to 0
# silently has no effect, so check that it was actually cleared.
return sock.getsockopt(IPPROTO_IPV6, IPV6_V6ONLY) == 0
except error:
return False
@@ -0,0 +1,3 @@
Fix :func:`socket.has_dualstack_ipv6` to return ``False`` on platforms such as
DragonFly BSD where setting ``IPV6_V6ONLY`` to 0 silently has no
effect.