summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/ohai/plugins/hostname.rb17
1 files changed, 14 insertions, 3 deletions
diff --git a/lib/ohai/plugins/hostname.rb b/lib/ohai/plugins/hostname.rb
index 0f103c5d..15d19091 100644
--- a/lib/ohai/plugins/hostname.rb
+++ b/lib/ohai/plugins/hostname.rb
@@ -173,9 +173,20 @@ Ohai.plugin(:Hostname) do
if info.first =~ /.+?\.(.*)/
fqdn info.first
else
- # host is not in dns. optionally use:
- # C:\WINDOWS\system32\drivers\etc\hosts
- fqdn Socket.gethostbyaddr(info.last).first
+ #host is not in dns. optionally use:
+ #C:\WINDOWS\system32\drivers\etc\hosts
+ found_fqdn = false
+ info[3..info.length].reverse.each do |addr|
+ hostent = Socket.gethostbyaddr(addr)
+ if hostent.first =~ /.+?\.(.*)/
+ fqdn hostent.first
+ found_fqdn = true
+ break
+ end
+ end
+ if !found_fqdn
+ fqdn info.first
+ end
end
domain collect_domain
end