From 8ec28c00e140d7f5e8b8e7c584b7f14c4a789c18 Mon Sep 17 00:00:00 2001 From: Thomas Powell Date: Tue, 3 Oct 2023 20:38:48 -0400 Subject: [PATCH] Replace ip? for getnameinfo, but look for dot for canonname Signed-off-by: Thomas Powell --- lib/ohai/mixin/network_helper.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/ohai/mixin/network_helper.rb b/lib/ohai/mixin/network_helper.rb index 005952685..8d5757d08 100644 --- a/lib/ohai/mixin/network_helper.rb +++ b/lib/ohai/mixin/network_helper.rb @@ -38,9 +38,10 @@ def hex_to_dec_netmask(netmask) dec end + # Addrinfo#ip*? methods return true on AI_CANONNAME Addrinfo records that match + # the ipv* scheme and #ip? always returns true unless a non tcp Addrinfo def ip?(hostname) !!(canonname =~ Resolv::IPv4::Regex) || !!(canonname =~ Resolv::IPv6::Regex) - end # This does a forward and reverse lookup on the hostname to return what should be @@ -62,8 +63,9 @@ def canonicalize_hostname(hostname) # This API is preferred as it never gives us an IP address for broken DNS # (see https://github.com/chef/ohai/pull/1705) # However, we have found that Windows hosts that are not joined to a domain - # can return a non-qualified hostname) - return canonname unless ip?(canonname) + # can return a non-qualified hostname). + # Use a '.' in the canonname as indicator of FQDN + return canonname if canonname =~ /\./ # If we got a non-qualified name, then we do a standard reverse resolve # which, assuming DNS is working, will work around that windows bug