Retagging 0.3.0, used up my mistake quota for today
[prosody.git] / net / dns.lua
index 1d165de12c0b26977025090a1871d5dd766628ef..c86a088668b1c6f29abd5caac014a34312b0688a 100644 (file)
@@ -1,4 +1,6 @@
-
+-- Prosody IM v0.3
+-- This file is included with Prosody IM. It has modifications,
+-- which are hereby placed in the public domain.
 
 -- public domain 20080404 lua@ztact.com
 
@@ -502,11 +504,16 @@ function resolver:setnameserver (address)    -- - - - - - - - - - setnameserver
 
 function resolver:adddefaultnameservers ()    -- - - - -  adddefaultnameservers
   local resolv_conf = io.open("/etc/resolv.conf");
-  if not resolv_conf then return nil; end
-  for line in resolv_conf:lines() do
-    local address = string.match (line, 'nameserver%s+(%d+%.%d+%.%d+%.%d+)')
-    if address then  self:addnameserver (address)  end
-    end  end
+  if resolv_conf then
+         for line in resolv_conf:lines() do
+               local address = string.match (line, 'nameserver%s+(%d+%.%d+%.%d+%.%d+)')
+               if address then  self:addnameserver (address)  end
+         end
+  else -- FIXME correct for windows, using opendns nameservers for now
+       self:addnameserver ("208.67.222.222")
+       self:addnameserver ("208.67.220.220")
+  end
+end
 
 
 function resolver:getsocket (servernum)    -- - - - - - - - - - - - - getsocket
@@ -686,7 +693,8 @@ function resolver:pulse ()    -- - - - - - - - - - - - - - - - - - - - -  pulse
           if not next (self.active) then  return nil  end
         else
           -- print ('retry', o.server, o.delay)
-          self.socket[o.server]:send (o.packet)
+          local _a = self.socket[o.server];
+          if _a then _a:send (o.packet) end
           o.retry = self.time + self.delays[o.delay]
           end  end  end  end