Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 23 Aug 2004 09:51:54 -0600
From:      Greg Lewis <glewis@eyesbeyond.com>
To:        Brad Karp <bkarp+@cs.cmu.edu>
Cc:        freebsd-java@freebsd.org
Subject:   Re: getHostName() broken?
Message-ID:  <20040823155154.GA15838@misty.eyesbeyond.com>
In-Reply-To: <20040820030209.9E7D643D1D@mx1.FreeBSD.org>
References:  <20040820030209.9E7D643D1D@mx1.FreeBSD.org>

next in thread | previous in thread | raw e-mail | index | archive | help

--r5Pyd7+fXNt84Ff3
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

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@eyesbeyond.com
Eyes Beyond                         Web     : http://www.eyesbeyond.com
Information Technology              FreeBSD : glewis@FreeBSD.org

--r5Pyd7+fXNt84Ff3
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="HostName.java"

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();
		}
	}
}

--r5Pyd7+fXNt84Ff3--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040823155154.GA15838>