JDK-4073539 : InetAddress get local host fails on Solaris in some cases
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 1.1.1,1.1.2,1.1.3,1.1.5,1.2.0
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: solaris_2.5.1,solaris_2.6
  • CPU: unknown,sparc
  • Submitted: 1997-08-21
  • Updated: 1999-01-07
  • Resolved: 1999-01-07
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
1.2.2 1.2.2Fixed
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Description
If the first entry of /etc/hosts is localhost on Solaris, the getLocalHost call will return "localhost".


dale.mcduffie@Eng 1998-09-30
----------------------------
A customer reports that this bug is in fact not fixed in 1.2beta4: they are not
using NIS. I am unable to find a non-NIS machine, but believe that the customer
is correct. Here is the call with the test case:

Bug #4073539 describes how java.net.InetAddress.getLocalHost()
returns the first entry in /etc/hosts instead of the correct
address.  That bug page is labeled "closed, fixed in 1.2beta4,
1998-04-13".  However, the bug is still present in 1.2beta4
on my Solaris 2.6 system, as seen below.


[baskerville] uname -a
SunOS baskerville.CS.Arizona.EDU 5.6 Generic_105181-06 sun4u sparc SUNW,Ultra-1
[baskerville] java -version
java version "1.2beta4"
Classic VM (build JDK-1.2beta4-K, green threads, sunwjit)
[baskerville] java -fullversion
java full version "JDK-1.2beta4-K"
[baskerville] 
[baskerville] cat t.java

import java.net.*;

class t {
    public static void main (String args[]) {
        try {
            System.out.println(InetAddress.getLocalHost().getHostName());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

[baskerville] 
[baskerville] javac t.java
[baskerville] java t
localhost
[baskerville]

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: 1.2.2 FIXED IN: 1.2.2 INTEGRATED IN: 1.2.2
14-06-2004

SUGGESTED FIX Use sysV sysinfo callinstead of getlocalhost in the implementation.
11-06-2004

WORK AROUND Make sure that the first entry in /etc/hosts is the actual host name and not "localhost". jeff.nisewanger@Eng 1998-12-15
15-12-1998

EVALUATION Fixed in 1.2beta4. benjamin.renaud@Eng 1998-04-13 All we do is call gethostname() from libc. If it gives us a goofy answer then that is a Solaris bug -- it will be giving goofy answers to a bunch of other software on the same machine also. It's hard to see how this is the JDK's problem. jeff.nisewanger@Eng 1998-10-27 Actually gethostname() returns the correct host name which isn't a fully qualified host name. InetAddressImpl.c tries its best to get a fully qualified host name. It calls gethostbyname_r() to get the IP address; then calls gethostbyaddr_r() to get the host name - in some cases, it gets fully qualified name at this point. But due to a solaris bug (#4185755), if "files" is the first source for "hosts" in /etc/nsswitch.conf, the first entry in /etc/hosts is returned instead of the correct host information. To work around this solaris bug, we can check the host name returned by gethostbyaddr_r(). If the host name returned by gethostname() isn't a prefix of the name returned by gethostbyaddr_r(), we just return the host name returned by gethostname(). sharon.liu@eng 1998-10-29
29-10-1998