[kaffe] java.net.InetAddress.getAllByName returns wrong value for localhost

Ito Kazumitsu kaz at maczuka.gcd.org
Tue Sep 9 09:00:03 PDT 2003


Hi,

I am afraid there is something wrong around java.net.InetAddress.

First, I patched InetAddress.java for debugging:

bash-2.05b$ diff -u java/net/InetAddress.java.orig java/net/InetAddress.java
--- java/net/InetAddress.java.orig	Sun Sep  7 23:09:00 2003
+++ java/net/InetAddress.java	Wed Sep 10 00:20:04 2003
@@ -306,8 +306,15 @@
 
     for (int i = 0; i < iplist.length; i++)
       {
-        if (iplist[i].length != 4)
+        if (iplist[i].length != 4) {
+	  System.err.println("i=" + i + " iplist[i].length=" + iplist[i].length);
+	  for (int j = 0; j < iplist[i].length; j++) {
+	    System.err.print("" + iplist[i][j] + ".");
+	  }
+	  System.err.println();
+	  System.err.flush();
           throw new UnknownHostException (hostname);
+	}
 
         // Don't store the hostname in order to force resolution of the
         // canonical names of these ip's when the user asks for the hostname

Then I ran the following test.

bash-2.05b$ cat TestInetAddress.java
import java.net.InetAddress;
public class TestInetAddress {
    public static void main(String args[]) throws Exception {
	String host = args[0];
	InetAddress ia = InetAddress.getByName(host);
	System.out.println(host + " = " + ia);
    }
}
bash-2.05b$ java TestInetAddress ph.maczuka.gcd.org
ph.maczuka.gcd.org = ph.maczuka.gcd.org/192.168.0.1
bash-2.05b$ java TestInetAddress localhost         
i=0 iplist[i].length=16
0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.1.
java.net.UnknownHostException: localhost
   at java.net.InetAddress.getAllByName (InetAddress.java:316)
   at java.net.InetAddress.getByName (InetAddress.java:382)
   at TestInetAddress.main (TestInetAddress.java:5)




More information about the kaffe mailing list