aiortc / aioquic

QUIC and HTTP/3 implementation in Python

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

only support IPv6 socket?

lastpepole opened this issue · comments

in aioquic/asyncio/client.py file, line 70

# explicitly enable IPv4/IPv6 dual stack
sock = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)         // **only support IPv6 socket ?**
completed = False
try:
    sock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 0)
    sock.bind((local_host, local_port, 0, 0))
    completed = True
finally:
    if not completed:
        sock.close()

This is not v6-only. IPv6 can do both v4 and v6 on one socket via IPv4-mapped IPv6 addresses provided it's enabled. This code is explicitly enabling the IPv4 mapped addresses just in case the default has been set to off on a platform. Basically it's ensuring the IPv6-only option is off. If you look a bit above, you can see it constructing an IPv4 mapped address if needed:

if len(addr) == 2:
        addr = ("::ffff:" + addr[0], addr[1], 0, 0)

So, all is ok!