diff options
Diffstat (limited to 'vm/reference/java/net/VMNetworkInterface.java')
-rw-r--r-- | vm/reference/java/net/VMNetworkInterface.java | 57 |
1 files changed, 44 insertions, 13 deletions
diff --git a/vm/reference/java/net/VMNetworkInterface.java b/vm/reference/java/net/VMNetworkInterface.java index 47f803246..7a29f4ee3 100644 --- a/vm/reference/java/net/VMNetworkInterface.java +++ b/vm/reference/java/net/VMNetworkInterface.java @@ -40,6 +40,9 @@ package java.net; import gnu.classpath.Configuration; +import java.nio.ByteBuffer; +import java.util.HashSet; +import java.util.Set; import java.util.Vector; /** @@ -54,22 +57,50 @@ import java.util.Vector; */ final class VMNetworkInterface { + String name; + Set addresses; + + VMNetworkInterface(String name) + { + this.name = name; + addresses = new HashSet(); + } + static - { - if (Configuration.INIT_LOAD_LIBRARY) - System.loadLibrary("javanet"); - } + { + if (Configuration.INIT_LOAD_LIBRARY) + System.loadLibrary("javanet"); + + initIds(); + } + + private static native void initIds(); /** - * Returns a Vector of InetAddresses. The returned value will be - * 'condensed', meaning that all elements with the same interface - * name will be collapesed into one InetAddress for that name - * containing all addresses before the returning the result to the - * user. This means the native method can be implemented in a naive - * way mapping each address/interface to a name even if that means - * that the Vector contains multiple InetAddresses with the same - * interface name. + * Return a list of VM network interface objects. + * + * @return The list of network interfaces. + * @throws SocketException */ - public static native Vector getInterfaces() + public static native VMNetworkInterface[] getVMInterfaces() throws SocketException; + + private void addAddress(ByteBuffer addr) + throws SocketException, UnknownHostException + { + if (addr.remaining() == 4) + { + byte[] ipv4 = new byte[4]; + addr.get(ipv4); + addresses.add(Inet4Address.getByAddress(ipv4)); + } + else if (addr.remaining() == 16) + { + byte[] ipv6 = new byte[16]; + addr.get(ipv6); + addresses.add(Inet6Address.getByAddress(ipv6)); + } + else + throw new SocketException("invalid interface address"); + } } |