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

**URL:** <https://www.ruby-forum.com/t/bug-on-resolv-rb-or-im-just-a-newbe/110642>\
**Category:** Ruby\
**Created:** [July 28, 2007, 7:20pm UTC](https://www.ruby-forum.com/t/bug-on-resolv-rb-or-im-just-a-newbe/110642 "2007-07-28T19:20:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![urubatan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/bbe5ce/32.png) [@urubatan](https://www.ruby-forum.com/u/urubatan)\
**Post date:** [July 28, 2007, 7:20pm UTC](https://www.ruby-forum.com/t/bug-on-resolv-rb-or-im-just-a-newbe/110642/1 "2007-07-28T19:20:29Z")

</div>

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](http://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](http://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](http://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:in `put\_pack’  
from /usr/lib/ruby/1.8/resolv.rb:1142:in `encode' from /usr/lib/ruby/1.8/resolv.rb:1139:in `each’  
from /usr/lib/ruby/1.8/resolv.rb:1139:in `encode' from /usr/lib/ruby/1.8/resolv.rb:1159:in `initialize’  
from /usr/lib/ruby/1.8/resolv.rb:1125:in `new' from /usr/lib/ruby/1.8/resolv.rb:1125:in `encode’  
from /usr/lib/ruby/1.8/resolv.rb:652:in `sender' ... 6 levels... from /usr/lib/ruby/1.8/resolv.rb:868:in `each’  
from /usr/lib/ruby/1.8/resolv.rb:868:in `resolv' from /usr/lib/ruby/1.8/resolv.rb:470:in `each\_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.

---

<div class="post-metadata">

**Author:** ![urubatan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/bbe5ce/32.png) [@urubatan](https://www.ruby-forum.com/u/urubatan)\
**Post date:** [July 28, 2007, 9:29pm UTC](https://www.ruby-forum.com/t/bug-on-resolv-rb-or-im-just-a-newbe/110642/2 "2007-07-28T21:29:28Z")

</div>

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/](http://www.urubatan.com.br/2007/07/28/dicas-rapidas-de-ruby-para-quem-estiver-iniciando-como-eu/)
