Skip to content

parsed_scoped_addresses() may return link-local IPv6 addresses with %0 as the scope id. #1361

@twslankard

Description

@twslankard

OS: Ubuntu 22.04.3 LTS
Python: 3.10.12 (though the issue occurs with 3.12 as well.)
zeroconf: 0.131.0

Hi all,

I've noticed that the parsed_scoped_addresses() will sometimes return IPv6 addresses with the scope ID uninitialized, e.g. fe80::be0f:a7ff:fe00:8a54%0.

When using the address this naturally results in an invalid argument (errno 22) OSError (e.g. from socket.connect.)

Here's some code I've been using to replicate the issue. (Naturally, replicating the issue requires that there be some services on the network matching those specified in the code.) Any idea what I'm doing wrong?

import time
from zeroconf import ServiceBrowser, ServiceListener, Zeroconf, InterfaceChoice, IPVersion

class MyListener(ServiceListener):

    def __init__(self):
        self.address_cache_ = {}

    def update_service(self, zc: Zeroconf, type_: str, name: str) -> None:
        pass

    def remove_service(self, zc: Zeroconf, type_: str, name: str) -> None:
        pass

    def add_service(self, zc: Zeroconf, type_: str, name: str) -> None:
        info = zc.get_service_info(type_, name)
        if info:
            print(info.parsed_scoped_addresses())

zeroconf = Zeroconf(InterfaceChoice.All, False, IPVersion.All)
listener = MyListener()
browser = ServiceBrowser(zeroconf, ["_roger._tcp.local.", "_ouster-lidar._tcp.local."], listener)
time.sleep(10)
zeroconf.close()

Here is some output from the script showing the addresses with the uninitialized scope ids:

['<redacted>.65', 'fe80::be0f:a7ff:fe00:8a98%0', '<redacted>:8a98']
['<redacted>.65', 'fe80::be0f:a7ff:fe00:8a98%0', '<redacted>:8a98']
['<redacted>.124', 'fe80::be0f:a7ff:fe00:8a54%0', '<redacted>:8a54']
['<redacted>.124', 'fe80::be0f:a7ff:fe00:8a54%0', '<redacted>:8a54']
['<redacted>.149']
['<redacted>.149']
['<redacted>.24', 'fe80::be0f:a7ff:fe00:8a20%0', '<redacted>:8a20']
['<redacted>.24', 'fe80::be0f:a7ff:fe00:8a20%0', '<redacted>:8a20']
['<redacted>.200', 'fe80::be0f:a7ff:fe00:9bd9%0', '<redacted>:9bd9']
['<redacted>.200', 'fe80::be0f:a7ff:fe00:9bd9%0', '<redacted>:9bd9']
['<redacted>.114', 'fe80::be0f:a7ff:fe00:83bc%0', '<redacted>:83bc']
['<redacted>.114', 'fe80::be0f:a7ff:fe00:83bc%0', '<redacted>:83bc']
['<redacted>.184', 'fe80::be0f:a7ff:fe00:8be5%0', '<redacted>:8be5']
['<redacted>.184', 'fe80::be0f:a7ff:fe00:8be5%0', '<redacted>:8be5']

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