summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Clayton <alex.clayton@isode.com>2016-02-22 16:05:37 (GMT)
committerAlex Clayton <alex.clayton@isode.com>2016-02-29 12:10:44 (GMT)
commitd636d68c84229c82ff746c7697d2014ff4dd4477 (patch)
treea534ffdb9696c68d21d1cec6624023795ef683d7 /src/com/isode/stroke/network/NetworkInterface.java
parent2de569d23468c94fdcf1adc336a580b053423fd7 (diff)
downloadstroke-d636d68c84229c82ff746c7697d2014ff4dd4477.zip
stroke-d636d68c84229c82ff746c7697d2014ff4dd4477.tar.bz2
Finish porting on Network Package
As per PortingProgress.txt finsh porting all the classes I can from the network package. This involved some updates as the tests and code had changed since they existing classes had been imported. I have added notes for the classes I did not port in PortingProgress explaining why they were not ported. Test-information: All unit tests pass. Change-Id: Ibb52ae409f1da9b72a4c1e590cd22835a1be95eb
Diffstat (limited to 'src/com/isode/stroke/network/NetworkInterface.java')
-rw-r--r--src/com/isode/stroke/network/NetworkInterface.java24
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);