/[classpath]/classpath/java/net/NetworkInterface.java
ViewVC logotype

Diff of /classpath/java/net/NetworkInterface.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.8.2.5 by gnu_andrew, Tue Aug 2 20:12:23 2005 UTC revision 1.8.2.6 by gnu_andrew, Tue Aug 16 16:22:37 2005 UTC
# Line 38  exception statement from your version. * Line 38  exception statement from your version. *
38    
39  package java.net;  package java.net;
40    
41    import java.util.Collection;
42    import java.util.Collections;
43  import java.util.Enumeration;  import java.util.Enumeration;
44    import java.util.HashMap;
45    import java.util.Iterator;
46    import java.util.Map;
47  import java.util.Vector;  import java.util.Vector;
48    
49  /**  /**
# Line 143  public final class NetworkInterface Line 148  public final class NetworkInterface
148    public static NetworkInterface getByName(String name)    public static NetworkInterface getByName(String name)
149      throws SocketException      throws SocketException
150    {    {
151      Vector networkInterfaces = VMNetworkInterface.getInterfaces();      for (Enumeration e = getNetworkInterfaces(); e.hasMoreElements();)
   
     for (Enumeration e = networkInterfaces.elements(); e.hasMoreElements();)  
152        {        {
153          NetworkInterface tmp = (NetworkInterface) e.nextElement();          NetworkInterface tmp = (NetworkInterface) e.nextElement();
154    
# Line 170  public final class NetworkInterface Line 173  public final class NetworkInterface
173    public static NetworkInterface getByInetAddress(InetAddress addr)    public static NetworkInterface getByInetAddress(InetAddress addr)
174      throws SocketException      throws SocketException
175    {    {
176      Vector networkInterfaces = VMNetworkInterface.getInterfaces();      for (Enumeration interfaces = getNetworkInterfaces();
   
     for (Enumeration interfaces = networkInterfaces.elements();  
177           interfaces.hasMoreElements();)           interfaces.hasMoreElements();)
178        {        {
179          NetworkInterface tmp = (NetworkInterface) interfaces.nextElement();          NetworkInterface tmp = (NetworkInterface) interfaces.nextElement();
# Line 188  public final class NetworkInterface Line 189  public final class NetworkInterface
189      throw new SocketException("no network interface is bound to such an IP address");      throw new SocketException("no network interface is bound to such an IP address");
190    }    }
191    
192      static private Collection condense(Collection interfaces)
193      {
194        final Map condensed = new HashMap();
195    
196        final Iterator interfs = interfaces.iterator();
197        while (interfs.hasNext()) {
198    
199          final NetworkInterface face = (NetworkInterface) interfs.next();
200          final String name = face.getName();
201          
202          if (condensed.containsKey(name))
203            {
204              final NetworkInterface conface = (NetworkInterface) condensed.get(name);
205              if (!conface.inetAddresses.containsAll(face.inetAddresses))
206                {
207                  final Iterator faceAddresses = face.inetAddresses.iterator();
208                  while (faceAddresses.hasNext())
209                    {
210                      final InetAddress faceAddress = (InetAddress) faceAddresses.next();
211                      if (!conface.inetAddresses.contains(faceAddress))
212                        {
213                          conface.inetAddresses.add(faceAddress);
214                        }
215                    }
216                }
217            }
218          else
219            {
220              condensed.put(name, face);
221            }
222        }
223    
224        return condensed.values();
225      }
226    
227    /**    /**
228     * Return an <code>Enumeration</code> of all available network interfaces     * Return an <code>Enumeration</code> of all available network interfaces
229     *     *
# Line 202  public final class NetworkInterface Line 238  public final class NetworkInterface
238      if (networkInterfaces.isEmpty())      if (networkInterfaces.isEmpty())
239        return null;        return null;
240    
241      return networkInterfaces.elements();      Collection condensed = condense(networkInterfaces);
242    
243        return Collections.enumeration(condensed);
244    }    }
245    
246    /**    /**

Legend:
Removed from v.1.8.2.5  
changed lines
  Added in v.1.8.2.6

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26