Skip to content

Commit

Permalink
Use socket.has_dualstack_ipv6()
Browse files Browse the repository at this point in the history
  • Loading branch information
catap committed Jul 7, 2024
1 parent 3c4a567 commit a468000
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions src/aioquic/asyncio/client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import asyncio
import socket
import sys
from contextlib import asynccontextmanager
from typing import AsyncGenerator, Callable, Optional, Tuple, Union, cast

Expand Down Expand Up @@ -60,12 +59,9 @@ async def connect(
token_handler=token_handler,
)

# OpenBSD well known to not support dual-stack
dual_stack = not sys.platform.startswith("openbsd")

# Use AI_ADDRCONFIG on platforms which doesn't support dual-stack
flags = 0
if not dual_stack:
if not socket.has_dualstack_ipv6():
flags = socket.AI_ADDRCONFIG

# lookup remote address
Expand All @@ -74,7 +70,7 @@ async def connect(
local_tuple: Union[Tuple[str, int], Tuple[str, int, int, int]]
addr = infos[0][4]
# addr is 2-tuple for AF_INET and 4-tuple for AF_INET6
if dual_stack and len(addr) == 2:
if socket.has_dualstack_ipv6() and len(addr) == 2:
addr = ("::ffff:" + addr[0], addr[1], 0, 0)
local_tuple = ("::", local_port, 0, 0)
sock = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
Expand Down

0 comments on commit a468000

Please sign in to comment.