dns support underscore

This commit is contained in:
Cloud Wu
2015-05-28 16:10:19 +08:00
parent b8c54cbac2
commit ca50a5f518

View File

@@ -91,7 +91,7 @@ local function verify_domain_name(name)
if not name:match("^[%l%d-%.]+$") then if not name:match("^[%l%d-%.]+$") then
return false return false
end end
for w in name:gmatch("([%w-]+)%.?") do for w in name:gmatch("([_%w%-]+)%.?") do
if #w > MAX_LABEL_LEN then if #w > MAX_LABEL_LEN then
return false return false
end end
@@ -113,7 +113,7 @@ end
local function pack_question(name, qtype, qclass) local function pack_question(name, qtype, qclass)
local labels = {} local labels = {}
for w in name:gmatch("([%w-]+)%.?") do for w in name:gmatch("([_%w%-]+)%.?") do
table.insert(labels, string.pack("s1",w)) table.insert(labels, string.pack("s1",w))
end end
table.insert(labels, '\0') table.insert(labels, '\0')
@@ -282,7 +282,7 @@ function dns.resolve(name, ipv6)
qdcount = 1, qdcount = 1,
} }
local req = pack_header(question_header) .. pack_question(name, qtype, QCLASS.IN) local req = pack_header(question_header) .. pack_question(name, qtype, QCLASS.IN)
assert(dns_server, "Call dns.server fist") assert(dns_server, "Call dns.server first")
socket.write(dns_server, req) socket.write(dns_server, req)
return suspend(question_header.tid, name, qtype) return suspend(question_header.tid, name, qtype)
end end