Skip to content

Commit

Permalink
chore(dns): pretty code in parse_section
Browse files Browse the repository at this point in the history
Signed-off-by: Jianhui Zhao <zhaojh329@gmail.com>
  • Loading branch information
zhaojh329 committed Sep 16, 2023
1 parent 46ebdbf commit 4e74fbc
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions dns.lua
Original file line number Diff line number Diff line change
Expand Up @@ -155,31 +155,27 @@ local function decode_name(buf, pos)
return table.concat(labels, '.'), pos
end

local function parse_section(answers, section, buf, start_pos, size, should_skip)
local function parse_section(answers, section, buf, start_pos, size)
local pos = start_pos

for _ = 1, size do
local ans = {}

if not should_skip then
answers[#answers + 1] = ans
end

ans.section = section

local name
name, pos = decode_name(buf, pos)
if not name then
return nil, pos
end

ans.name = name

local typ, class, ttl, len = string.unpack('>I2I2I4I2', buf:sub(pos))

ans.type = typ
ans.class = class
ans.ttl = ttl
local ans = {
section = section,
type = typ,
class = class,
ttl = ttl,
name = name
}

answers[#answers + 1] = ans

pos = pos + 10

Expand Down

0 comments on commit 4e74fbc

Please sign in to comment.