From ee1f5055eae87391cff650d260f9ea8aaded567c Mon Sep 17 00:00:00 2001 From: xjdrew Date: Thu, 28 Mar 2019 14:26:23 +0800 Subject: [PATCH] bugfix: dns parse hosts.conf --- lualib/skynet/dns.lua | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/lualib/skynet/dns.lua b/lualib/skynet/dns.lua index 08f3c0f5..ae75cef2 100644 --- a/lualib/skynet/dns.lua +++ b/lualib/skynet/dns.lua @@ -119,23 +119,31 @@ local function parse_hosts() local rts = {} for line in f:lines() do - local ip, hosts = string.match(line, "^%s*([%[%]%x%.%:]+)%s+([^#;]*)") - local family = guess_name_type(ip) - if hosts and family ~= "hostname" then - for host in hosts:gmatch("%S+") do - host = host:lower() - local rt = rts[host] - if not rt then - rt = {} - rts[host] = rt - end - - if not rt[family] then - rt[family] = {} - end - table.insert(rt[family], ip) - end + local ip, hosts = string.match(line, "^%s*([%[%]%x%.%:]+)%s+([^#;]+)") + if not ip or not hosts then + goto continue end + + local family = guess_name_type(ip) + if family == "hostname" then + goto continue + end + + for host in hosts:gmatch("%S+") do + host = host:lower() + local rt = rts[host] + if not rt then + rt = {} + rts[host] = rt + end + + if not rt[family] then + rt[family] = {} + end + table.insert(rt[family], ip) + end + + ::continue:: end return rts end