39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/facter/util/resolvers/ffi/hostname.rb', line 39
def self.getffiaddrinfo(hostname)
ret = FFI::MemoryPointer.new(:pointer)
hints = Facter::Util::Resolvers::Ffi::AddrInfo.new
hints[:ai_family] = Socket::AF_UNSPEC
hints[:ai_socketype] = Socket::SOCK_STREAM
hints[:ai_flags] = Socket::AI_CANONNAME
res = Hostname.getaddrinfo(hostname, '', hints.to_ptr, ret)
log = Log.new(self)
log.debug("FFI Getaddrinfo finished with exit status: #{res}")
log.debug("FFI Getaddrinfo returned an AddrInfo struct at address: #{ret}")
return unless res.zero?
return if ret == FFI::Pointer::NULL || ret.read_pointer == FFI::Pointer::NULL
begin
addr = Facter::Util::Resolvers::Ffi::AddrInfo.new(ret.read_pointer)
name = addr[:ai_canonname]
log.debug("FFI AddrInfo struct has the fqdn: #{name}")
return if !name || hostname == name
name
ensure
Hostname.freeaddrinfo(ret.read_pointer)
end
end
|