Comparison

net/dns.lua @ 2741:fcd30b72c50c

net.dns: More reliable parsing of resolv.conf - allow multiple nameserver IPs on one line (thanks dersd)
author Matthew Wild <mwild1@gmail.com>
date Fri, 05 Mar 2010 18:15:08 +0000
parent 2620:481c6724818f
child 2742:6c0a081cd766
comparison
equal deleted inserted replaced
2740:2442c54cf9ec 2741:fcd30b72c50c
536 end 536 end
537 else -- posix 537 else -- posix
538 local resolv_conf = io.open("/etc/resolv.conf"); 538 local resolv_conf = io.open("/etc/resolv.conf");
539 if resolv_conf then 539 if resolv_conf then
540 for line in resolv_conf:lines() do 540 for line in resolv_conf:lines() do
541 local address = line:gsub("#.*$", ""):match('^%s*nameserver%s+(%d+%.%d+%.%d+%.%d+)%s*$'); 541 line = line:gsub("#.*$", "")
542 if address then self:addnameserver(address) end 542 :match('^%s*nameserver%s+(.*)%s*$');
543 if line then
544 line:gsub("%f[%d.](%d+%.%d+%.%d+%.%d+)%f[^%d.]", function (address)
545 self:addnameserver(address)
546 end);
547 end
543 end 548 end
544 end 549 end
545 if not self.server or #self.server == 0 then 550 if not self.server or #self.server == 0 then
546 -- TODO log warning about no nameservers, adding localhost as the default nameserver 551 -- TODO log warning about no nameservers, adding localhost as the default nameserver
547 self:addnameserver("127.0.0.1"); 552 self:addnameserver("127.0.0.1");