lib/ipaddress_2/ipv6.rb
#
# This method implements the subnetting function
# similar to the one described in RFC3531.
#
# By specifying a new prefix, the method calculates
# the network number for the given IPv4 object
# and calculates the subnets associated to the new
# prefix.
#
# For example, given the following network:
#
#   ip = IPAddress "172.16.10.0/24"
#
# we can calculate the subnets with a /26 prefix
#
#   ip.subnet(26).map{&:to_string)
#     #=> ["172.16.10.0/26", "172.16.10.64/26",
#          "172.16.10.128/26", "172.16.10.192/26"]
#
# The resulting number of subnets will of course always be
# a power of two.
#
This method implements the subnetting function
similar to the one described in RFC3531.

By specifying a new prefix, the method calculates
the network number for the given IPv4 object
and calculates the subnets associated to the new
prefix.

For example, given the following network.



we can calculate the subnets with a /26 prefix



The resulting number of subnets will of course always be
a power of two.
This method implements the subnetting function similar to the one described in RFC3531 . By specifying a new prefix the method calculates the network number for the given IPv4 object and calculates the subnets associated to the new prefix . For example given the following network . we can calculate the subnets with a / 26 prefix The resulting number of subnets will of course always be a power of two .
def subnet(subprefix)
      unless ((@prefix.to_i)..128).include? subprefix
        raise ArgumentError, "New prefix must be between #@prefix and 128"
      end
      Array.new(2**(subprefix-@prefix.to_i)) do |i|
        self.class.parse_u128(network_u128+(i*(2**(128-subprefix))), subprefix)
      end
    end
def subnet ( subprefix ) unless ( ( @prefix . to_i ) .. 128 ) . include? subprefix raise ArgumentError , "New prefix must be between #@prefix and 128" end Array . new ( 2 ** ( subprefix - @prefix . to_i ) ) do | i | self . class . parse_u128 ( network_u128 + ( i * ( 2 ** ( 128 - subprefix ) ) ) , subprefix ) end end
This method implements the subnetting function
similar to the one described in RFC3531.
This method implements the subnetting function similar to the one described in RFC3531 .
subprefix
<not_specific>