Skip to content

Commit b2e8bd6

Browse files
miss-islingtonserhiy-storchakaclaude
authored
[3.14] gh-154291: Fix socket.has_dualstack_ipv6() on DragonFly BSD (GH-154292) (GH-154300)
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 903265f commit b2e8bd6

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
@@ -891,7 +891,9 @@ def has_dualstack_ipv6():
891891
try:
892892
with socket(AF_INET6, SOCK_STREAM) as sock:
893893
sock.setsockopt(IPPROTO_IPV6, IPV6_V6ONLY, 0)
894-
return True
894+
# On some platforms (e.g. DragonFly BSD) setting IPV6_V6ONLY to 0
895+
# silently has no effect, so check that it was actually cleared.
896+
return sock.getsockopt(IPPROTO_IPV6, IPV6_V6ONLY) == 0
895897
except error:
896898
return False
897899

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)