struct IPAddress::Prefix32

Defined in:

ipaddress/prefix.cr

Constant Summary

IN4MASK = 4294967295_i64.to_u32

32 bit mask for IPv4

Constructors

Class Method Summary

Instance Method Summary

Instance methods inherited from struct IPAddress::Prefix

+(other : Prefix) : Int
+(other : Int) : Int
+
, -(other : Prefix) : Int
-(other : Int) : Int
-
, <=>(other : Prefix)
<=>(other : Int)
<=>
, hash(hasher) hash, pred : Prefix pred, prefix : Int32 prefix, succ : Prefix succ, to_i : Int32 to_i, to_s(io : IO) to_s

Constructor methods inherited from struct IPAddress::Prefix

new(prefix : Int) new

Constructor Detail

def self.new(prefix : Int32 = 32) #

Creates a new prefix object for 32 bits IPv4 addresses.

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

[View source]

Class Method Detail

def self.parse_netmask(netmask : String) : Prefix #

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

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

[View source]

Instance Method Detail

def [](index) : Int32 #

Shortcut for the octecs in the dotted decimal representation.

prefix = IPAddress::Prefix32.new 24
prefix[2] # => 255

See also #octets


[View source]
def bits : String #

Transforms the prefix into a string of bits representing the netmask.

prefix = IPAddress::Prefix32.new 24
prefix.bits # => "11111111111111111111111100000000"

[View source]
def host_prefix : Int32 #

Returns the length of the host portion of a netmask.

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

[View source]
def hostmask : String #

Returns the wildcard mask, i.e. a mask of bits that indicates which parts of an IP address are available for examination.

A wildcard mask can be thought of as an inverted subnet mask. For example, a subnet mask of 255.255.255.0 inverts to a wildcard mask of 0.0.0.255.

prefix = IPAddress::Prefix32.new 24
prefix.hostmask # => "0.0.0.255"

[View source]
def octets : Array(Int32) #

An array of octets of the IPv4 dotted decimal format.

prefix = IPAddress::Prefix32.new 24
prefix.octets # => [255, 255, 255, 0]

See also #to_ip


[View source]
def to_ip : String #

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"

[View source]
def to_u32 : UInt32 #

Unsigned 32 bits decimal number representing the prefix.

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

[View source]