This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Patch: java.net.InetAddress


Hi list,


InetAddress.lookup() has the problem that is looks up all addresses given to 
it. Even "0.0.0.0" is looked up. DNS severs tend to just return 0.0.0.0 as 
address. GLIBC doesnt seem to do this. When you have no access to a nameserver
the lookup method blocks until a timeout occurs (normally 5 seconds or so).
This mainly occurs on offline systems.

To circumvent this timeout I rewrite lookup() to just return when it is asked 
for "0.0.0.0".

Please review and comment.


Michael
Index: ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/libjava/ChangeLog,v
retrieving revision 1.2380
diff -u -b -B -r1.2380 ChangeLog
--- ChangeLog	27 Nov 2003 10:08:31 -0000	1.2380
+++ ChangeLog	27 Nov 2003 11:37:46 -0000
@@ -1,3 +1,15 @@
+2003-11-27  Michael Koch  <konqueror@gmx.de>
+
+	* java/net/InetAddress.java
+	(lookup): New method that doesnt lookup "0.0.0.0".
+	(lookup0): Renamed from lookup.
+	* java/net/natInetAddressNoNet.cc
+	(lookup0): Renamed from lookup.
+	* java/net/natInetAddressPosix.cc
+	(lookup0): Renamed from lookup.
+	* java/net/natInetAddressWin32.cc
+	(lookup0): Renamed from lookup.
+
 2003-11-27  Dalibor Topic <robilad@kaffe.org>
 
 	* java/text/FieldPosition.java (equals): Adapted to handle
Index: java/net/InetAddress.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/net/InetAddress.java,v
retrieving revision 1.24
diff -u -b -B -r1.24 InetAddress.java
--- java/net/InetAddress.java	29 Oct 2003 10:53:19 -0000	1.24
+++ java/net/InetAddress.java	27 Nov 2003 11:37:46 -0000
@@ -564,8 +564,22 @@
    */
   private static native byte[] aton (String host);
 
-  private static native InetAddress[] lookup (String hostname,
+  private static native InetAddress[] lookup0 (String hostname,
 		                              InetAddress addr, boolean all);
+
+  private static InetAddress[] lookup (String hostname,
+				       InetAddress addr, boolean all)
+  {
+    if (addr.equals(ANY_IF))
+      {
+	byte[] zeros = { 0, 0, 0, 0 };
+	InetAddress[] result = new InetAddress[1];
+	result[0] = new InetAddress(zeros, "0.0.0.0");
+	return result;
+      }
+
+    return lookup0(hostname, addr, all);
+  }
 
   private static native int getFamily (byte[] address);
 
Index: java/net/natInetAddressNoNet.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/net/natInetAddressNoNet.cc,v
retrieving revision 1.2
diff -u -b -B -r1.2 natInetAddressNoNet.cc
--- java/net/natInetAddressNoNet.cc	24 Mar 2003 13:40:44 -0000	1.2
+++ java/net/natInetAddressNoNet.cc	27 Nov 2003 11:37:46 -0000
@@ -24,7 +24,7 @@
 }
 
 JArray<java::net::InetAddress*> *
-java::net::InetAddress::lookup (jstring, java::net::InetAddress *, jboolean)
+java::net::InetAddress::lookup0 (jstring, java::net::InetAddress *, jboolean)
 {
   return NULL;
 }
Index: java/net/natInetAddressPosix.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/net/natInetAddressPosix.cc,v
retrieving revision 1.1
diff -u -b -B -r1.1 natInetAddressPosix.cc
--- java/net/natInetAddressPosix.cc	18 Mar 2003 06:01:16 -0000	1.1
+++ java/net/natInetAddressPosix.cc	27 Nov 2003 11:37:46 -0000
@@ -106,7 +106,7 @@
 
 
 JArray<java::net::InetAddress*> *
-java::net::InetAddress::lookup (jstring host, java::net::InetAddress* iaddr,
+java::net::InetAddress::lookup0 (jstring host, java::net::InetAddress* iaddr,
 				jboolean all)
 {
   struct hostent *hptr = NULL;
Index: java/net/natInetAddressWin32.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/net/natInetAddressWin32.cc,v
retrieving revision 1.4
diff -u -b -B -r1.4 natInetAddressWin32.cc
--- java/net/natInetAddressWin32.cc	29 Aug 2003 04:21:01 -0000	1.4
+++ java/net/natInetAddressWin32.cc	27 Nov 2003 11:37:46 -0000
@@ -50,7 +50,7 @@
 
 
 JArray<java::net::InetAddress*> *
-java::net::InetAddress::lookup (jstring host, java::net::InetAddress* iaddr,
+java::net::InetAddress::lookup0 (jstring host, java::net::InetAddress* iaddr,
         jboolean all)
 {
   struct hostent *hptr = NULL;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]