@@ -48,6 +48,7 @@ local TYPE_MX = 15
4848local TYPE_TXT = 16
4949local TYPE_AAAA = 28
5050local TYPE_SRV = 33
51+ local TYPE_NAPTR = 35
5152local TYPE_SPF = 99
5253
5354local CLASS_IN = 1
@@ -67,6 +68,7 @@ local _M = {
6768 TYPE_TXT = TYPE_TXT ,
6869 TYPE_AAAA = TYPE_AAAA ,
6970 TYPE_SRV = TYPE_SRV ,
71+ TYPE_NAPTR = TYPE_NAPTR ,
7072 TYPE_SPF = TYPE_SPF ,
7173 CLASS_IN = CLASS_IN ,
7274 SECTION_AN = SECTION_AN ,
@@ -209,6 +211,16 @@ local function _encode_name(s)
209211 return char (# s ) .. s
210212end
211213
214+ local function _decode_string (buf , pos )
215+ local slen = byte (buf , pos )
216+ if slen == 0 then
217+ return " " , pos + 1
218+ end
219+ if pos + 1 + slen >= # buf then
220+ return nil , ' truncated'
221+ end
222+ return sub (buf , pos + 1 , pos + slen ), pos + slen + 1
223+ end
212224
213225local function _decode_name (buf , pos )
214226 local labels = {}
@@ -484,6 +496,43 @@ local function parse_section(answers, section, buf, start_pos, size,
484496
485497 pos = p
486498
499+ elseif typ == TYPE_NAPTR then
500+ if len < 7 then
501+ return nil , " bad NAPTR record value length: " .. len
502+ end
503+
504+ local hi = byte (buf , pos )
505+ local lo = byte (buf , pos + 1 )
506+ ans .order = lshift (hi , 8 ) + lo
507+
508+ hi = byte (buf , pos + 2 )
509+ lo = byte (buf , pos + 3 )
510+ ans .preference = lshift (hi , 8 ) + lo
511+
512+ local str , p = _decode_string (buf , pos + 4 )
513+ if not str then return nil , pos end
514+ ans .flags = str
515+
516+ str , p = _decode_string (buf , p )
517+ if not str then return nil , pos end
518+ ans .services = str
519+
520+ str , p = _decode_string (buf , p )
521+ if not str then return nil , pos end
522+ ans .regexp = str
523+
524+ if p - pos < len then
525+ str ,p = _decode_name (buf , p )
526+ if not str then return nil , pos end
527+ ans .replacements = str
528+ end
529+
530+ if p - pos ~= len then
531+ return nil , format (" bad NAPTR record length: %d ~= %d" , p - pos , len )
532+ end
533+
534+ pos = p
535+
487536 elseif typ == TYPE_NS then
488537
489538 local name , p = _decode_name (buf , pos )
0 commit comments