John,

I'll bet that the first line in your /etc/hosts is:

127.0.0.1               localhost localhost.localdomain

At least, that's the way it was with mine and, when I tried your program, I 
got the same "broken" answer you got.  After reading Per's message, I moved 
that line below the second line in my /etc/hosts so that it looks like this:

198.41.2.245            knight.internic.net knight
127.0.0.1               localhost localhost.localdomain

Guess what?  It now works correctly.  I have a feeling that it shouldn't be 
dependent on your /etc/hosts entry order, but at least this will account for 
the difference between your and Per's results.

BTW, I'm testing this on a RH 5.1 system with sn's jdk-1.1.6v1.2.

pete

] John A. Zinky wrote:
] > 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?
] 
] It works fine for me: RedHat 5.0 and jdk1.1.6-v1 (sbb). Make sure you
] have the
] latest version of libc installed (can be found at www.redhat.com).
] 
] > [ .... ]
] > 2) Could this be a configuration error in the linux host?
] 
] I believe that is the case. Try with DNS configured.
] 
] > [ .... ]
] 
] /Per Widerlund
] 


Reply via email to