Joe Carter suggested:
> Change the order of localhost and the real host name in /etc/hosts.
> (real first!). The getlocalhost just seems to get the first it finds.
I tried this straightforward workaround, as silly as it seemed, and
the "GNU/Linux JDK InetAddr.getLocalHost() on glibc bug" vanished
immediately. I'm wondering why someone might have coded things this
way, since ordinarily people don't change their /etc/hosts file every
time they switch between interfaces (e.g., ppp0 at home, eth0 at
work). So I'd consider this a glic bug, unless it turns out the
code in getlocalhost() has a reason behind it.
--
Geoffrey S. Knauth http://world.std.com/~gsk
---------------------------------------------------------------------------
> From: "John A. Zinky" <[EMAIL PROTECTED]>
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/191.79.84.43
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