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

Inherits:
Metasploit::Model::Base
  • Object
show all
Extended by:
Match::Child
Includes:
Comparable
Defined in:
app/models/metasploit_data_models/ip_address/v4/segment/single.rb

Overview

A segment number in an IPv4 address or the Nmap::Range#begin or Nmap::Range#send.

Constant Summary collapse

BITS =

Number of bits in a IPv4 segment

8
LIMIT =

Limit that #value can never reach

1 << BITS
MAXIMUM =

Maximum segment #value

LIMIT - 1
MINIMUM =

Minimum segment #value

0
REGEXP =

Regular expression for a segment (octet) of an IPv4 address in decimal dotted notation.

/(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Match::Child

match, match_regexp, regexp

Instance Attribute Details

#valueObject

Returns the value of attribute value.



38
39
40
# File 'app/models/metasploit_data_models/ip_address/v4/segment/single.rb', line 38

def value
  @value
end

Class Method Details

.bitsInteger

Number of bits in a IPv4 segment



58
59
60
# File 'app/models/metasploit_data_models/ip_address/v4/segment/single.rb', line 58

def self.bits
  BITS
end

Instance Method Details

#<=>(other) ⇒ 1, ...

Compare this segment to other.



72
73
74
# File 'app/models/metasploit_data_models/ip_address/v4/segment/single.rb', line 72

def <=>(other)
  value <=> other.value
end

#add_with_carry(other, carry = 0) ⇒ Array<(MetasploitDataModels::IPAddress::V4::Segment::Single, Integer)>

Full add (as in full adder) two (this segment and other) segments and a carry from the previous #add_with_carry.



85
86
87
88
89
90
91
92
# File 'app/models/metasploit_data_models/ip_address/v4/segment/single.rb', line 85

def add_with_carry(other, carry=0)
  improper_value = self.value + other.value + carry
  proper_value = improper_value % LIMIT
  carry = improper_value / LIMIT
  segment = self.class.new(value: proper_value)

  [segment, carry]
end

#succMetasploitDataModels::IPAddress::V4::Segment::Single?

The succeeding segment. Used in Ranges when walking the Range.



98
99
100
101
102
# File 'app/models/metasploit_data_models/ip_address/v4/segment/single.rb', line 98

def succ
  if value.respond_to? :succ
    self.class.new(value: value.succ)
  end
end