Problem with Socket.getaddrinfo inside controller or model

I am using Rails 2.2.2,
trying to get hostname by IP with code like

require ‘socket’
Socket.getaddrinfo(‘’, nil, “AF_INET”)

In the rails console it works well and gives me:

[[“AF_INET”, 0, “”, “”, 2, 2, 17],
[“AF_INET”, 0, “”, “”, 2, 1, 6]]

But, inside model or controller output different:

[[“AF_INET”, 0, “”, “”, 2, 2, 17],
[“AF_INET”, 0, “”, “”, 2, 1, 6]]

Please help to fix and get hostname by ip inside model.


There is a method in mongrel gem, mongrel.rb, Mongrel::HttpServer#run
which has a line:


and it seems this changes the global state of the Socket class. So,
basically I did this:

Socket.getaddrinfo(some_ip, nil, “AF_INET”)
BasicSocket.do_not_reverse_lookup=true # In case nothing goes wrong
with mongrel :slight_smile:

Quit annoying stuff, I found it almost accidently, doubt it is
somewhere documented.

On Feb 16, 11:55 am, Taro I. [email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs