Hello Alan, I have to say you are not right. And if you are, then there is somwhere huge problem, because it behaves in completely different way as it should. I tried to use getaddrinfo aswell, but the result was same (no canonical name). Performance was terrible (17 times slower than getaddress and approx. 4 times slower than gethostbyname). Next thing is, that I don't have to have reverse dns set up, in fact I don't. Reason why I believe this is true is, that "host" command works perfectly withouth correct reverse dns. I thought that it is due to line in /etc/hosts where I assigned IP to conanical name and aliases, but when I commented out this line it worked as good as before. result of command host a : a.b.c.d.e.f.g has address 10.0.2.1 result of nslookup 10.0.2.1 : Server: v.x.y.z Address: v.x.y.z#53 ** server can't find 1.2.0.10.in-addr.arpa: NXDOMAIN So if "host" command works and all ruby's functions don't I assume there is some problem in ruby. Regards, V. On Thu, Nov 20, 2008 at 09:21:44AM +0900, Alan Johnson wrote: > On Wed, Nov 19, 2008 at 3:44 PM, Vladimir Fekete > <fekete / melkor.dnp.fmph.uniba.sk> wrote: > > Hello Alan, > > > > I think we don't understand each other. I don't need reverse DNS (I would use > > resolv.rb for it instead). What I need is: > > > > you have machine with fully qualified domain name (FQDN) > > a.b.c.d.e > > It's hostname is > > a > > It's IP is > > v.x.y.z > > > > I'm looking for function which could give me back fully qualified domain > > name and IP when I pass hostname as argument. > > > > Probably I don't understand what is canonical name I thought it should be FQDN > > but it is not. > > > > because this code: > > > > puts "getaddress : " + IPSocket.getaddress("a").inspect > > puts "gethostbyname : " + TCPSocket.gethostbyname("a").inspect > > > > has result: > > > > getaddress : "10.0.2.1" > > gethostbyname : ["a", [], 2, "10.0.2.1"] > > > > and what i need is result like this: > > > > gethostbyname : ["a.b.c.d.e", ["a"], 2, "10.0.2.1"] > > > > I hope it's more clear now. (or maybe I completely did not get what you > > wanted to tell me) > > > > Cheers, > > > > V. > > > > TCPSocket.gethostbyname is confusingly inconsistent with Socket.gethostbyname. > I suggest always using the Socket version. I think it will work the way you > want it to. > > Alternatively, the getaddrinfo method may do what you are looking for. > Technically getaddrinfo obsoletes gethostbyname, anyway. It looks like: > Socket.getaddrinfo(host, port [, family] [, socktype] [, protocol] [, > flags]) => resultsArray > > The rules for using it are pretty complicated but you'll probably want to do > something like: > > include Socket::Constants > p Socket.getaddrinfo('myhost', nil, AF_INET, SOCK_STREAM) > > Note that in either case your reverse DNS lookup must be configured correctly > or all you will get is an ip address. You can test this using the nslookup > command from a command prompt in Linux or Windows. > > -- > Alan > >