[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[commit-cp] [bug #12826] NetworkInterface.getNetworkInterfaces() should
From: |
Ito Kazumitsu |
Subject: |
[commit-cp] [bug #12826] NetworkInterface.getNetworkInterfaces() should return condensed results |
Date: |
Tue, 7 Jun 2005 22:13:41 +0000 |
User-agent: |
w3m/0.5.1 |
Follow-up Comment #1, bug #12826 (project classpath):
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);
}
/**
_______________________________________________________
Reply to this item at:
<http://savannah.gnu.org/bugs/?func=detailitem&item_id=12826>
_______________________________________________
Message sent via/by Savannah
http://savannah.gnu.org/
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [commit-cp] [bug #12826] NetworkInterface.getNetworkInterfaces() should return condensed results,
Ito Kazumitsu <=