Class IPAddress::Prefix32
In: lib/ipaddress/prefix.rb
Parent: Prefix

Methods

[]   bits   host_prefix   hostmask   new   octets   parse_netmask   to_ip   to_u32  

Constants

IN4MASK = 0xffffffff

Public Class methods

Creates a new prefix object for 32 bits IPv4 addresses

  prefix = IPAddress::Prefix32.new 24
    #=> 24

Creates a new prefix by parsing a netmask in dotted decimal form

  prefix = IPAddress::Prefix32::parse_netmask "255.255.255.0"
    #=> 24

Public Instance methods

Shortcut for the octecs in the dotted decimal representation

  prefix = IPAddress::Prefix32.new 24

  prefix[2]
    #=> 255

Transforms the prefix into a string of bits representing the netmask

  prefix = IPAddress::Prefix32.new 24

  prefix.bits
    #=> "11111111111111111111111100000000"

Returns the length of the host portion of a netmask.

  prefix = Prefix32.new 24

  prefix.host_prefix
    #=> 8

The hostmask is the contrary of the subnet mask, as it shows the bits that can change within the hosts

  prefix = IPAddress::Prefix32.new 24

  prefix.hostmask
    #=> "0.0.0.255"

An array of octets of the IPv4 dotted decimal format

  prefix = IPAddress::Prefix32.new 24

  prefix.octets
    #=> [255, 255, 255, 0]

Gives the prefix in IPv4 dotted decimal format, i.e. the canonical netmask we‘re all used to

  prefix = IPAddress::Prefix32.new 24

  prefix.to_ip
    #=> "255.255.255.0"

Unsigned 32 bits decimal number representing the prefix

  prefix = IPAddress::Prefix32.new 24

  prefix.to_u32
    #=> 4294967040

[Validate]