Skip to content

Interface option InterfaceChoice.Default not working for IPv6 #1562

@agners

Description

@agners

When trying to use InterfaceChoice.Default with IPv6 on Linux Python Zeroconf isn't able to start browsing/sending frames:

E.g. running this snipped:

import asyncio
import logging
from zeroconf import (
    DNSQuestionType,
    InterfaceChoice,
    IPVersion,
    ServiceStateChange,
    Zeroconf,
)
from zeroconf.asyncio import AsyncServiceBrowser, AsyncZeroconf

logging.basicConfig(format='%(asctime)s %(message)s', level=logging.INFO)
logging.getLogger("zeroconf").setLevel(logging.DEBUG)

def service_browser_handler(zeroconf: Zeroconf, service_type: str, name: str, state_change: ServiceStateChange) -> None:
    logging.info("mDNS service state change: %s - %s - %s", name, service_type, state_change)


async def browse_service():
    _aiozc = AsyncZeroconf(interfaces=InterfaceChoice.Default, ip_version=IPVersion.V6Only)
    _aiobrowser = AsyncServiceBrowser(
        _aiozc.zeroconf,
        ["_matter._tcp.local."],
        handlers=[service_browser_handler],
        question_type=DNSQuestionType.QM,
    )
	await asyncio.sleep(5)

asyncio.run(browse_service())

The same is true when trying to use dual-stack with IPVersion.All. Also the question type doesn't matter DNSQuestionType.QU won't get delivered either.

Leads to the following output:

2025-04-10 16:17:46,736 Creating new socket with port 5353, ip_version IPVersion.V6Only, apple_p2p False and bind_addr ('',)
2025-04-10 16:17:46,736 Created socket <socket.socket fd=8, family=10, type=2, proto=0, laddr=('::', 5353, 0, 0)>
2025-04-10 16:17:46,736 Adding (('', 0, 0), 0) (socket 8) to multicast group
2025-04-10 16:17:46,736 Listen socket <socket.socket fd=8, family=10, type=2, proto=0, laddr=('::', 5353, 0, 0)>, respond sockets [<socket.socket fd=8, family=10, type=2, proto=0, laddr=('::', 5353, 0, 0)>]
2025-04-10 16:17:46,781 offsets = questions=0, answers=0, authorities=0, additionals=0
2025-04-10 16:17:46,782 lengths = questions=1, answers=0, authorities=0, additionals=0
2025-04-10 16:17:46,782 now offsets = questions=1, answers=0, authorities=0, additionals=0
2025-04-10 16:17:46,782 Sending to (ff02::fb, 5353) via [socket 8 (('::', 5353, 0, 0))] (36 bytes #1) <DNSOutgoing:multicast=True, flags=0, questions=[ptr[question,QM,in,_matter._tcp.local.]], answers=[], authorities=[], additionals=[]> as b'\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x07_matter\x04_tcp\x05local\x00\x00\x0c\x00\x01'...
2025-04-10 16:17:46,782 Error with socket 8 (('::', 5353, 0, 0))): [Errno 99] Cannot assign requested address
Traceback (most recent call last):
  File "/usr/lib/python3.13/asyncio/selector_events.py", line 1268, in sendto
    self._sock.sendto(data, addr)
    ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^
OSError: [Errno 99] Cannot assign requested address

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions