Module: Facter::Util::Resolvers::Ffi::Hostname
- Extended by:
- FFI::Library
- Defined in:
- lib/facter/util/resolvers/ffi/hostname.rb
Overview
Constant Summary collapse
- HOST_NAME_MAX =
64
Class Method Summary collapse
-
.getffiaddrinfo(hostname) ⇒ Object
rubocop:disable Metrics/AbcSize.
- .getffihostname ⇒ Object
Class Method Details
.getffiaddrinfo(hostname) ⇒ Object
rubocop:disable Metrics/AbcSize
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) # rubocop:disable Metrics/AbcSize 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 |
.getffihostname ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/facter/util/resolvers/ffi/hostname.rb', line 30 def self.getffihostname raw_hostname = ::FFI::MemoryPointer.new(:char, HOST_NAME_MAX) res = Hostname.gethostname(raw_hostname, HOST_NAME_MAX) return unless res.zero? raw_hostname.read_string end |