Skip to content

Commit 4833e1c

Browse files
miss-islingtonserhiy-storchakaclaude
authored
[3.13] gh-154291: Fix socket.has_dualstack_ipv6() on DragonFly BSD (GH-154292) (GH-154301)
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 6531253 commit 4833e1c

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
@@ -885,7 +885,9 @@ def has_dualstack_ipv6():
885885
try:
886886
with socket(AF_INET6, SOCK_STREAM) as sock:
887887
sock.setsockopt(IPPROTO_IPV6, IPV6_V6ONLY, 0)
888-
return True
888+
# On some platforms (e.g. DragonFly BSD) setting IPV6_V6ONLY to 0
889+
# silently has no effect, so check that it was actually cleared.
890+
return sock.getsockopt(IPPROTO_IPV6, IPV6_V6ONLY) == 0
889891
except error:
890892
return False
891893

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)