From: Serhiy Storchaka Date: Mon, 20 Jul 2026 19:59:56 +0000 (+0300) Subject: gh-154291: Fix socket.has_dualstack_ipv6() on DragonFly BSD (GH-154292) X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c7bbf040e721781be8f11a3b0716220835d4de2f;p=thirdparty%2FPython%2Fcpython.git 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) --- diff --git a/Lib/socket.py b/Lib/socket.py index 03c3fe88f15c..2a4f875f76b0 100644 --- a/Lib/socket.py +++ b/Lib/socket.py @@ -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 diff --git a/Misc/NEWS.d/next/Library/2026-07-20-22-03-44.gh-issue-154291.Mi5HeQ.rst b/Misc/NEWS.d/next/Library/2026-07-20-22-03-44.gh-issue-154291.Mi5HeQ.rst new file mode 100644 index 000000000000..d962f8987ad4 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-07-20-22-03-44.gh-issue-154291.Mi5HeQ.rst @@ -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.