This is the mail archive of the java-discuss@sourceware.cygnus.com 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]

[patch] Re: Correction to InetAddress bug?


Warren Levy wrote:

> Hmm, the problem seems to be that the InetAddress that is instantiated
> has a null address value.  I'll have to look deeper to decide on the
> right fix (something might be relying on address being null at times,
> though I hope not).

Err, well... here is a suggested fix ;-)

[WARNING: DatagramSocketImpl changes not tested.]

regards

  [ bryce ]

Index: libjava/java/net/ServerSocket.java
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/net/ServerSocket.java,v
retrieving revision 1.5
diff -u -r1.5 ServerSocket.java
--- ServerSocket.java 1999/06/17 00:21:22 1.5
+++ ServerSocket.java 1999/07/27 07:38:28
@@ -25,6 +25,10 @@
   static SocketImplFactory factory;
   SocketImpl impl;

+  static final byte[] zeros = {0,0,0,0};
+  /* dummy InetAddress, used to bind socket to any (all) network interfaces */
+  static final InetAddress IF_ANY = new InetAddress(zeros, null);
+
   public ServerSocket (int port)
     throws java.io.IOException
   {
@@ -34,7 +38,7 @@
   public ServerSocket (int port, int backlog)
     throws java.io.IOException
   {
-    this(port, backlog, null);
+    this(port, backlog, IF_ANY);
   }

   public ServerSocket (int port, int backlog, InetAddress bindAddr)
Index: libjava/java/net/natPlainSocketImpl.cc
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/net/natPlainSocketImpl.cc,v
retrieving revision 1.6
diff -u -r1.6 natPlainSocketImpl.cc
--- natPlainSocketImpl.cc 1999/06/17 00:21:26 1.6
+++ natPlainSocketImpl.cc 1999/07/27 07:38:28
@@ -66,17 +66,10 @@
 {
   union SockAddr u;
   struct sockaddr *ptr = (struct sockaddr *) &u.address;
-  jbyte *bytes = NULL;
-  // FIXME: Use getaddrinfo() to get actual protocol instead of assuming ipv4.
-  int len = 4; // Initialize for INADDR_ANY in case host is NULL.
+  jbyteArray haddress = host->address;
+  jbyte *bytes = elements (haddress);
+  int len = haddress->length;

-  if (host != NULL)
-    {
-      jbyteArray haddress = host->address;
-      bytes = elements (haddress);
-      len = haddress->length;
-    }
-
   if (len == 4)
     {
       u.address.sin_family = AF_INET;
Index: libjava/java/net/natPlainDatagramSocketImpl.cc
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/net/natPlainDatagramSocketImpl.cc,v
retrieving revision 1.7
diff -u -r1.7 natPlainDatagramSocketImpl.cc
--- natPlainDatagramSocketImpl.cc 1999/07/02 18:50:21 1.7
+++ natPlainDatagramSocketImpl.cc 1999/07/27 07:38:29
@@ -96,16 +96,10 @@
   // FIXME: prob. need to do a setsockopt with SO_BROADCAST to allow multicast.
   union SockAddr u;
   struct sockaddr *ptr = (struct sockaddr *) &u.address;
-  jbyte *bytes = NULL;
   // FIXME: Use getaddrinfo() to get actual protocol instead of assuming ipv4.
-  int len = 4; // Initialize for INADDR_ANY in case host is NULL.
-
-  if (host != NULL)
-    {
-      jbyteArray haddress = host->address;
-      bytes = elements (haddress);
-      len = haddress->length;
-    }
+  jbyteArray haddress = host->address;
+  jbyte *bytes = elements (haddress);
+  int len = haddress->length;

   if (len == 4)
     {



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