Class: IPAddress::IPv6::Loopback

Inherits:
IPAddress::IPv6 show all
Defined in:
lib/ipaddress_2/ipv6.rb

Overview

The loopback address is a unicast localhost address. If an application in a host sends packets to this address, the IPv6 stack will loop these packets back on the same virtual interface.

Loopback addresses are expressed in the following form:

::1

or, with their appropriate prefix,

::1/128

As for the unspecified addresses, IPv6 loopbacks can be created with IPAddress calling their own class:

ip = IPAddress::IPv6::Loopback.new

ip.to_string
  #=> "::1/128"

or by using the wrapper:

ip = IPAddress "::1"

ip.to_string
  #=> "::1/128"

Checking if an address is loopback is easy with the IPv6#loopback? method:

ip.loopback?
  #=> true

The IPv6 loopback address corresponds to 127.0.0.1 in IPv4.

Constant Summary

Constants inherited from IPAddress::IPv6

IN6FORMAT

Constants included from IPAddress

AUTHORS, GEM, NAME, VERSION

Instance Method Summary collapse

Methods inherited from IPAddress::IPv6

#+, #<=>, #[], #[]=, #add, #address, #advance_network, #allocate, #as_json, #bits, #broadcast, #broadcast_u128, compress, #compressed, #data, #each, expand, #find_adjacent_subnet, #first, groups, #groups, #hexs, #hostpart, #hostpart_u128, #include?, #include_all?, #last, #link_local?, #literal, #loopback?, #mapped?, #network, #network?, #network_u128, #next_network, parse_data, parse_hex, parse_u128, #pred, #prefix, #prefix=, #previous_network, #regress_network, #reverse, #size, #split, #subnet, #subtract, #succ, summarize, #supernet, #to_hex, #to_i, #to_s, #to_string, #to_string_uncompressed, #unique_local?, #unspecified?

Methods included from IPAddress

demongoize, deprecate, evolve, #ipv4?, #ipv6?, mongoize, #mongoize, ntoa, parse, valid?, valid_ip?, valid_ipv4?, valid_ipv4_netmask?, valid_ipv4_subnet?, valid_ipv6?, valid_ipv6_subnet?

Constructor Details

#initializeLoopback

Creates a new IPv6 unspecified address

ip = IPAddress::IPv6::Loopback.new

ip.to_string
  #=> "::1/128"

1324
1325
1326
1327
1328
1329
# File 'lib/ipaddress_2/ipv6.rb', line 1324

def initialize
  @address = ("0000:"*7)+"0001"
  @groups = Array.new(7,0).push(1)
  @prefix = Prefix128.new(128)
  @compressed = compress_address
end