class Resolv::IPv4 - Documentation for Ruby 4.0
Description: class Resolv::IPv4: DNS IPv4 address.
Keywords: ruby,class,Resolv::IPv4

🔍

No recent searches

# class Resolv::IPv4

A `Resolv::DNS` `IPv4` address.

### Constants

Regex

  Regular expression `IPv4` addresses must match.

### Attributes

address [R]

The raw `IPv4` address as a `String`.

### Public Class Methods

create (arg)
Source

    # File lib/resolv.rb, line 2945
    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

Creates a new `IPv4` address from `arg` which may be:

`IPv4`

  returns `arg`.

`String`

  `arg` must match the IPv4::Regex constant

### Public Instance Methods

to_name ()
Source

    # File lib/resolv.rb, line 2992
    def to_name
      return DNS::Name.create(
        '%d.%d.%d.%d.in-addr.arpa.' % @address.unpack('CCCC').reverse)
    end

Turns this `IPv4` address into a Resolv::DNS::Name.