Hi,
the attached patch partly fixes PR29576. Without redesigning VMNetworkInterface
I just added a constructor which sets the field name to null and adds the
ANY_ADDR to the address list. NetworkInterface got a new package private method
which is to be called by MulticastSocket. Some other methods learned to deal
with the field name of an VMNetworkInterface instance being null.

ChangeLog:
2006-10-25  Robert Schuster  <[EMAIL PROTECTED]>

        Fixes PR29576
        * java/net/NetworkInterface.java:
        (createAnyInterface): New method.
        (equals): Added if-statement to handle case where netif.name is null.
        * vm/reference/java/net/VMNetworkInterface.java:
        (hashCode): Rewritten.
        (VMNetworkInterface): New constructor.


cya
Robert
Index: java/net/NetworkInterface.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/net/NetworkInterface.java,v
retrieving revision 1.20
diff -u -r1.20 NetworkInterface.java
--- java/net/NetworkInterface.java	17 Sep 2006 07:31:42 -0000	1.20
+++ java/net/NetworkInterface.java	24 Oct 2006 23:17:23 -0000
@@ -67,6 +67,16 @@
     this.netif = netif;
   }
   
+  /** Creates an NetworkInterface instance which
+   * represents any interface in the system. Its only
+   * address is <code>0.0.0.0/0.0.0.0</code>. This
+   * method is needed by [EMAIL PROTECTED] MulticastSocket#getNetworkInterface}
+   */
+  static NetworkInterface createAnyInterface()
+  {
+    return new NetworkInterface(new VMNetworkInterface());
+  }
+  
   /**
    * Returns the name of the network interface
    *
@@ -206,6 +216,9 @@
       return false;
 
     NetworkInterface tmp = (NetworkInterface) obj;
+    
+    if (netif.name == null)
+      return tmp.netif.name == null;
 
     return (netif.name.equals(tmp.netif.name)
             && (netif.addresses.equals(tmp.netif.addresses)));
@@ -219,7 +232,12 @@
   public int hashCode()
   {
     // FIXME: hash correctly
-    return netif.name.hashCode() + netif.addresses.hashCode();
+    int hc = netif.addresses.hashCode();
+    
+    if (netif.name != null)
+      hc += netif.name.hashCode();
+    
+    return hc;
   }
 
   /**
Index: vm/reference/java/net/VMNetworkInterface.java
===================================================================
RCS file: /cvsroot/classpath/classpath/vm/reference/java/net/VMNetworkInterface.java,v
retrieving revision 1.5
diff -u -r1.5 VMNetworkInterface.java
--- vm/reference/java/net/VMNetworkInterface.java	17 Sep 2006 07:31:43 -0000	1.5
+++ vm/reference/java/net/VMNetworkInterface.java	24 Oct 2006 23:17:23 -0000
@@ -66,6 +66,23 @@
     addresses = new HashSet();
   }
   
+  /**
+   * Creates a dummy instance which represents any network
+   * interface.
+   */
+  public VMNetworkInterface()
+  {
+    addresses = new HashSet();
+    try
+      {
+        addresses.add(InetAddress.getByName("0.0.0.0"));
+      }
+    catch (UnknownHostException _)
+      {
+        // Cannot happen.
+      }
+  }
+  
   static
   {
     if (Configuration.INIT_LOAD_LIBRARY)

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to