class Dnsruby::IPv4

Constants

Regex

Regular expression IPv4 addresses must match

Attributes

address[R]

A String representation of the IPv4 address.

Public Class Methods

create(arg) click to toggle source
# File lib/dnsruby/ipv4.rb, line 21
def self.create(arg)
  case arg
  when IPv4
    return arg
  when Regex
    if (0..255) === (a = $1.to_i) &&
     (0..255) === (b = $2.to_i) &&
     (0..255) === (c = $3.to_i) &&
     (0..255) === (d = $4.to_i)
      return self.new([a, b, c, d].pack("CCCC"))
    else
      raise ArgumentError.new("IPv4 address with invalid value: " + arg)
    end
  else
    raise ArgumentError.new("cannot interpret as IPv4 address: #{arg.inspect}")
  end
end

Public Instance Methods

==(other) click to toggle source
# File lib/dnsruby/ipv4.rb, line 62
def ==(other)
  return @address == other.address
end
eql?(other) click to toggle source
# File lib/dnsruby/ipv4.rb, line 66
def eql?(other)
  return self == other
end
hash() click to toggle source
# File lib/dnsruby/ipv4.rb, line 70
def hash
  return @address.hash
end
to_name() click to toggle source
# File lib/dnsruby/ipv4.rb, line 57
def to_name
  return Name.create(
    '%d.%d.%d.%d.in-addr.arpa.' % @address.unpack('CCCC').reverse)
end