JDK-4073306 : iaddr.getLocalHost/iaddr.getHostName() does not understand /etc/hosts correctly
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 1.1.1
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: solaris_2.5.1
  • CPU: sparc
  • Submitted: 1997-08-20
  • Updated: 1997-11-12
  • Resolved: 1997-11-12
Related Reports
Duplicate :  
Description
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 - ###@###.###
======================================================================

Comments
WORK AROUND Name: joT67522 Date: 08/20/97 We can get it right by changing the /etc/hosts on *all* our Solaris machines. Our sys admin, however, does not at all like the idea of needing special /etc/hosts files for each machine. Moreover, since we are a department of a large faculty, we inherit a global /etc/hosts repeatedly, i.e., whenever an entry is changed somewhere in the faculty universe. The bug mentioned above requires us to patch the officially distributed /etc/hosts too often and for too many of our own hosts. We would greatly appreciate a quick bug fix. ======================================================================
11-06-2004