Software /
code /
prosody
Comparison
net/dns.lua @ 2067:0ed6369605bf
net.dns: Updated to use util.windows.get_nameservers for enumerating nameservers on Windows.
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Mon, 02 Nov 2009 00:46:43 +0500 |
parent | 2027:4cd673721e72 |
child | 2068:1e1ee53d7f6e |
comparison
equal
deleted
inserted
replaced
2066:b3a640892549 | 2067:0ed6369605bf |
---|---|
15 | 15 |
16 | 16 |
17 require 'socket' | 17 require 'socket' |
18 local ztact = require 'util.ztact' | 18 local ztact = require 'util.ztact' |
19 local require = require | 19 local require = require |
20 local os = os; | 20 local _, windows = pcall(require, "util.windows"); |
21 local is_windows = (_ and windows) or os.getenv("WINDIR"); | |
21 | 22 |
22 local coroutine, io, math, socket, string, table = | 23 local coroutine, io, math, socket, string, table = |
23 coroutine, io, math, socket, string, table | 24 coroutine, io, math, socket, string, table |
24 | 25 |
25 local ipairs, next, pairs, print, setmetatable, tostring, assert, error, unpack = | 26 local ipairs, next, pairs, print, setmetatable, tostring, assert, error, unpack = |
505 self:addnameserver (address) | 506 self:addnameserver (address) |
506 end | 507 end |
507 | 508 |
508 | 509 |
509 function resolver:adddefaultnameservers () -- - - - - adddefaultnameservers | 510 function resolver:adddefaultnameservers () -- - - - - adddefaultnameservers |
510 local resolv_conf = io.open("/etc/resolv.conf"); | 511 if is_windows then |
511 if resolv_conf then | 512 if windows then |
512 for line in resolv_conf:lines() do | 513 for _, server in ipairs(windows.get_nameservers()) do |
513 local address = line:gsub("#.*$", ""):match('^%s*nameserver%s+(%d+%.%d+%.%d+%.%d+)%s*$') | 514 self:addnameserver(server) |
514 if address then self:addnameserver (address) end | 515 end |
515 end | 516 end |
516 elseif os.getenv("WINDIR") then | 517 if not self.server or #self.server == 0 then |
517 self:addnameserver ("208.67.222.222") | 518 -- TODO log warning about no nameservers, adding opendns servers as fallback |
518 self:addnameserver ("208.67.220.220") | 519 self:addnameserver("208.67.222.222") |
519 end | 520 self:addnameserver("208.67.220.220") |
520 if not self.server or #self.server == 0 then | 521 end |
521 self:addnameserver("127.0.0.1"); | 522 else -- posix |
523 local resolv_conf = io.open("/etc/resolv.conf"); | |
524 if resolv_conf then | |
525 for line in resolv_conf:lines() do | |
526 local address = line:gsub("#.*$", ""):match('^%s*nameserver%s+(%d+%.%d+%.%d+%.%d+)%s*$') | |
527 if address then self:addnameserver (address) end | |
528 end | |
529 end | |
530 if not self.server or #self.server == 0 then | |
531 -- TODO log warning about no nameservers, adding localhost as the default nameserver | |
532 self:addnameserver("127.0.0.1"); | |
533 end | |
522 end | 534 end |
523 end | 535 end |
524 | 536 |
525 | 537 |
526 function resolver:getsocket (servernum) -- - - - - - - - - - - - - getsocket | 538 function resolver:getsocket (servernum) -- - - - - - - - - - - - - getsocket |