Skip to content

Commit 4294605

Browse files
miss-islingtonserhiy-storchakaclaude
authored
[3.15] gh-154291: Fix socket.has_dualstack_ipv6() on DragonFly BSD (GH-154292) (GH-154299)
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. (cherry picked from commit c7bbf04) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 387f7cd commit 4294605

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

Lib/socket.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,9 @@ def has_dualstack_ipv6():
900900
try:
901901
with socket(AF_INET6, SOCK_STREAM) as sock:
902902
sock.setsockopt(IPPROTO_IPV6, IPV6_V6ONLY, 0)
903-
return True
903+
# On some platforms (e.g. DragonFly BSD) setting IPV6_V6ONLY to 0
904+
# silently has no effect, so check that it was actually cleared.
905+
return sock.getsockopt(IPPROTO_IPV6, IPV6_V6ONLY) == 0
904906
except error:
905907
return False
906908

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix :func:`socket.has_dualstack_ipv6` to return ``False`` on platforms such as
2+
DragonFly BSD where setting ``IPV6_V6ONLY`` to 0 silently has no
3+
effect.

0 commit comments

Comments
 (0)