From b563f52a8181fea7d341aa383a0489dcce08251f Mon Sep 17 00:00:00 2001 From: Emil Styrke Date: Wed, 25 Sep 2019 13:43:11 +0200 Subject: [PATCH 01/13] Fixes for OS X * Listen on respond_sockets in addition to listen_socket * Do not bind to respond_sockets in multicast mode Without either of these changes, I get no replies at all when browsing for services using the browser example. I'm on a corporate network, and when connecting to a different network it works without these changes, so maybe it's something about the network configuration in this particular network that breaks the previous behavior. Unfortunately, I have no idea how this affects other platforms, or what the changes really mean. However, it works for me and it seems reasonable to get replies back on the same socket where they are sent. --- zeroconf/__init__.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/zeroconf/__init__.py b/zeroconf/__init__.py index 17e6ef2f..a8a7c4a6 100644 --- a/zeroconf/__init__.py +++ b/zeroconf/__init__.py @@ -2090,7 +2090,10 @@ def normalize_interface_choice( def new_socket( - port: int = _MDNS_PORT, ip_version: IPVersion = IPVersion.V4Only, apple_p2p: bool = False + port: int = _MDNS_PORT, + ip_version: IPVersion = IPVersion.V4Only, + apple_p2p: bool = False, + bind_addr: str = None, ) -> socket.socket: if ip_version == IPVersion.V4Only: s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) @@ -2143,7 +2146,9 @@ def new_socket( # https://opensource.apple.com/source/xnu/xnu-4570.41.2/bsd/sys/socket.h s.setsockopt(socket.SOL_SOCKET, 0x1104, 1) - s.bind(('', port)) + if bind_addr is not None: + s.bind((bind_addr, port)) + return s @@ -2205,7 +2210,7 @@ def create_sockets( if unicast: listen_socket = None else: - listen_socket = new_socket(ip_version=ip_version, apple_p2p=apple_p2p) + listen_socket = new_socket(ip_version=ip_version, apple_p2p=apple_p2p, bind_addr='') interfaces = normalize_interface_choice(interfaces, ip_version) @@ -2215,7 +2220,7 @@ def create_sockets( if not unicast: respond_socket = add_multicast_member(cast(socket.socket, listen_socket), i, apple_p2p=apple_p2p) else: - respond_socket = new_socket(port=0, ip_version=ip_version, apple_p2p=apple_p2p) + respond_socket = new_socket(port=0, ip_version=ip_version, apple_p2p=apple_p2p, bind_addr='') if respond_socket is not None: respond_sockets.append(respond_socket) @@ -2306,9 +2311,8 @@ def __init__( self.listener = Listener(self) if not unicast: self.engine.add_reader(self.listener, cast(socket.socket, self._listen_socket)) - else: - for s in self._respond_sockets: - self.engine.add_reader(self.listener, s) + for s in self._respond_sockets: + self.engine.add_reader(self.listener, s) self.reaper = Reaper(self) self.debug = None # type: Optional[DNSOutgoing] From 2132860659c8636c8f6bd91d7c9cde32154162e4 Mon Sep 17 00:00:00 2001 From: Jakub Stasiak Date: Sun, 31 May 2020 23:43:06 +0200 Subject: [PATCH 02/13] Log listen and respond sockets --- zeroconf/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/zeroconf/__init__.py b/zeroconf/__init__.py index a8a7c4a6..63c4af87 100644 --- a/zeroconf/__init__.py +++ b/zeroconf/__init__.py @@ -2292,6 +2292,7 @@ def __init__( self._listen_socket, self._respond_sockets = create_sockets( interfaces, unicast, ip_version, apple_p2p=apple_p2p ) + log.debug('Listen socket %r, respond sockets %s', self._listen_socket, self._respond_sockets) self.listeners = [] # type: List[RecordUpdateListener] self.browsers = {} # type: Dict[ServiceListener, ServiceBrowser] From 898efee365865af49d1912a876463485c6bc4a02 Mon Sep 17 00:00:00 2001 From: Jakub Stasiak Date: Mon, 1 Jun 2020 00:48:56 +0200 Subject: [PATCH 03/13] Bind responding sockets to ddresses of their interfaces only This is an attempt to still send packets with the correct source port yet not bind to INADDR_ANY so that the original use case of this pull request is taken care of. --- zeroconf/__init__.py | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/zeroconf/__init__.py b/zeroconf/__init__.py index 63c4af87..d73888c6 100644 --- a/zeroconf/__init__.py +++ b/zeroconf/__init__.py @@ -2003,18 +2003,26 @@ def get_all_addresses() -> List[str]: return list(set(addr.ip for iface in ifaddr.get_adapters() for addr in iface.ips if addr.is_IPv4)) -def get_all_addresses_v6() -> List[int]: +def get_all_addresses_v6() -> List[Tuple[str, int]]: # IPv6 multicast uses positive indexes for interfaces try: - nameindex = socket.if_nameindex + nameindex = socket.if_nametoindex except AttributeError: # Requires Python 3.8 on Windows. Fall back to Default. QuietLogger.log_warning_once( 'if_nameindex is not available, falling back to using the default IPv6 interface' ) - return [0] - - return [tpl[0] for tpl in nameindex()] + return [('', 0)] + + # TODO: What about multi-address interfaces? + return list( + set( + (addr.ip, socket.if_nametoindex(iface.name)) + for iface in ifaddr.get_adapters() + for addr in iface.ips + if addr.is_IPv6 + ) + ) def ip_to_index(adapters: List[Any], ip: str) -> int: @@ -2033,7 +2041,7 @@ def ip_to_index(adapters: List[Any], ip: str) -> int: raise RuntimeError('No adapter found for IP address %s' % ip) -def ip6_addresses_to_indexes(interfaces: List[Union[str, int]]) -> List[int]: +def ip6_addresses_to_indexes(interfaces: List[Union[str, int]]) -> List[Tuple[str, int]]: """Convert IPv6 interface addresses to interface indexes. IPv4 addresses are ignored. The conversion currently only works on POSIX @@ -2056,7 +2064,7 @@ def ip6_addresses_to_indexes(interfaces: List[Union[str, int]]) -> List[int]: def normalize_interface_choice( choice: InterfacesType, ip_version: IPVersion = IPVersion.V4Only -) -> List[Union[str, int]]: +) -> List[Union[str, Tuple[str, int]]]: """Convert the interfaces choice into internal representation. :param choice: `InterfaceChoice` or list of interface addresses or indexes (IPv6 only). @@ -2093,7 +2101,7 @@ def new_socket( port: int = _MDNS_PORT, ip_version: IPVersion = IPVersion.V4Only, apple_p2p: bool = False, - bind_addr: str = None, + bind_addr: str = '', ) -> socket.socket: if ip_version == IPVersion.V4Only: s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) @@ -2146,14 +2154,13 @@ def new_socket( # https://opensource.apple.com/source/xnu/xnu-4570.41.2/bsd/sys/socket.h s.setsockopt(socket.SOL_SOCKET, 0x1104, 1) - if bind_addr is not None: - s.bind((bind_addr, port)) + s.bind((bind_addr, port)) return s def add_multicast_member( - listen_socket: socket.socket, interface: Union[str, int], apple_p2p: bool = False + listen_socket: socket.socket, interface: Union[str, Tuple[str, int]], apple_p2p: bool = False ) -> Optional[socket.socket]: # This is based on assumptions in normalize_interface_choice is_v6 = isinstance(interface, int) @@ -2189,7 +2196,9 @@ def add_multicast_member( raise respond_socket = new_socket( - ip_version=(IPVersion.V6Only if is_v6 else IPVersion.V4Only), apple_p2p=apple_p2p + ip_version=(IPVersion.V6Only if is_v6 else IPVersion.V4Only), + apple_p2p=apple_p2p, + bind_addr=interface[0] if is_v6 else interface, ) log.debug('Configuring socket %d with multicast interface %s', respond_socket, interface) if is_v6: From ee6c5510154e5a16968f63a6e9376f68b71ef918 Mon Sep 17 00:00:00 2001 From: Jakub Stasiak Date: Mon, 1 Jun 2020 01:06:09 +0200 Subject: [PATCH 04/13] Fix some type mismatches --- zeroconf/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/zeroconf/__init__.py b/zeroconf/__init__.py index d73888c6..3c1cbf02 100644 --- a/zeroconf/__init__.py +++ b/zeroconf/__init__.py @@ -2163,11 +2163,11 @@ def add_multicast_member( listen_socket: socket.socket, interface: Union[str, Tuple[str, int]], apple_p2p: bool = False ) -> Optional[socket.socket]: # This is based on assumptions in normalize_interface_choice - is_v6 = isinstance(interface, int) + is_v6 = isinstance(interface, tuple) log.debug('Adding %r (socket %d) to multicast group', interface, listen_socket.fileno()) try: if is_v6: - iface_bin = struct.pack('@I', cast(int, interface)) + iface_bin = struct.pack('@I', cast(int, interface[1])) _value = _MDNS_ADDR6_BYTES + iface_bin listen_socket.setsockopt(_IPPROTO_IPV6, socket.IPV6_JOIN_GROUP, _value) else: From 10b261a87276137076bd0cac12952a115e1b5dba Mon Sep 17 00:00:00 2001 From: Jakub Stasiak Date: Tue, 2 Jun 2020 13:06:13 +0200 Subject: [PATCH 05/13] Fix binding IPv6 sockets, they need scope ids to work It has some dirty log.debug changes too, I'll clean it up once it works. Also it's a tangled mess of tuples now, I'll also deal with that when there's time to do it. --- zeroconf/__init__.py | 57 +++++++++++++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 19 deletions(-) diff --git a/zeroconf/__init__.py b/zeroconf/__init__.py index 3c1cbf02..216fece8 100644 --- a/zeroconf/__init__.py +++ b/zeroconf/__init__.py @@ -190,7 +190,7 @@ class InterfaceChoice(enum.Enum): All = 2 -InterfacesType = Union[List[Union[str, int]], InterfaceChoice] +InterfacesType = Union[List[Union[str, Tuple[Tuple[str, int, int], int]]], InterfaceChoice] @enum.unique @@ -2003,7 +2003,7 @@ def get_all_addresses() -> List[str]: return list(set(addr.ip for iface in ifaddr.get_adapters() for addr in iface.ips if addr.is_IPv4)) -def get_all_addresses_v6() -> List[Tuple[str, int]]: +def get_all_addresses_v6() -> List[Tuple[Tuple[str, int, int], int]]: # IPv6 multicast uses positive indexes for interfaces try: nameindex = socket.if_nametoindex @@ -2012,7 +2012,7 @@ def get_all_addresses_v6() -> List[Tuple[str, int]]: QuietLogger.log_warning_once( 'if_nameindex is not available, falling back to using the default IPv6 interface' ) - return [('', 0)] + return [(('', 0, 0), 0)] # TODO: What about multi-address interfaces? return list( @@ -2025,7 +2025,7 @@ def get_all_addresses_v6() -> List[Tuple[str, int]]: ) -def ip_to_index(adapters: List[Any], ip: str) -> int: +def ip6_to_address_and_index(adapters: List[Any], ip: str) -> Tuple[Tuple[str, int, int], int]: if os.name != 'posix': # Adapter names that ifaddr reports are not compatible with what if_nametoindex expects on Windows. # We need https://github.com/pydron/ifaddr/pull/21 but it seems stuck on review. @@ -2036,12 +2036,14 @@ def ip_to_index(adapters: List[Any], ip: str) -> int: for adapter_ip in adapter.ips: # IPv6 addresses are represented as tuples if isinstance(adapter_ip.ip, tuple) and ipaddress.ip_address(adapter_ip.ip[0]) == ipaddr: - return socket.if_nametoindex(adapter.name) + return (cast(Tuple[str, int, int], adapter_ip.ip), socket.if_nametoindex(adapter.name)) raise RuntimeError('No adapter found for IP address %s' % ip) -def ip6_addresses_to_indexes(interfaces: List[Union[str, int]]) -> List[Tuple[str, int]]: +def ip6_addresses_to_indexes( + interfaces: List[Union[str, Tuple[Tuple[str, int, int], int]]] +) -> List[Tuple[Tuple[str, int, int], int]]: """Convert IPv6 interface addresses to interface indexes. IPv4 addresses are ignored. The conversion currently only works on POSIX @@ -2055,27 +2057,29 @@ def ip6_addresses_to_indexes(interfaces: List[Union[str, int]]) -> List[Tuple[st for iface in interfaces: if isinstance(iface, int): - result.append(iface) + # Temporarily disabled to validate something else + # result.append(iface) + pass elif isinstance(iface, str) and ipaddress.ip_address(iface).version == 6: - result.append(ip_to_index(adapters, iface)) + result.append(ip6_to_address_and_index(adapters, iface)) return result def normalize_interface_choice( choice: InterfacesType, ip_version: IPVersion = IPVersion.V4Only -) -> List[Union[str, Tuple[str, int]]]: +) -> List[Union[str, Tuple[Tuple[str, int, int], int]]]: """Convert the interfaces choice into internal representation. :param choice: `InterfaceChoice` or list of interface addresses or indexes (IPv6 only). :param ip_address: IP version to use (ignored if `choice` is a list). :returns: List of IP addresses (for IPv4) and indexes (for IPv6). """ - result = [] # type: List[Union[str, int]] + result = [] # type: List[Union[str, Tuple[Tuple[str, int, int], int]]] if choice is InterfaceChoice.Default: if ip_version != IPVersion.V4Only: # IPv6 multicast uses interface 0 to mean the default - result.append(0) + result.append((('', 0, 0), 0)) if ip_version != IPVersion.V6Only: result.append('0.0.0.0') elif choice is InterfaceChoice.All: @@ -2098,11 +2102,18 @@ def normalize_interface_choice( def new_socket( + bind_addr: Union[Tuple[str], Tuple[str, int, int]], port: int = _MDNS_PORT, ip_version: IPVersion = IPVersion.V4Only, apple_p2p: bool = False, - bind_addr: str = '', ) -> socket.socket: + log.debug( + 'Creating new socket with port %s, ip_version %s, apple_p2p %s and bind_addr %r', + port, + ip_version, + apple_p2p, + bind_addr, + ) if ip_version == IPVersion.V4Only: s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) else: @@ -2154,15 +2165,18 @@ def new_socket( # https://opensource.apple.com/source/xnu/xnu-4570.41.2/bsd/sys/socket.h s.setsockopt(socket.SOL_SOCKET, 0x1104, 1) - s.bind((bind_addr, port)) - + s.bind((bind_addr[0], port, *bind_addr[1:])) + log.debug('Created socket %s', s) return s def add_multicast_member( - listen_socket: socket.socket, interface: Union[str, Tuple[str, int]], apple_p2p: bool = False + listen_socket: socket.socket, + interface: Union[str, Tuple[Tuple[str, int, int], int]], + apple_p2p: bool = False, ) -> Optional[socket.socket]: # This is based on assumptions in normalize_interface_choice + print(interface) is_v6 = isinstance(interface, tuple) log.debug('Adding %r (socket %d) to multicast group', interface, listen_socket.fileno()) try: @@ -2198,9 +2212,9 @@ def add_multicast_member( respond_socket = new_socket( ip_version=(IPVersion.V6Only if is_v6 else IPVersion.V4Only), apple_p2p=apple_p2p, - bind_addr=interface[0] if is_v6 else interface, + bind_addr=cast(Tuple[Tuple[str, int, int], int], interface)[0] if is_v6 else (cast(str, interface),), ) - log.debug('Configuring socket %d with multicast interface %s', respond_socket, interface) + log.debug('Configuring socket %s with multicast interface %s', respond_socket, interface) if is_v6: respond_socket.setsockopt(_IPPROTO_IPV6, socket.IPV6_MULTICAST_IF, iface_bin) else: @@ -2219,7 +2233,7 @@ def create_sockets( if unicast: listen_socket = None else: - listen_socket = new_socket(ip_version=ip_version, apple_p2p=apple_p2p, bind_addr='') + listen_socket = new_socket(ip_version=ip_version, apple_p2p=apple_p2p, bind_addr=('',)) interfaces = normalize_interface_choice(interfaces, ip_version) @@ -2229,7 +2243,12 @@ def create_sockets( if not unicast: respond_socket = add_multicast_member(cast(socket.socket, listen_socket), i, apple_p2p=apple_p2p) else: - respond_socket = new_socket(port=0, ip_version=ip_version, apple_p2p=apple_p2p, bind_addr='') + respond_socket = new_socket( + port=0, + ip_version=ip_version, + apple_p2p=apple_p2p, + bind_addr=i[0] if isinstance(i, tuple) else (i,), + ) if respond_socket is not None: respond_sockets.append(respond_socket) From ac30ef8cbe548f9e621404068e697af7c80377be Mon Sep 17 00:00:00 2001 From: Jakub Stasiak Date: Tue, 2 Jun 2020 13:54:07 +0200 Subject: [PATCH 06/13] Remove unused variable --- zeroconf/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zeroconf/__init__.py b/zeroconf/__init__.py index 216fece8..76903fe2 100644 --- a/zeroconf/__init__.py +++ b/zeroconf/__init__.py @@ -2006,7 +2006,7 @@ def get_all_addresses() -> List[str]: def get_all_addresses_v6() -> List[Tuple[Tuple[str, int, int], int]]: # IPv6 multicast uses positive indexes for interfaces try: - nameindex = socket.if_nametoindex + socket.if_nametoindex except AttributeError: # Requires Python 3.8 on Windows. Fall back to Default. QuietLogger.log_warning_once( From 36e5b8180be368921ead08d032f902d11c5e4900 Mon Sep 17 00:00:00 2001 From: Jakub Stasiak Date: Tue, 2 Jun 2020 13:59:47 +0200 Subject: [PATCH 07/13] Crash in case of temporarily disabled behavior being triggered --- zeroconf/__init__.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/zeroconf/__init__.py b/zeroconf/__init__.py index 76903fe2..0a8eaa15 100644 --- a/zeroconf/__init__.py +++ b/zeroconf/__init__.py @@ -2057,9 +2057,8 @@ def ip6_addresses_to_indexes( for iface in interfaces: if isinstance(iface, int): - # Temporarily disabled to validate something else + assert False, 'Temporarily disabled to test something else' # result.append(iface) - pass elif isinstance(iface, str) and ipaddress.ip_address(iface).version == 6: result.append(ip6_to_address_and_index(adapters, iface)) From 76751a6d692b8291f10444b5b3f288fe6820a89d Mon Sep 17 00:00:00 2001 From: Jakub Stasiak Date: Tue, 2 Jun 2020 14:01:38 +0200 Subject: [PATCH 08/13] Remove stray print --- zeroconf/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/zeroconf/__init__.py b/zeroconf/__init__.py index 0a8eaa15..42e4af06 100644 --- a/zeroconf/__init__.py +++ b/zeroconf/__init__.py @@ -2175,7 +2175,6 @@ def add_multicast_member( apple_p2p: bool = False, ) -> Optional[socket.socket]: # This is based on assumptions in normalize_interface_choice - print(interface) is_v6 = isinstance(interface, tuple) log.debug('Adding %r (socket %d) to multicast group', interface, listen_socket.fileno()) try: From 13527a36431eebb135a03c17b834e8d115d9a643 Mon Sep 17 00:00:00 2001 From: gjbadros Date: Tue, 2 Jun 2020 01:20:07 -0700 Subject: [PATCH 09/13] Fix false warning (#273) When there is nothing to write, we don't need to warn about not making progress. --- zeroconf/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/zeroconf/__init__.py b/zeroconf/__init__.py index 42e4af06..6520123c 100644 --- a/zeroconf/__init__.py +++ b/zeroconf/__init__.py @@ -1184,7 +1184,9 @@ def packets(self) -> List[bytes]: authority_offset += authorities_written additional_offset += additionals_written log.debug("now offsets = %d, %d, %d", answer_offset, authority_offset, additional_offset) - if answers_written == 0 and authorities_written == 0 and additional_offset == 0: + if (answers_written + authorities_written + additionals_written) == 0 and ( + len(self.answers) + len(self.authorities) + len(self.additionals) + ) > 0: log.warning("packets() made no progress adding records; returning") break self.state = self.State.finished From 57ce364d23a2dcfd1bb721e8778690274a07bf7d Mon Sep 17 00:00:00 2001 From: Jakub Stasiak Date: Tue, 2 Jun 2020 14:17:30 +0200 Subject: [PATCH 10/13] Handle providing interface indexes again --- zeroconf/__init__.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/zeroconf/__init__.py b/zeroconf/__init__.py index 6520123c..d0ad8682 100644 --- a/zeroconf/__init__.py +++ b/zeroconf/__init__.py @@ -2043,6 +2043,22 @@ def ip6_to_address_and_index(adapters: List[Any], ip: str) -> Tuple[Tuple[str, i raise RuntimeError('No adapter found for IP address %s' % ip) +def interface_index_to_ip6_address(adapters: List[Any], index: int) -> Tuple[str, int, int]: + if os.name != 'posix': + # Adapter names that ifaddr reports are not compatible with what if_nametoindex expects on Windows. + # We need https://github.com/pydron/ifaddr/pull/21 but it seems stuck on review. + raise RuntimeError('Converting from adapter names to indexes is not supported on non-POSIX systems') + + for adapter in adapters: + if socket.if_nametoindex(adapter.name) == index: + for adapter_ip in adapter.ips: + # IPv6 addresses are represented as tuples + if isinstance(adapter_ip.ip, tuple): + return cast(Tuple[str, int, int], adapter_ip.ip) + + raise RuntimeError('No adapter found for index %s' % index) + + def ip6_addresses_to_indexes( interfaces: List[Union[str, Tuple[Tuple[str, int, int], int]]] ) -> List[Tuple[Tuple[str, int, int], int]]: @@ -2059,8 +2075,7 @@ def ip6_addresses_to_indexes( for iface in interfaces: if isinstance(iface, int): - assert False, 'Temporarily disabled to test something else' - # result.append(iface) + result.append((interface_index_to_ip6_address(adapters, iface), iface)) elif isinstance(iface, str) and ipaddress.ip_address(iface).version == 6: result.append(ip6_to_address_and_index(adapters, iface)) From db8b26d71c8a0aff5ce7a4a2f69457b664aee244 Mon Sep 17 00:00:00 2001 From: Jakub Stasiak Date: Tue, 2 Jun 2020 14:29:17 +0200 Subject: [PATCH 11/13] Unconditionally del_reader() respond sockets --- zeroconf/__init__.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/zeroconf/__init__.py b/zeroconf/__init__.py index d0ad8682..bfb0abbd 100644 --- a/zeroconf/__init__.py +++ b/zeroconf/__init__.py @@ -2864,9 +2864,8 @@ def close(self) -> None: if not self.unicast: self.engine.del_reader(cast(socket.socket, self._listen_socket)) cast(socket.socket, self._listen_socket).close() - else: - for s in self._respond_sockets: - self.engine.del_reader(s) + for s in self._respond_sockets: + self.engine.del_reader(s) self.engine.join() # shutdown the rest From eecb9b13ac4a1b85820c3161f523ea6392275780 Mon Sep 17 00:00:00 2001 From: Jakub Stasiak Date: Wed, 17 Jun 2020 01:30:14 +0200 Subject: [PATCH 12/13] Fix the typing --- zeroconf/__init__.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/zeroconf/__init__.py b/zeroconf/__init__.py index bfb0abbd..dfeed826 100644 --- a/zeroconf/__init__.py +++ b/zeroconf/__init__.py @@ -190,7 +190,7 @@ class InterfaceChoice(enum.Enum): All = 2 -InterfacesType = Union[List[Union[str, Tuple[Tuple[str, int, int], int]]], InterfaceChoice] +InterfacesType = Union[List[Union[str, int, Tuple[Tuple[str, int, int], int]]], InterfaceChoice] @enum.unique @@ -2060,7 +2060,7 @@ def interface_index_to_ip6_address(adapters: List[Any], index: int) -> Tuple[str def ip6_addresses_to_indexes( - interfaces: List[Union[str, Tuple[Tuple[str, int, int], int]]] + interfaces: List[Union[str, int, Tuple[Tuple[str, int, int], int]]] ) -> List[Tuple[Tuple[str, int, int], int]]: """Convert IPv6 interface addresses to interface indexes. @@ -2250,11 +2250,11 @@ def create_sockets( else: listen_socket = new_socket(ip_version=ip_version, apple_p2p=apple_p2p, bind_addr=('',)) - interfaces = normalize_interface_choice(interfaces, ip_version) + normalized_interfaces = normalize_interface_choice(interfaces, ip_version) respond_sockets = [] - for i in interfaces: + for i in normalized_interfaces: if not unicast: respond_socket = add_multicast_member(cast(socket.socket, listen_socket), i, apple_p2p=apple_p2p) else: From b46da942aa07adaebd6f8d07c7c44174d2cfa121 Mon Sep 17 00:00:00 2001 From: Jakub Stasiak Date: Tue, 7 Jul 2020 12:57:34 +0200 Subject: [PATCH 13/13] Reformat --- zeroconf/__init__.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/zeroconf/__init__.py b/zeroconf/__init__.py index 349f13d7..3a1c5f66 100644 --- a/zeroconf/__init__.py +++ b/zeroconf/__init__.py @@ -2020,12 +2020,7 @@ def get_all_addresses_v6() -> List[Tuple[Tuple[str, int, int], int]]: # IPv6 multicast uses positive indexes for interfaces # TODO: What about multi-address interfaces? return list( - set( - (addr.ip, iface.index) - for iface in ifaddr.get_adapters() - for addr in iface.ips - if addr.is_IPv6 - ) + set((addr.ip, iface.index) for iface in ifaddr.get_adapters() for addr in iface.ips if addr.is_IPv6) )