Class: MetasploitDataModels::IPAddress::V4::Single

Inherits:
Segmented
  • Object
show all
Defined in:
app/models/metasploit_data_models/ip_address/v4/single.rb

Overview

A single IPv4 address, in standard, dotted decimal notation.

Examples:

Dotted Decimal Notation

'1.2.3.4'

Constant Summary

Constants inherited from Segmented

MetasploitDataModels::IPAddress::V4::Segmented::SEGMENT_COUNT, MetasploitDataModels::IPAddress::V4::Segmented::SEPARATOR

Instance Attribute Summary

Attributes inherited from Segmented

#value

Instance Method Summary collapse

Methods inherited from Segmented

#<=>, regexp, segment, segment_class, segment_class_name, segment_count, #segments, #segments=, #to_s

Methods included from Match::Child

#match, #match_regexp, #regexp

Instance Method Details

#+(other) ⇒ MetasploitDataModels::IPAddress::V4::Single

Adds other IPv4 address to this IPv4 address.

Returns:

Raises:

  • (TypeError)

    if other isn't the same class.

  • (ArgmentError)

    if self plus other yields an IP address greater than 255.255.255.255.

See Also:



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/models/metasploit_data_models/ip_address/v4/single.rb', line 24

def +(other)
  unless other.is_a? self.class
    raise TypeError, "Cannot add #{other.class} to #{self.class}"
  end

  carry = 0
  sum_segments = []
  low_to_high_segments = segments.zip(other.segments).reverse

  low_to_high_segments.each do |self_segment, other_segment|
    segment, carry = self_segment.add_with_carry(other_segment, carry)
    sum_segments.unshift segment
  end

  unless carry == 0
    raise ArgumentError,
          "#{self} + #{other} is not a valid IP address.  It is #{sum_segments.join('.')} with a carry (#{carry})"
  end

  self.class.new(segments: sum_segments)
end

#succObject

The succeeding IPv4 address.

Raises:

  • (TypeError)

    if other isn't the same class.

  • (ArgmentError)

    if self plus other yields an IP address greater than 255.255.255.255.

See Also:



50
51
52
# File 'app/models/metasploit_data_models/ip_address/v4/single.rb', line 50

def succ
  self + self.class.new(value: '0.0.0.1')
end