The answer is pretty simple. The JDK finds out its information using 
gethostname(). This information is something that's been previously
set at system boot up with the sethostname syscall. The problem isn't really
the jdk, it's how your system is setup. If you type 'hostname' on the command
line, and you get localhost, that's what java's getLocalHost() is gonna
give you too. You need to look into having your machine setup correctly, 
and that usually revolves around a properly setup /etc/hosts. 

That's pretty much the extent of getLocalhost()...it does a gethostname, 
a gethostbyname to pull up the full host/domain, and then a gethostbyaddr
to provide you the address. 

Hope this helps out, 
Cheers, 
Karl Asha
[EMAIL PROTECTED]


"John A. Zinky" <[EMAIL PROTECTED]> writes:
> We have not been able to find a configuration of Linux Red Hat 5.0 and
> jdk 1.1.x that works for the following one line test program.
> 
> public class TestGetLocalHost {
>   public static void main(String[] args) {
>     try {
>       System.out.println(java.net.InetAddress.getLocalHost());
>     } catch (Exception e) { e.printStackTrace(); }
>   }}
> 
> The Test program prints the IP address of local host 
> (A necessary function for servers that need to publish their location)
> 
> On Solaris,NT, and  Red Hat 4.0/jdk1.1.3 this works: e.g:
>    guava.bbn.com/171.78.82.34
> On Linux Red Hat 5.0 jdk1.1.5 this returns the loopback address: e.g:
>    localhost/127.0.0.1
> 
> We have traced the problem in to the C routines for native platform
> on Line 298 in .../jdk1.1.5/src/java/net/InetAddress.java
>           localHost.hostName = impl.getLocalHostName();
>           System.out.println("local host name: " + localHost.hostName);
> 
> On linux:     local host name: localhost
> On Solaris:   local host name: guava.bbn.com
> 
> **** Questions *****
> 1) Does anyone have a Linux RedHat 5.0 configuration where this program works?
> 
> a) jdk1.1.3 does not work under RedHat 5.0 because it uses libc and not glibc
>    Is there a way to shimmy in libc just for this one java executable?
> 
> b) We have tried several version of jdk1.1.5 and jdk1.1.6, 
>    all of which we had a hard time installing.
> 
> c) How about a statically linked version of jdk1.1.x?
> 
> 2) Could this be a configuration error in the linux host?
> 
> 3) Could we hack the C source for impl.getLocalHostName?
>  a) Where is the source code?
>  b) Where is the Make?
> 
> 4) Could this be a security feature?
>  The news groups has lots of chatter on why getLocalHosts should not
>  give the IP address IN THE CASE OF APPLETS.
>  But this case, we have a SERVER, so it needs to get it's own address.
> 
> thanks
> zinky

Reply via email to