class PacketGen::Header::IP::Addr

IP address, as a group of 4 bytes @author Sylvain Daubert

Constants

IPV4_ADDR_REGEX

Public Instance Methods

==(other) click to toggle source
# File lib/packetgen/header/ip/addr.rb, line 66
def ==(other)
  other.is_a?(self.class) &&
    fields.all? { |attr| self[attr].value == other[attr].value }
end
from_human(str) click to toggle source

Read a dotted address @param [String] str @return [self]

# File lib/packetgen/header/ip/addr.rb, line 34
def from_human(str)
  return self if str.nil?

  m = str.match(IPV4_ADDR_REGEX)
  if m
    self[:a1].read m[1].to_i
    self[:a2].read m[2].to_i
    self[:a3].read m[3].to_i
    self[:a4].read m[4].to_i
  end
  self
end
mcast?() click to toggle source

Return true if this address is a multicast one @return [Boolean]

# File lib/packetgen/header/ip/addr.rb, line 62
def mcast?
  self.a1 >= 224 && self.a1 <= 239
end
to_human() click to toggle source

Addr in human readable form (dotted format) @return [String]

# File lib/packetgen/header/ip/addr.rb, line 49
def to_human
  fields.map { |f| self[f].to_i.to_s }.join('.')
end
to_i() click to toggle source

Addr as an integer @return [Integer]

# File lib/packetgen/header/ip/addr.rb, line 55
def to_i
  (self.a1 << 24) | (self.a2 << 16) | (self.a3 << 8) |
    self.a4
end