Class: EnfCli::IPV6

Inherits:
Object
  • Object
show all
Defined in:
lib/enfcli.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ipv6) ⇒ IPV6

Returns a new instance of IPV6.



48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/enfcli.rb', line 48

def initialize(ipv6)
  begin
    # create IPAddr object
    ip = IPAddr.new ipv6

    # make sure it is an ipv6 address
    raise EnfCli::ERROR, "#{ipv6} is not a valid Ipv6 address." unless ip.ipv6?

    @ip = ip
  rescue IPAddr::InvalidAddressError
    raise EnfCli::ERROR, "#{ipv6} is not a valid Ipv6 address."
  end
end

Class Method Details

.ntoh(ipv6_bytes) ⇒ Object



70
71
72
73
# File 'lib/enfcli.rb', line 70

def self.ntoh(ipv6_bytes)
  ip = IPAddr::new_ntoh(ipv6_bytes)
  EnfCli::IPV6.new ip.to_s
end

Instance Method Details

#htonObject



66
67
68
# File 'lib/enfcli.rb', line 66

def hton
  @ip.hton
end

#to_sObject



62
63
64
# File 'lib/enfcli.rb', line 62

def to_s
  @ip.to_s
end