diff --git a/src/zeroconf/_core.py b/src/zeroconf/_core.py index 7067466f..1f74dcd5 100644 --- a/src/zeroconf/_core.py +++ b/src/zeroconf/_core.py @@ -271,21 +271,9 @@ def datagram_received( self, data: bytes, addrs: Union[Tuple[str, int], Tuple[str, int, int, int]] ) -> None: assert self.transport is not None - v6_flow_scope: Union[Tuple[()], Tuple[int, int]] = () data_len = len(data) debug = log.isEnabledFor(logging.DEBUG) - if len(addrs) == 2: - # https://github.com/python/mypy/issues/1178 - addr, port = addrs # type: ignore - scope = None - else: - # https://github.com/python/mypy/issues/1178 - addr, port, flow, scope = addrs # type: ignore - if debug: - log.debug('IPv6 scope_id %d associated to the receiving interface', scope) - v6_flow_scope = (flow, scope) - if data_len > _MAX_MSG_ABSOLUTE: # Guard against oversized packets to ensure bad implementations cannot overwhelm # the system. @@ -308,15 +296,26 @@ def datagram_received( # Guard against duplicate packets if debug: log.debug( - 'Ignoring duplicate message with no unicast questions received from %r:%r [socket %s] (%d bytes) as [%r]', - addr, - port, + 'Ignoring duplicate message with no unicast questions received from %s [socket %s] (%d bytes) as [%r]', + addrs, self.sock_description, data_len, data, ) return + v6_flow_scope: Union[Tuple[()], Tuple[int, int]] = () + if len(addrs) == 2: + # https://github.com/python/mypy/issues/1178 + addr, port = addrs # type: ignore + scope = None + else: + # https://github.com/python/mypy/issues/1178 + addr, port, flow, scope = addrs # type: ignore + if debug: + log.debug('IPv6 scope_id %d associated to the receiving interface', scope) + v6_flow_scope = (flow, scope) + msg = DNSIncoming(data, (addr, port), scope, now) self.data = data self.last_time = now