Clover Coverage Report - JmDNS 3.4.1
Coverage timestamp: Thu Aug 25 2011 13:06:33 CEST
../../../img/srcFileCovDistChart0.png 77% of files have more coverage
36   132   20   7.2
18   87   0.56   5
5     4  
1    
 
  NetworkTopologyDiscoveryImpl       Line # 23 36 0% 20 59 0% 0.0
 
No Tests
 
1    /**
2    *
3    */
4    package javax.jmdns.impl;
5   
6    import java.lang.reflect.Method;
7    import java.net.InetAddress;
8    import java.net.NetworkInterface;
9    import java.net.SocketException;
10    import java.util.Enumeration;
11    import java.util.HashSet;
12    import java.util.Set;
13    import java.util.logging.Level;
14    import java.util.logging.Logger;
15   
16    import javax.jmdns.NetworkTopologyDiscovery;
17   
18    /**
19    * This class implements NetworkTopologyDiscovery.
20    *
21    * @author Pierre Frisch
22    */
 
23    public class NetworkTopologyDiscoveryImpl implements NetworkTopologyDiscovery {
24    private final static Logger logger = Logger.getLogger(NetworkTopologyDiscoveryImpl.class.getName());
25   
26    private final Method _isUp;
27   
28    private final Method _supportsMulticast;
29   
30    /**
31    *
32    */
 
33  0 toggle public NetworkTopologyDiscoveryImpl() {
34  0 super();
35  0 Method isUp;
36  0 try {
37  0 isUp = NetworkInterface.class.getMethod("isUp", (Class<?>[]) null);
38    } catch (Exception exception) {
39    // We do not want to throw anything if the method does not exist.
40  0 isUp = null;
41    }
42  0 _isUp = isUp;
43  0 Method supportsMulticast;
44  0 try {
45  0 supportsMulticast = NetworkInterface.class.getMethod("supportsMulticast", (Class<?>[]) null);
46    } catch (Exception exception) {
47    // We do not want to throw anything if the method does not exist.
48  0 supportsMulticast = null;
49    }
50  0 _supportsMulticast = supportsMulticast;
51    }
52   
53    /*
54    * (non-Javadoc)
55    * @see javax.jmdns.JmmDNS.NetworkTopologyDiscovery#getInetAddresses()
56    */
 
57  0 toggle @Override
58    public InetAddress[] getInetAddresses() {
59  0 Set<InetAddress> result = new HashSet<InetAddress>();
60  0 try {
61   
62  0 for (Enumeration<NetworkInterface> nifs = NetworkInterface.getNetworkInterfaces(); nifs.hasMoreElements();) {
63  0 NetworkInterface nif = nifs.nextElement();
64  0 for (Enumeration<InetAddress> iaenum = nif.getInetAddresses(); iaenum.hasMoreElements();) {
65  0 InetAddress interfaceAddress = iaenum.nextElement();
66  0 if (logger.isLoggable(Level.FINEST)) {
67  0 logger.finest("Found NetworkInterface/InetAddress: " + nif + " -- " + interfaceAddress);
68    }
69  0 if (this.useInetAddress(nif, interfaceAddress)) {
70  0 result.add(interfaceAddress);
71    }
72    }
73    }
74    } catch (SocketException se) {
75  0 logger.warning("Error while fetching network interfaces addresses: " + se);
76    }
77  0 return result.toArray(new InetAddress[result.size()]);
78    }
79   
80    /*
81    * (non-Javadoc)
82    * @see javax.jmdns.JmmDNS.NetworkTopologyDiscovery#useInetAddress(java.net.NetworkInterface, java.net.InetAddress)
83    */
 
84  0 toggle @Override
85    public boolean useInetAddress(NetworkInterface networkInterface, InetAddress interfaceAddress) {
86  0 try {
87  0 if (_isUp != null) {
88  0 try {
89  0 if (!((Boolean) _isUp.invoke(networkInterface, (Object[]) null)).booleanValue()) {
90  0 return false;
91    }
92    } catch (Exception exception) {
93    // We should hide that exception.
94    }
95    }
96  0 if (_supportsMulticast != null) {
97  0 try {
98  0 if (!((Boolean) _supportsMulticast.invoke(networkInterface, (Object[]) null)).booleanValue()) {
99  0 return false;
100    }
101    } catch (Exception exception) {
102    // We should hide that exception.
103    }
104    }
105  0 if (interfaceAddress.isLoopbackAddress()) {
106  0 return false;
107    }
108  0 return true;
109    } catch (Exception exception) {
110  0 return false;
111    }
112    }
113   
114    /*
115    * (non-Javadoc)
116    * @see javax.jmdns.NetworkTopologyDiscovery#lockInetAddress(java.net.InetAddress)
117    */
 
118  0 toggle @Override
119    public void lockInetAddress(InetAddress interfaceAddress) {
120    // Default implementation does nothing.
121    }
122   
123    /*
124    * (non-Javadoc)
125    * @see javax.jmdns.NetworkTopologyDiscovery#unlockInetAddress(java.net.InetAddress)
126    */
 
127  0 toggle @Override
128    public void unlockInetAddress(InetAddress interfaceAddress) {
129    // Default implementation does nothing.
130    }
131   
132    }