Bug on resolv.rb? or I'm just a newbe?


#1

I can’t get the point in this problem …
this code works fine …
require ‘resolv’
r = Resolv::DNS.new
puts r.getaddress(“www.google.com”)
r.each_resource(“urubatan.com.br”, Resolv::DNS::Resource::IN::A) { |mx|
puts mx
}

but if I change to this
require ‘resolv’
r = Resolv::DNS.new
puts r.getaddress(“www.google.com”)
r.each_resource(“urubatan.com.br”, Resolv::DNS::Resource::CNAME) { |mx|
puts mx
}

ot this (that is what I want to do)
require ‘resolv’
r = Resolv::DNS.new
puts r.getaddress(“www.google.com”)
r.each_resource(“urubatan.com.br”, Resolv::DNS::Resource::MX) { |mx|
puts mx
}

I get this error:
/usr/lib/ruby/1.8/resolv.rb:1171:in pack': can't convert nil into Integer (TypeError) from /usr/lib/ruby/1.8/resolv.rb:1171:input_pack’
from /usr/lib/ruby/1.8/resolv.rb:1142:in encode' from /usr/lib/ruby/1.8/resolv.rb:1139:ineach’
from /usr/lib/ruby/1.8/resolv.rb:1139:in encode' from /usr/lib/ruby/1.8/resolv.rb:1159:ininitialize’
from /usr/lib/ruby/1.8/resolv.rb:1125:in new' from /usr/lib/ruby/1.8/resolv.rb:1125:inencode’
from /usr/lib/ruby/1.8/resolv.rb:652:in sender' ... 6 levels... from /usr/lib/ruby/1.8/resolv.rb:868:ineach’
from /usr/lib/ruby/1.8/resolv.rb:868:in resolv' from /usr/lib/ruby/1.8/resolv.rb:470:ineach_resource’
from teste.rb:4

I think it is a bug in the ruby base library.
I’m using ruby 1.8, and I have tried this in tree different machines …

Can some one help me with this please?

Thanks.


#2

It seems that is a bug in the resolv.rb …
I found a workaround with the Net::DNS gem …
and posted the solution in my blog (but this one is in portuguese)
if there is anyone with the same problem, please take a look at here:
http://www.urubatan.com.br/2007/07/28/dicas-rapidas-de-ruby-para-quem-estiver-iniciando-como-eu/