@@ -285,7 +285,7 @@ function _M.decode_request(self, req)
285
285
local rdata = nil
286
286
if rdlen > 0 then
287
287
-- get whole rdata
288
- rdata = byte (self .buf , self .pos - 1 , self .pos + rdlen )
288
+ rdata = strsub (self .buf , self .pos + 1 , self .pos + rdlen )
289
289
290
290
-- parse OPTION-CODE
291
291
self .pos = self .pos + 2
@@ -387,6 +387,12 @@ local function _encode_4byt(x)
387
387
end
388
388
389
389
390
+ local function _encode_1byt (x )
391
+ local lo = band (x , 0xFF )
392
+
393
+ return char (lo )
394
+ end
395
+
390
396
local function _encode_2byt (x )
391
397
local hi = band (rshift (x , 8 ), 0x00FF )
392
398
local lo = band (x , 0x00FF )
@@ -472,12 +478,14 @@ function _M.encode_response(self)
472
478
end
473
479
474
480
for i = 1 , self .response .header .arcount do
475
- buf = buf .. _encode_name (self .response .arsections [i ].name )
481
+ buf = buf .. _encode_name (self .response .arsections [i ].name )
476
482
buf = buf .. _encode_2byt (self .response .arsections [i ].type )
477
483
buf = buf .. _encode_2byt (self .response .arsections [i ].class )
478
484
buf = buf .. _encode_4byt (self .response .arsections [i ].ttl or 0x258 )
479
485
buf = buf .. _encode_2byt (self .response .arsections [i ].rdlength )
480
- buf = buf .. self .response .arsections [i ].rdata
486
+ if self .response .arsections [i ].rdlength > 0 then
487
+ buf = buf .. self .response .arsections [i ].rdata
488
+ i end
481
489
end
482
490
483
491
return buf
@@ -531,7 +539,7 @@ function _M.create_a_answer(self, name, ttl, ipv4)
531
539
return nil
532
540
end
533
541
534
- function _M .replay_additional_opt (self )
542
+ function _M .replay_additional_opts (self )
535
543
536
544
for i = 1 , # self .request .additionals do
537
545
local additional = self .request .additionals [i ]
0 commit comments