@@ -93,11 +93,12 @@ def build_address(address):
93
93
return b'' .join (results )
94
94
95
95
96
- def build_request (address , qtype , request_id ):
97
- header = struct .pack ('!HBBHHHH' , request_id , 1 , 0 , 1 , 0 , 0 , 0 )
96
+ def build_request (address , qtype ):
97
+ request_id = os .urandom (2 )
98
+ header = struct .pack ('!BBHHHH' , 1 , 0 , 1 , 0 , 0 , 0 )
98
99
addr = build_address (address )
99
100
qtype_qclass = struct .pack ('!HH' , qtype , QCLASS_IN )
100
- return header + addr + qtype_qclass
101
+ return request_id + header + addr + qtype_qclass
101
102
102
103
103
104
def parse_ip (addrtype , data , length , offset ):
@@ -270,7 +271,6 @@ class DNSResolver(object):
270
271
271
272
def __init__ (self ):
272
273
self ._loop = None
273
- self ._request_id = 1
274
274
self ._hosts = {}
275
275
self ._hostname_status = {}
276
276
self ._hostname_to_cb = {}
@@ -412,10 +412,7 @@ def remove_callback(self, callback):
412
412
del self ._hostname_status [hostname ]
413
413
414
414
def _send_req (self , hostname , qtype ):
415
- self ._request_id += 1
416
- if self ._request_id > 32768 :
417
- self ._request_id = 1
418
- req = build_request (hostname , qtype , self ._request_id )
415
+ req = build_request (hostname , qtype )
419
416
for server in self ._servers :
420
417
logging .debug ('resolving %s with type %d using server %s' ,
421
418
hostname , qtype , server )
0 commit comments