diff options
Diffstat (limited to 'src/com/isode/stroke/network/NetworkInterface.java')
-rw-r--r-- | src/com/isode/stroke/network/NetworkInterface.java | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/src/com/isode/stroke/network/NetworkInterface.java b/src/com/isode/stroke/network/NetworkInterface.java index 5590837..1bffafc 100644 --- a/src/com/isode/stroke/network/NetworkInterface.java +++ b/src/com/isode/stroke/network/NetworkInterface.java @@ -4,7 +4,7 @@ * See Documentation/Licenses/BSD-simplified.txt for more information. */ /* - * Copyright (c) 2015 Isode Limited. + * Copyright (c) 2015-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -16,6 +16,9 @@ package com.isode.stroke.network; +import java.net.InetAddress; +import java.net.SocketException; +import java.util.Enumeration; import java.util.Vector; public class NetworkInterface { @@ -28,6 +31,25 @@ public class NetworkInterface { this.name = name; this.loopback = loopback; } + + /** + * Creates a {@link NetworkInterface} from a {@link java.net.NetworkInterface} including + * all addresses in the {@link java.net.NetworkInterface} + * @param javaNI The {@link java.net.NetworkInterface} to create the {@link NetworkInterface} + * from, should not be {@code null}. + * @throws SocketException If an I/O error occurs when trying to determine if it is + * a loop back interface. + */ + public NetworkInterface(java.net.NetworkInterface javaNI) throws SocketException { + this.name = javaNI.getName(); + this.loopback = javaNI.isLoopback(); + Enumeration<InetAddress> addressEnumeration = javaNI.getInetAddresses(); + while (addressEnumeration.hasMoreElements()) { + InetAddress inetAddress = addressEnumeration.nextElement(); + HostAddress hostAddress = new HostAddress(inetAddress); + addAddress(hostAddress); + } + } public void addAddress(final HostAddress address) { addresses.add(address); |