[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug-classpath] [Bug classpath/22929] New: NetworkInterface.getNetworkIn
From: |
pinskia at gcc dot gnu dot org |
Subject: |
[bug-classpath] [Bug classpath/22929] New: NetworkInterface.getNetworkInterfaces() should return condensed results |
Date: |
7 Aug 2005 21:01:44 -0000 |
Let's describe a network interface whose name is n and which has
addresses a1, a2, ..., an as (n (a1 a2 ... an)), or (n a1) if
n has only on address a1 or addresses other than a1 is ignored.
NetworkInterface.getNetworkInterfaces() should return something
like this:
((n1 (a11 a12 a13)) (n2 (a21 a22))) ---[a]
But it may be the case that VMNetworkInterface.getInterfaces()
returns something like this:
((n1 a11) (n1 a12) (n1 a13) (n2 a21) (n2 a22)) ---[b]
So NetworkInterface.getNetworkInterfaces() should condense
the data structure [b] into [a]. But now it simply returns [b].
We may ask VMNetworkInterface.getInterfaces() to return already
condensed data like [a], but I cannot expect that all implementations
of VMNetworkInterface can easily do this.
This will be a problem when a network interface has both IPv4 and
IPv6 addresses.
Kaffe's NetworkInterface is modified to do the condensing.
Please refer to the articles of Kaffe's mailing list around
http://www.kaffe.org/pipermail/kaffe/2005-April/102338.html
------- Additional Comments From from-classpath at savannah dot gnu dot org
2005-06-07 22:13 -------
This is the patch applied in Kaffe:
2005-04-25 Ito Kazumitsu <address@hidden>
* libraries/javalib/java/net/NetworkInterface.java
(getByName, getByInetAddress): call getNetworkInterfaces()
so that condensed result may be returned.
--- java/net/NetworkInterface.java.orig Wed Apr 20 06:42:21 2005
+++ java/net/NetworkInterface.java Tue Apr 26 00:47:21 2005
@@ -38,7 +38,12 @@
package java.net;
+import java.util.Collection;
+import java.util.Collections;
import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
import java.util.Vector;
/**
@@ -143,9 +148,7 @@
public static NetworkInterface getByName(String name)
throws SocketException
{
- Vector networkInterfaces = VMNetworkInterface.getInterfaces();
-
- for (Enumeration e = networkInterfaces.elements(); e.hasMoreElements();)
+ for (Enumeration e = getNetworkInterfaces(); e.hasMoreElements();)
{
NetworkInterface tmp = (NetworkInterface) e.nextElement();
@@ -170,9 +173,7 @@
public static NetworkInterface getByInetAddress(InetAddress addr)
throws SocketException
{
- Vector networkInterfaces = VMNetworkInterface.getInterfaces();
-
- for (Enumeration interfaces = networkInterfaces.elements();
+ for (Enumeration interfaces = getNetworkInterfaces();
interfaces.hasMoreElements();)
{
NetworkInterface tmp = (NetworkInterface) interfaces.nextElement();
@@ -188,6 +189,41 @@
throw new SocketException("no network interface is bound to such an IP
address");
}
+ static private Collection condense(Collection interfaces)
+ {
+ final Map condensed = new HashMap();
+
+ final Iterator interfs = interfaces.iterator();
+ while (interfs.hasNext()) {
+
+ final NetworkInterface face = (NetworkInterface) interfs.next();
+ final String name = face.getName();
+
+ if (condensed.containsKey(name))
+ {
+ final NetworkInterface conface = (NetworkInterface)
condensed.get(name);
+ if (!conface.inetAddresses.containsAll(face.inetAddresses))
+ {
+ final Iterator faceAddresses = face.inetAddresses.iterator();
+ while (faceAddresses.hasNext())
+ {
+ final InetAddress faceAddress = (InetAddress)
faceAddresses.next();
+ if (!conface.inetAddresses.contains(faceAddress))
+ {
+ conface.inetAddresses.add(faceAddress);
+ }
+ }
+ }
+ }
+ else
+ {
+ condensed.put(name, face);
+ }
+ }
+
+ return condensed.values();
+ }
+
/**
* Return an <code>Enumeration</code> of all available network interfaces
*
@@ -202,7 +238,9 @@
if (networkInterfaces.isEmpty())
return null;
- return networkInterfaces.elements();
+ Collection condensed = condense(networkInterfaces);
+
+ return Collections.enumeration(condensed);
}
/**
------- Additional Comments From pinskia at gcc dot gnu dot org 2005-08-07
21:01 -------
Confirmed.
--
Summary: NetworkInterface.getNetworkInterfaces() should return
condensed results
Product: classpath
Version: unspecified
Status: NEW
Severity: normal
Priority: P3
Component: classpath
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: from-classpath at savannah dot gnu dot org
CC: bug-classpath at gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22929
- [bug-classpath] [Bug classpath/22929] New: NetworkInterface.getNetworkInterfaces() should return condensed results,
pinskia at gcc dot gnu dot org <=