[kaffe] CVS kaffe (dalibor): Fixed NetworkInterface to return single interface per interface name
Kaffe CVS
Kaffe Mailing List <kaffe@kaffe.org>
Sun May 23 14:15:03 2004
PatchSet 4774
Date: 2004/05/23 20:39:04
Author: dalibor
Branch: HEAD
Tag: (none)
Log:
Fixed NetworkInterface to return single interface per interface name
2004-05-23 Dalibor Topic <robilad@kaffe.org>
* libraries/javalib/java/net/NetworkInterface.java:
(condense) new method.
(getNetworkInterfaces) Use condense.
(getByName, getByInetAddress) Use getNetworkInterfaces.
Reported by: Ito Kazumitsu <kaz@maczuka.gcd.org>
Members:
ChangeLog:1.2345->1.2346
libraries/javalib/java/net/NetworkInterface.java:1.6->1.7
Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.2345 kaffe/ChangeLog:1.2346
--- kaffe/ChangeLog:1.2345 Sun May 23 18:53:07 2004
+++ kaffe/ChangeLog Sun May 23 20:39:04 2004
@@ -1,3 +1,12 @@
+2004-05-23 Dalibor Topic <robilad@kaffe.org>
+
+ * libraries/javalib/java/net/NetworkInterface.java:
+ (condense) new method.
+ (getNetworkInterfaces) Use condense.
+ (getByName, getByInetAddress) Use getNetworkInterfaces.
+
+ Reported by: Ito Kazumitsu <kaz@maczuka.gcd.org>
+
2004-05-23 Guilhem Lavaux <guilhem@kaffe.org>
* libraries/javalib/bootstrap.classlist: Added several missing classes
Index: kaffe/libraries/javalib/java/net/NetworkInterface.java
diff -u kaffe/libraries/javalib/java/net/NetworkInterface.java:1.6 kaffe/libraries/javalib/java/net/NetworkInterface.java:1.7
--- kaffe/libraries/javalib/java/net/NetworkInterface.java:1.6 Mon May 17 22:25:05 2004
+++ kaffe/libraries/javalib/java/net/NetworkInterface.java Sun May 23 20:39:10 2004
@@ -40,7 +40,7 @@
import gnu.classpath.Configuration;
import java.util.Enumeration;
import java.util.Vector;
-
+import java.util.*;
/**
* This class models a network interface on the host computer. A network
@@ -143,7 +143,7 @@
public static NetworkInterface getByName(String name)
throws SocketException
{
- Vector networkInterfaces = getRealNetworkInterfaces();
+ Vector networkInterfaces = getNetworkInterfaces();
for (Enumeration e = networkInterfaces.elements(); e.hasMoreElements();)
{
@@ -168,7 +168,7 @@
public static NetworkInterface getByInetAddress(InetAddress addr)
throws SocketException
{
- Vector networkInterfaces = getRealNetworkInterfaces();
+ Vector networkInterfaces = getNetworkInterfaces();
for (Enumeration interfaces = networkInterfaces.elements();
interfaces.hasMoreElements();)
@@ -186,6 +186,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
*
@@ -198,7 +233,9 @@
if (networkInterfaces.isEmpty())
return null;
- return networkInterfaces.elements();
+ Collection condensed = condense(networkInterfaces);
+
+ return Collections.enumeration(condensed);
}
/**