Class: NetAddr::CIDRv6

### Home Classes Methods

### In Files

- lib/cidr.rb

### Parent

NetAddr::CIDR

### Methods

- ::new
- ::unique_local

### Files

- Errors
- README
- changelog

### Class/Module Index

Quicksearch

- NetAddr
- NetAddr::CIDR
- NetAddr::CIDRv4
- NetAddr::CIDRv6
- NetAddr::EUI
- NetAddr::EUI48
- NetAddr::EUI64
- NetAddr::Tree

No matching classes.

# NetAddr::CIDRv6

IPv6 CIDR address - Inherits all methods from NetAddr::CIDR. Addresses of this class are composed of a 128-bit address space.

### Public Class Methods

new(ip, netmask=nil, tag={}, wildcard_mask=nil, wildcard_mask_bit_flipped=false) click to toggle source

    This method performs absolutely no error checking, and is meant to be used only by
    other internal methods for the sake of the speedier creation of CIDR objects.
    Please consider using #create unless you know what you are doing with 100% certainty.

### Arguments:

- ip - Integer representing an ip address

- netmask - Integer representing a binary netmask

- tag - Hash used to append custom tags to CIDR

- wildcard_mask - Integer representing a binary mask

- wildcard_mask_bit_flipped - indicates whether or not the wildcard_mask is bit-flipped or not

    # File lib/cidr.rb, line 239
    def initialize(ip, netmask=nil, tag={}, wildcard_mask=nil, wildcard_mask_bit_flipped=false)
        @ip = ip

        if ( self.kind_of?(NetAddr::CIDRv4) )
            @version = 4
            @address_len = 32
        else
            @version = 6
            @address_len = 128
        end
        @all_f = 2**@address_len - 1

        if (netmask)
            @netmask = netmask
        else
            @netmask = 2**@address_len - 1
        end

        @network = (@ip & @netmask)
        @hostmask = @netmask ^ @all_f
        @tag = tag

        if (!wildcard_mask)
            @wildcard_mask = @netmask
        else
            @wildcard_mask = wildcard_mask
            @wildcard_mask = ~@wildcard_mask if (wildcard_mask_bit_flipped)
        end

    end

unique_local(eui) click to toggle source

### Synopsis

Generate an IPv6 Unique Local CIDR address based on the algorithm described in RFC 4193.

From the RFC:

    1) Obtain the current time of day in 64-bit NTP format [NTP].

    2) Obtain an EUI-64 identifier from the system running this
       algorithm.  If an EUI-64 does not exist, one can be created from
       a 48-bit MAC address as specified in [ADDARCH].  If an EUI-64
       cannot be obtained or created, a suitably unique identifier,
       local to the node, should be used (e.g., system serial number).

    3) Concatenate the time of day with the system-specific identifier
       in order to create a key.

    4) Compute an SHA-1 digest on the key as specified in [FIPS, SHA1];
       the resulting value is 160 bits.

    5) Use the least significant 40 bits as the Global ID.

    6) Concatenate FC00::/7, the L bit set to 1, and the 40-bit Global
       ID to create a Local IPv6 address prefix.

    Example:
    eui = NetAddr::EUI.create('aabb.ccdd.eeff')
    NetAddr::CIDRv6.unique_local(eui) => fdb4:3014:e277:0000:0000:0000:0000:0000/48

### Arguments:

- NetAddr::EUI object

### Returns:

- CIDRv6 object

    # File lib/cidr.rb, line 2152
    def CIDRv6.unique_local(eui)

        if (eui.kind_of?(NetAddr::EUI48) )
            eui = eui.to_eui64.to_s
        elsif (eui.kind_of?(NetAddr::EUI64) )
            eui = eui.to_s
        else
            raise ArgumentError, "Expected NetAddr::EUI object but #{eui.class} received."
        end

        ntp_time = ''

        # get current time (32-bits), convert to 4-byte string, and append to ntp_time
        time = Time.now.to_i
        4.times do
            ntp_time.insert(0, (time & 0xff).chr )
            time = time >> 8
        end

        # create 32-bit fractional, convert to 4-byte string, and append to ntp_time
        fract = rand(2**32-1)
        4.times do
            ntp_time.insert(0, (fract & 0xff).chr )
            fract = fract >> 8
        end

        # create sha1 hash
        pre_hash = ntp_time << eui
        gid = Digest::SHA1.hexdigest(pre_hash).slice!(30..39)
        addr = 'fd' << gid << '00000000000000000000'

        return( NetAddr::CIDRv6.new(addr.to_i(16), 0xffffffffffff00000000000000000000 ) )
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.