getHostName() broken?

Greg Lewis glewis at eyesbeyond.com
Mon Aug 23 08:51:58 PDT 2004


On Thu, Aug 19, 2004 at 11:01:30PM -0400, Brad Karp wrote:
> I'm running 4.9-RELEASE, and have built the jdk1.4.2 port using revision 5
> of the FreeBSD patch kit.
> 
> I have a visualization application written in Java by a colleague that I've
> been running. The application shows nodes in a large-scale distributed system,
> and allows clicking on a host to show its Internet hostname.
> 
> The code uses getHostName() to do this.
> 
> I find that these reverse DNS lookups *all* fail; getHostName() returns a
> String that is a textual representation of the IP address. (There's no
> security manager involved here, BTW. The reference for getHostName() says
> the security manager may check for authorization on getHostName() calls,
> but I've not changed my Java runtime's security policy from the defaults.)
> 
> Further poking reveals that *no* outbound DNS queries (traffic destined for
> UDP or TCP port 53) are being generated for these reverse name lookups!
> 
> I'm perplexed. Can it really be that InetAddress.getHostName() is broken on
> FreeBSD? Has anyone seen similar behavior, and if so, can you propose a
> workaround, apart from linking in C code to do these reverse name lookups?

Works for me.  Test code attached.  Here is the output:

> java -cp . HostName
66.35.250.151
star.slashdot.org

Are you sure resolution works for you normally?  Can you run host(1) and
check that lookups succeed for the hosts?

-- 
Greg Lewis                          Email   : glewis at eyesbeyond.com
Eyes Beyond                         Web     : http://www.eyesbeyond.com
Information Technology              FreeBSD : glewis at FreeBSD.org
-------------- next part --------------
import java.net.*;

class
HostName {
	public
	static
	void
	main(String[] args) {
		try {
			InetAddress addr = InetAddress.getByName("66.35.250.151");
			System.out.println(addr.getHostAddress());
			System.out.println(addr.getHostName());
		}
		catch (Throwable t) {
			t.printStackTrace();
		}
	}
}


More information about the freebsd-java mailing list