# The question about getaddinfo

**URL:** <https://www.ruby-forum.com/t/the-question-about-getaddinfo/167943>\
**Category:** Ruby\
**Created:** [May 14, 2009, 10:29am UTC](https://www.ruby-forum.com/t/the-question-about-getaddinfo/167943 "2009-05-14T10:29:47Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![zq1956](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/bc79bd/32.png) [@zq1956](https://www.ruby-forum.com/u/zq1956)\
**Post date:** [May 14, 2009, 10:29am UTC](https://www.ruby-forum.com/t/the-question-about-getaddinfo/167943/1 "2009-05-14T10:29:47Z")

</div>

I use getaddinfo to get A machine’s hostname,  
in B machine,the result is correct.  
but in A machine,the result is just A machine’s name  
I use nslookup,the result is also correct.  
who can tell me why in A machineï¼Œthe result is wrong?

---

<div class="post-metadata">

**Author:** ![zq1956](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/bc79bd/32.png) [@zq1956](https://www.ruby-forum.com/u/zq1956)\
**Post date:** [May 14, 2009, 10:50am UTC](https://www.ruby-forum.com/t/the-question-about-getaddinfo/167943/2 "2009-05-14T10:50:22Z")

</div>

Hi,  
approx. 3-5 months ago I had similar problem. The guy who helped tried  
to  
help mes said that it works for him. Then he realized that he uses a  
newes  
version of ruby (1.9.something at that time). So my first suggestion  
would  
be to check (or to write) what version of ruby are you using.  
I solved the problem using external command (host). I hope it helped a  
bit.

Cheers,

V.

---

<div class="post-metadata">

**Author:** ![zq1956](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/bc79bd/32.png) [@zq1956](https://www.ruby-forum.com/u/zq1956)\
**Post date:** [May 14, 2009, 12:18pm UTC](https://www.ruby-forum.com/t/the-question-about-getaddinfo/167943/3 "2009-05-14T12:18:27Z")

</div>

Qq Zz wrote:

> I use getaddinfo to get A machine’s hostname,  
> in B machine,the result is correct.  
> but in A machine,the result is just A machine’s name  
> I use nslookup,the result is also correct.  
> who can tell me why in A machineï¼Œthe result is wrong?

You don’t even say what platform you’re on. If you’re on a Unix-like  
platform, then maybe you have something like

1.2.3.4 machineA [machineA.com](http://machineA.com)

in /etc/hosts.

---

<div class="post-metadata">

**Author:** ![zq1956](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/bc79bd/32.png) [@zq1956](https://www.ruby-forum.com/u/zq1956)\
**Post date:** [May 14, 2009, 12:46pm UTC](https://www.ruby-forum.com/t/the-question-about-getaddinfo/167943/4 "2009-05-14T12:46:47Z")

</div>

Brian C. wrote:

> Qq Zz wrote:
> 
> > I use getaddinfo to get A machine’s hostname,  
> > in B machine,the result is correct.  
> > but in A machine,the result is just A machine’s name  
> > I use nslookup,the result is also correct.  
> > who can tell me why in A machineï¼Œthe result is wrong?
> 
> You don’t even say what platform you’re on. If you’re on a Unix-like  
> platform, then maybe you have something like
> 
> 1.2.3.4 machineA [machineA.com](http://machineA.com)
> 
> in /etc/hosts.

no,windows vista

---

<div class="post-metadata">

**Author:** ![zq1956](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/bc79bd/32.png) [@zq1956](https://www.ruby-forum.com/u/zq1956)\
**Post date:** [May 14, 2009, 12:21pm UTC](https://www.ruby-forum.com/t/the-question-about-getaddinfo/167943/5 "2009-05-14T12:21:22Z")

</div>

From: “Qq Zz” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> I use getaddinfo to get A machine’s hostname,  
> in B machine,the result is correct.  
> but in A machine,the result is just A machine’s name  
> I use nslookup,the result is also correct.  
> who can tell me why in A machineï¼Œthe result is wrong?

I ran into something similar awhile back:  
[http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/13805](http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/13805)

This is what I now use:

ip = “208.77.188.166”  
result = Socket.getnameinfo( Socket.pack\_sockaddr\_in(0, ip) )  
hostname = result ? result.first : ip

Hope this helps,

Bill

---

<div class="post-metadata">

**Author:** ![zq1956](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/bc79bd/32.png) [@zq1956](https://www.ruby-forum.com/u/zq1956)\
**Post date:** [May 14, 2009, 12:49pm UTC](https://www.ruby-forum.com/t/the-question-about-getaddinfo/167943/6 "2009-05-14T12:49:02Z")

</div>

Bill K. wrote:

> From: “Qq Zz” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
> 
> > I use getaddinfo to get A machine’s hostname,  
> > in B machine,the result is correct.  
> > but in A machine,the result is just A machine’s name  
> > I use nslookup,the result is also correct.  
> > who can tell me why in A machineï¼Œthe result is wrong?
> 
> I ran into something similar awhile back:  
> [http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/13805](http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/13805)
> 
> This is what I now use:
> 
> ip = “208.77.188.166”  
> result = Socket.getnameinfo( Socket.pack\_sockaddr\_in(0, ip) )  
> hostname = result ? result.first : ip
> 
> Hope this helps,
> 
> Bill

the response is: address family for hostname not supported

oh my god!!!

---

<div class="post-metadata">

**Author:** ![zq1956](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/bc79bd/32.png) [@zq1956](https://www.ruby-forum.com/u/zq1956)\
**Post date:** [May 15, 2009, 6:11am UTC](https://www.ruby-forum.com/t/the-question-about-getaddinfo/167943/7 "2009-05-15T06:11:52Z")

</div>

Vladimir F. wrote:

> Hi,  
> approx. 3-5 months ago I had similar problem. The guy who helped tried  
> to  
> help mes said that it works for him. Then he realized that he uses a  
> newes  
> version of ruby (1.9.something at that time). So my first suggestion  
> would  
> be to check (or to write) what version of ruby are you using.  
> I solved the problem using external command (host). I hope it helped a  
> bit.
> 
> Cheers,
> 
> V.

1.9.1 not work  
host? in windows?

---

<div class="post-metadata">

**Author:** ![zq1956](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/bc79bd/32.png) [@zq1956](https://www.ruby-forum.com/u/zq1956)\
**Post date:** [May 14, 2009, 2:49pm UTC](https://www.ruby-forum.com/t/the-question-about-getaddinfo/167943/8 "2009-05-14T14:49:44Z")

</div>

From: “Qq Zz” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> the response is: address family for hostname not supported

Hmm. I too get that error on Windows:

ruby -v -rsocket -e “p Socket.getnameinfo(Socket.pack\_sockaddr\_in(0,  
‘208.77.188.166’))”  
ruby 1.8.4 (2005-12-24) [i386-mswin32]  
-e:1:in `getnameinfo’: getnameinfo: address family for hostname not  
supported. (SocketError)  
from -e:1

ruby19 -v -rsocket -e “p Socket.getnameinfo(Socket.pack\_sockaddr\_in(0,  
‘208.77.188.166’))”  
ruby 1.9.1p129 (2009-05-12) [i386-mswin32\_71]  
-e:1:in `getnameinfo': getnameinfo: The requested name is valid and was found in the database, but it does not have the correct associated data being resolved for. (SocketError) from -e:1:in `’

However it works on Linux:

ruby -v -rsocket -e “p Socket.getnameinfo(Socket.pack\_sockaddr\_in(0,  
‘208.77.188.166’))”  
ruby 1.8.6 (2008-07-17 patchlevel 279) [x86\_64-linux]  
[“[www.example.com](http://www.example.com)”, “0”]

Hmm… dunno… ☹

Regards,

Bill
