Getting error Uninitialized contstant IN
Closed this issue · 4 comments
mayuroks commented
I just want an async dns resolver for one time task. I installed 0.5 version n copy pasted the resolver code to test.. But it gave me the error Uninitialized constant IN. Can you gimme a simple example pasted on a gist or tell what possiblly could i b doing wrong?
ioquatix commented
Can you show me the full source code of what you are running?
mayuroks commented
This is on ruby 1.9.3
#! /usr/bin/env ruby
require 'rubydns/system'
require "rubygems"
require "rubydns"
#resolver = RubyDNS::Resolver.new([[:udp, "8.8.8.8", 53], [:tcp, "8.8.8.8", 53]])
resolver = RubyDNS::Resolver.new(RubyDNS::System::nameservers)
EventMachine::run do
resolver.query('google.com', IN::A) do |response|
case response
when RubyDNS::Message
puts "Got response: #{response.answers.first}"
else
# Response is of class RubyDNS::ResolutionFailure
puts "Failed: #{response.message}"
end
EventMachine::stop
end
end
This is the error I get
./rubydns_test.rb
./rubydns_test.rb:11:in `block in <main>': uninitialized constant IN (NameError)
from /usr/local/rvm/gems/ruby-1.9.3-p545/gems/eventmachine-1.0.3/lib/eventmachine.rb:187:in `call'
from /usr/local/rvm/gems/ruby-1.9.3-p545/gems/eventmachine-1.0.3/lib/eventmachine.rb:187:in `run_machine'
from /usr/local/rvm/gems/ruby-1.9.3-p545/gems/eventmachine-1.0.3/lib/eventmachine.rb:187:in `run'
from ./rubydns_test.rb:10:in `<main>'
mayuroks commented
Found it. This works
#! /usr/bin/env ruby
require 'rubydns/system'
require "rubygems"
require "rubydns"
require 'resolv'
#resolver = RubyDNS::Resolver.new([[:udp, "8.8.8.8", 53], [:tcp, "8.8.8.8", 53]])
resolver = RubyDNS::Resolver.new(RubyDNS::System::nameservers)
EventMachine::run do
addr = Resolv::DNS::Resource::IN::A
resolver.query('in1.php.net', addr) do |response|
case response
when RubyDNS::Message
puts "Got response: #{response.answer}"
else
# Response is of class RubyDNS::ResolutionFailure
puts "Failed: #{response.message}"
end
EventMachine::stop
end
end
ioquatix commented
I guess somewhere in the code you copied from was IN = Resolv::DNS::Resource::IN
which you didn't copy. Thus it didn't work :D Good work sorting it out yourself.