summaryrefslogtreecommitdiffstats
blob: 0113c57d340c0bbd0ffbae5681e1ebe0e15f3f2a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*  Copyright (c) 2016, Isode Limited, London, England.
 *  All rights reserved.
 *
 *  Acquisition and use of this software and related materials for any
 *  purpose requires a written license agreement from Isode Limited,
 *  or a written license from an organisation licensed by Isode Limited
 *  to grant such a license.
 *
 */
package com.isode.stroke.network;

import java.net.SocketException;
import java.util.Enumeration;
import java.util.Vector;
import java.util.logging.Logger;

/**
 * Java implementation of {@link NetworkEnvironment}
 */
public class JavaNetworkEnviroment extends NetworkEnvironment {

    /**
     * Logger
     */
    private final Logger logger = Logger.getLogger(this.getClass().getName());
    
    @Override
    public Vector<NetworkInterface> getNetworkInterfaces() {
        Vector<NetworkInterface> results = new Vector<NetworkInterface>();
        try {
            Enumeration<java.net.NetworkInterface> javaNIEnumeration = 
                    java.net.NetworkInterface.getNetworkInterfaces();
            if (javaNIEnumeration.hasMoreElements()) {
                java.net.NetworkInterface javaNI = javaNIEnumeration.nextElement();
                try {
                    NetworkInterface strokeNI = new NetworkInterface(javaNI);
                    results.add(strokeNI);
                } catch (SocketException e) {
                    logger.warning("Error determining if "+javaNI+
                            " is loopback : "+e.getMessage());
                }
                
            }
        } 
        catch (SocketException e) {
            logger.warning("Error occured when getting network interfaces - "+e.getMessage());
        }
        return results;
    }

}