Comment on this RCR (edit wiki page) | RCRchive home

RCR 176: Extend resolv.rb

submitted by danielhobe on Fri Dec 19 2003 08:04:37 PM -0800

Status: pending


Abstract

It would be very useful to be able to tell the Resolv::DNS class what DNS servers to use without reading them in from a file.

Problem

Resolv::DNS requires that the list of DNS servers to query comes from a specified file (/etc/resolv.conf is the default). To use arbitrary DNS servers for name resolution one must create a resolv.conf format file with the servers in it and then pass that to Resolv::DNS. This should be much easier to do.

Proposal

There should be a second class (DNS2) within the Resolv class that is designed to allow the user to tell it what DNS servers to use when they instantiate the object.

A second solution might be to modify the current class to accept either a filename or the DNS server list.

Analysis

Telling the object what DNS servers to use directly is much cleaner than creating files for the object to read in.

Implementation

The following is a sample implementation of a DNS2 class that takes all the information found in a resolv.conf file as arguments:
require 'resolv'

class Resolv::DNS2 < Resolv::DNS
  def initialize(nameserver=['localhost'],search = nil,ndots=1)
@mutex = Mutex.new @config = Config.new(nameserver,search,ndots) @initialized = nil end class Config < Resolv::DNS::Config def initialize(nameserver,search,ndots) @mutex = Mutex.new @nameserver = nameserver @search = search @ndots = ndots @initialized = nil end def lazy_initialize unless @search hostname = Socket.gethostname if /\./ =~ hostname @search = [Resolv::DNS::Label.split($')] else @search = [[]] end end end end end

Vote for this RCR

Strongly opposed [0]
Opposed [0]
Neutral [0]
In favor [9]
Strongly advocate [0]

Change the status of this RCR to:

accepted

rejected

withdrawn


Add comments here

I like the idea, but I don't like calling the class DNS2. It's not very descriptive, IMO. Could the DNS initialize method be changed to accept either a filename or a Hash of named arguments? -- Paul Brannan


Back to RCRchive.


RCR Submission page and RCRchive powered by Ruby, Apache, RuWiki (modified), and RubLog