Skip to content

Commit

Permalink
Replace ip? for getnameinfo, but look for dot for canonname
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Powell <thomas.powell@progress.com>
  • Loading branch information
tpowell-progress committed Oct 4, 2023
1 parent 6bde4b1 commit 8ec28c0
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/ohai/mixin/network_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 =~ /\./

Check failure on line 68 in lib/ohai/mixin/network_helper.rb

View workflow job for this annotation

GitHub Actions / chefstyle

[Correctable] Performance/RegexpMatch: Use match? instead of =~ when MatchData is not used.

Check failure on line 68 in lib/ohai/mixin/network_helper.rb

View workflow job for this annotation

GitHub Actions / chefstyle

[Correctable] Performance/StringInclude: Use String#include? instead of a regex match with literal-only pattern.

# 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
Expand Down

0 comments on commit 8ec28c0

Please sign in to comment.