Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →
class method
IPAddr.ntop
(::String addr) -> ::String
ntop(addr)
lib/ipaddr.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.4.1/lib/ipaddr.rb, line 114
def self.ntop(addr)
if addr.is_a?(String) && addr.encoding != Encoding::BINARY
raise InvalidAddressError, "invalid encoding (given #{addr.encoding}, expected BINARY)"
end
case addr.bytesize
when 4
addr.unpack('C4').join('.')
when 16
IN6FORMAT % addr.unpack('n8')
else
raise AddressFamilyError, "unsupported address family"
end
end
Convert a network byte ordered string form of an IP address into human readable form. It expects the string to be encoded in Encoding::ASCII_8BIT (BINARY).