@@ -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 ,
@@ -210,6 +212,21 @@ local function _encode_name(s)
210212end
211213
212214
215+ local function _decode_string (buf , pos )
216+ local slen = byte (buf , pos )
217+
218+ if slen == 0 then
219+ return " " , pos + 1
220+ end
221+
222+ if pos + 1 + slen >= # buf then
223+ return nil , ' truncated'
224+ end
225+
226+ return sub (buf , pos + 1 , pos + slen ), pos + slen + 1
227+ end
228+
229+
213230local function _decode_name (buf , pos )
214231 local labels = {}
215232 local nptrs = 0
@@ -484,6 +501,50 @@ local function parse_section(answers, section, buf, start_pos, size,
484501
485502 pos = p
486503
504+ elseif typ == TYPE_NAPTR then
505+ if len < 7 then
506+ return nil , " bad NAPTR record value length: " .. len
507+ end
508+
509+ local order_hi = byte (buf , pos )
510+ local order_lo = byte (buf , pos + 1 )
511+ ans .order = lshift (order_hi , 8 ) + order_lo
512+
513+ local preference_hi = byte (buf , pos + 2 )
514+ local preference_lo = byte (buf , pos + 3 )
515+ ans .preference = lshift (preference_hi , 8 ) + preference_lo
516+
517+ local flags_str , p = _decode_string (buf , pos + 4 )
518+ if not flags_str then
519+ return nil , pos
520+ end
521+ ans .flags = flags_str
522+
523+ local services_str , p = _decode_string (buf , p )
524+ if not services_str then
525+ return nil , pos
526+ end
527+ ans .services = services_str
528+
529+ local regexp_str , p = _decode_string (buf , p )
530+ if not regexp_str then
531+ return nil , pos
532+ end
533+ ans .regexp = regexp_str
534+
535+ local replacements_str ,p = _decode_name (buf , p )
536+ if not replacements_str
537+ then return nil , pos
538+ end
539+ ans .replacements = replacements_str
540+
541+ if p - pos ~= len then
542+ return nil , format (" bad NAPTR record length: %d ~= %d" ,
543+ p - pos , len )
544+ end
545+
546+ pos = p
547+
487548 elseif typ == TYPE_NS then
488549
489550 local name , p = _decode_name (buf , pos )
0 commit comments