Class: MetasploitDataModels::IPAddress::V4::Single
- Inherits:
-
Segmented
- Object
- Segmented
- MetasploitDataModels::IPAddress::V4::Single
- Defined in:
- app/models/metasploit_data_models/ip_address/v4/single.rb
Overview
A single IPv4 address, in standard, dotted decimal notation.
Instance Method Summary collapse
-
#+(other) ⇒ MetasploitDataModels::IPAddress::V4::Single
Adds
other
IPv4 address to this IPv4 address. -
#succ ⇒ Object
The succeeding IPv4 address.
Instance Method Details
#+(other) ⇒ MetasploitDataModels::IPAddress::V4::Single
Adds other
IPv4 address to this IPv4 address.
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 |
#succ ⇒ Object
The succeeding IPv4 address.
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 |