aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWaqas Hussain <waqas20@gmail.com>2009-11-02 00:46:43 +0500
committerWaqas Hussain <waqas20@gmail.com>2009-11-02 00:46:43 +0500
commitc19649f0696ec88dae15115a64193517ca97a63f (patch)
tree20e59c28b4b4bef212acc35e75d686c70c984d68
parent18ecc84111bf02125312025638bc1a597141c098 (diff)
downloadprosody-c19649f0696ec88dae15115a64193517ca97a63f.tar.gz
prosody-c19649f0696ec88dae15115a64193517ca97a63f.zip
net.dns: Updated to use util.windows.get_nameservers for enumerating nameservers on Windows.
-rw-r--r--net/dns.lua38
1 files changed, 25 insertions, 13 deletions
diff --git a/net/dns.lua b/net/dns.lua
index 74c17a56..7b596f67 100644
--- a/net/dns.lua
+++ b/net/dns.lua
@@ -17,7 +17,8 @@
require 'socket'
local ztact = require 'util.ztact'
local require = require
-local os = os;
+local _, windows = pcall(require, "util.windows");
+local is_windows = (_ and windows) or os.getenv("WINDIR");
local coroutine, io, math, socket, string, table =
coroutine, io, math, socket, string, table
@@ -507,18 +508,29 @@ function resolver:setnameserver (address) -- - - - - - - - - - setnameserver
function resolver:adddefaultnameservers () -- - - - - adddefaultnameservers
- local resolv_conf = io.open("/etc/resolv.conf");
- if resolv_conf then
- for line in resolv_conf:lines() do
- local address = line:gsub("#.*$", ""):match('^%s*nameserver%s+(%d+%.%d+%.%d+%.%d+)%s*$')
- if address then self:addnameserver (address) end
- end
- elseif os.getenv("WINDIR") then
- self:addnameserver ("208.67.222.222")
- self:addnameserver ("208.67.220.220")
- end
- if not self.server or #self.server == 0 then
- self:addnameserver("127.0.0.1");
+ if is_windows then
+ if windows then
+ for _, server in ipairs(windows.get_nameservers()) do
+ self:addnameserver(server)
+ end
+ end
+ if not self.server or #self.server == 0 then
+ -- TODO log warning about no nameservers, adding opendns servers as fallback
+ self:addnameserver("208.67.222.222")
+ self:addnameserver("208.67.220.220")
+ end
+ else -- posix
+ local resolv_conf = io.open("/etc/resolv.conf");
+ if resolv_conf then
+ for line in resolv_conf:lines() do
+ local address = line:gsub("#.*$", ""):match('^%s*nameserver%s+(%d+%.%d+%.%d+%.%d+)%s*$')
+ if address then self:addnameserver (address) end
+ end
+ end
+ if not self.server or #self.server == 0 then
+ -- TODO log warning about no nameservers, adding localhost as the default nameserver
+ self:addnameserver("127.0.0.1");
+ end
end
end