aboutsummaryrefslogtreecommitdiffstats
path: root/net/dns.lua
diff options
context:
space:
mode:
authorFlorian Zeitz <florob@babelmonkeys.de>2013-06-18 23:02:20 +0200
committerFlorian Zeitz <florob@babelmonkeys.de>2013-06-18 23:02:20 +0200
commit60aa072e84e30fde745e5c7761bfb2c3bd0f4100 (patch)
treef2755f5d2e64effd4c1ff9c5c455e9a2d606d4d4 /net/dns.lua
parent08a3d63a95960b865184972700e0ce1cf13cf6f7 (diff)
downloadprosody-60aa072e84e30fde745e5c7761bfb2c3bd0f4100.tar.gz
prosody-60aa072e84e30fde745e5c7761bfb2c3bd0f4100.zip
net.dns: Support IPv6 addresses in resolv.conf [Backported from 0.10]
Diffstat (limited to 'net/dns.lua')
-rw-r--r--net/dns.lua19
1 files changed, 13 insertions, 6 deletions
diff --git a/net/dns.lua b/net/dns.lua
index 7ec13c81..9d90c24c 100644
--- a/net/dns.lua
+++ b/net/dns.lua
@@ -14,6 +14,7 @@
local socket = require "socket";
local timer = require "util.timer";
+local new_ip = require "util.ip".new_ip;
local _, windows = pcall(require, "util.windows");
local is_windows = (_ and windows) or os.getenv("WINDIR");
@@ -599,11 +600,12 @@ function resolver:adddefaultnameservers() -- - - - - adddefaultnameservers
if resolv_conf then
for line in resolv_conf:lines() do
line = line:gsub("#.*$", "")
- :match('^%s*nameserver%s+(.*)%s*$');
+ :match('^%s*nameserver%s+([%x:%.]*)%s*$');
if line then
- line:gsub("%f[%d.](%d+%.%d+%.%d+%.%d+)%f[^%d.]", function (address)
- self:addnameserver(address)
- end);
+ local ip = new_ip(line);
+ if ip then
+ self:addnameserver(ip.addr);
+ end
end
end
end
@@ -623,7 +625,12 @@ function resolver:getsocket(servernum) -- - - - - - - - - - - - - getsocket
if sock then return sock; end
local ok, err;
- sock, err = socket.udp();
+ local peer = self.server[servernum];
+ if peer:find(":") then
+ sock, err = socket.udp6();
+ else
+ sock, err = socket.udp();
+ end
if sock and self.socket_wrapper then sock, err = self.socket_wrapper(sock, self); end
if not sock then
return nil, err;
@@ -636,7 +643,7 @@ function resolver:getsocket(servernum) -- - - - - - - - - - - - - getsocket
-- if so, try the next server
ok, err = sock:setsockname('*', 0);
if not ok then return self:servfail(sock, err); end
- ok, err = sock:setpeername(self.server[servernum], 53);
+ ok, err = sock:setpeername(peer, 53);
if not ok then return self:servfail(sock, err); end
return sock;
end