resolver.timeout = default_timeout;
-local SRV_tostring;
-
local function default_rr_tostring(rr)
local rr_val = rr.type and rr[rr.type:lower()];
if type(rr_val) ~= "string" then
local special_tostrings = {
LOC = resolver.LOC_tostring;
- MX = function (rr) return string.format('%2i %s', rr.pref, rr.mx); end;
- SRV = SRV_tostring;
+ MX = function (rr)
+ return string.format('%2i %s', rr.pref, rr.mx);
+ end;
+ SRV = function (rr)
+ local s = rr.srv;
+ return string.format('%5d %5d %5d %s', s.priority, s.weight, s.port, s.target);
+ end;
};
local rr_metatable = {}; -- - - - - - - - - - - - - - - - - - - rr_metatable
rr.a = string.format('%i.%i.%i.%i', b1, b2, b3, b4);
end
+function resolver:AAAA(rr)
+ local addr = {};
+ for i = 1, rr.rdlength, 2 do
+ local b1, b2 = self:byte(2);
+ table.insert(addr, ("%02x%02x"):format(b1, b2));
+ end
+ rr.aaaa = table.concat(addr, ":");
+end
function resolver:CNAME(rr) -- - - - - - - - - - - - - - - - - - - - CNAME
rr.cname = self:name();
rr.ptr = self:name();
end
-function SRV_tostring(rr) -- - - - - - - - - - - - - - - - - - SRV_tostring
- local s = rr.srv;
- return string.format( '%5d %5d %5d %s', s.priority, s.weight, s.port, s.target );
-end
-
-
function resolver:TXT(rr) -- - - - - - - - - - - - - - - - - - - - - - TXT
- rr.txt = self:sub (rr.rdlength);
+ rr.txt = self:sub (self:byte());
end
--set(self.yielded, co, qclass, qtype, qname, true);
end
- local conn = self:getsocket(o.server)
+ local conn, err = self:getsocket(o.server)
+ if not conn then
+ return nil, err;
+ end
conn:send (o.packet)
if timer and self.timeout then
i = i + 1;
self:servfail(conn);
o.server = self.best_server;
- conn = self:getsocket(o.server);
- conn:send(o.packet);
- return self.timeout;
- else
- -- Tried everything, failed
- self:cancel(qclass, qtype, qname, co, true);
+ conn, err = self:getsocket(o.server);
+ if conn then
+ conn:send(o.packet);
+ return self.timeout;
+ end
end
+ -- Tried everything, failed
+ self:cancel(qclass, qtype, qname, co, true);
end
end)
end
+ return true;
end
function resolver:servfail(sock)