Name: joT67522 Date: 08/20/97
Currently, getLocalHost() and getHostName() return the machine
name of the first non comment line of /etc/hosts, independent of
whether this is the actual machine.
Here is a test program:
import java.net.*;
class inettest {
static public void main(String[] argv) {
try {
//this does not understand /etc/hosts. Instead of returning
//the proper results for the current machine. The first
//non-comment line of /etc/hosts is used. Even if this
//line is the entry of a completly different host.
InetAddress iaddr = InetAddress.getLocalHost();
System.out.println(iaddr.getHostName());
} catch (UnknownHostException e) {
System.out.println("UnknownHostException");
}
}
}
Here is an example of /etc/hosts that *works* for my machine
(Indianapolis)
# $Source: /home/irafs1/nis-files/NIS/RCS/hosts,v $ $Date: 1995/05/11 07:34:02 $# $Log: hosts,v $
# Revision 1.1 1995/05/11 07:34:02 guenther
# Initial revision
#
#----------------- INFORMATIK RECHNERABTEILUNG (IRA) -----------------
#
129.13.13.148 i41s26 Indianapolis # SS 4 / 85 28.9.95
#
# 129.13.1.1 iracs1 # Cisco R-140 (becker)
129.13.1.2 irams1 pppserver # Dial PPP
#
129.13.10.25 irau25 IRAU25 # Dec R-14? (N.N)
129.13.20.26 irau26 IRAU26 # Dec R-14? (N.N)
129.13.20.27 irau27 IRAU27 # Dec R-14? (N.N)
129.13.20.28 irau28 IRAU28 # Dec R-14? (N.N)
129.13.20.29 irau29 IRAU29 # Dec R-14? (N.N)
129.13.20.30 irau30 IRAU30 # Dec R-14? (N.N)
<-- a lot of lines removed -->
If Indianaplois is not the first non-comment line, but instead
irams1, then getLocalHost() and getHostName(0 will return that.
Similar for "localhost"
This problem was especially hard to track down, sind we use a
tool that itself uses RMI. For registering objects that tool
encodes the machine name into the name of remote objects, that
are not directly visible to the user.
company - University of Karlsruhe , email - ###@###.###
======================================================================
- duplicates
-
JDK-4073539 InetAddress get local host fails on Solaris in some cases
-
- Resolved
-