2121"""
2222
2323import struct
24- from typing import Callable , Dict , List , Optional , Set , cast
24+ from typing import Callable , Dict , List , Optional , Set , Tuple , cast
2525
2626from . import DNSMessage
2727from .._dns import DNSAddress , DNSHinfo , DNSNsec , DNSPointer , DNSQuestion , DNSRecord , DNSService , DNSText
@@ -67,9 +67,16 @@ class DNSIncoming(DNSMessage, QuietLogger):
6767 'valid' ,
6868 'now' ,
6969 'scope_id' ,
70+ 'source' ,
7071 )
7172
72- def __init__ (self , data : bytes , scope_id : Optional [int ] = None , now : Optional [float ] = None ) -> None :
73+ def __init__ (
74+ self ,
75+ data : bytes ,
76+ source : Optional [Tuple [str , int ]] = None ,
77+ scope_id : Optional [int ] = None ,
78+ now : Optional [float ] = None ,
79+ ) -> None :
7380 """Constructor from string holding bytes of packet"""
7481 super ().__init__ (0 )
7582 self .offset = 0
@@ -86,6 +93,7 @@ def __init__(self, data: bytes, scope_id: Optional[int] = None, now: Optional[fl
8693 self .valid = False
8794 self ._read_others = False
8895 self .now = now or current_time_millis ()
96+ self .source = source
8997 self .scope_id = scope_id
9098 self ._parse_data (self ._initial_parse )
9199
@@ -102,7 +110,12 @@ def _parse_data(self, parser_call: Callable) -> None:
102110 try :
103111 parser_call ()
104112 except DECODE_EXCEPTIONS :
105- self .log_exception_warning ('Choked at offset %d while unpacking %r' , self .offset , self .data )
113+ self .log_exception_warning (
114+ 'Received invalid packet from %s at offset %d while unpacking %r' ,
115+ self .source ,
116+ self .offset ,
117+ self .data ,
118+ )
106119
107120 @property
108121 def answers (self ) -> List [DNSRecord ]:
0 commit comments