| 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 |
|
|
| 20 |
|
|
| 21 |
|
@author |
| 22 |
|
|
|
|
|
| 0% |
Uncovered Elements: 59 (59) |
Complexity: 20 |
Complexity Density: 0.56 |
|
| 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 |
|
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 3 |
Complexity Density: 0.27 |
|
| 33 |
0
|
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 |
|
|
| 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 |
|
|
| 48 |
0
|
supportsMulticast = null; |
| 49 |
|
} |
| 50 |
0
|
_supportsMulticast = supportsMulticast; |
| 51 |
|
} |
| 52 |
|
|
| 53 |
|
|
| 54 |
|
|
| 55 |
|
@see |
| 56 |
|
|
|
|
|
| 0% |
Uncovered Elements: 20 (20) |
Complexity: 6 |
Complexity Density: 0.5 |
|
| 57 |
0
|
@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 |
|
|
| 82 |
|
@see |
| 83 |
|
|
|
|
|
| 0% |
Uncovered Elements: 23 (23) |
Complexity: 9 |
Complexity Density: 0.69 |
|
| 84 |
0
|
@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 |
|
|
| 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 |
|
|
| 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 |
|
|
| 116 |
|
@see |
| 117 |
|
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 118 |
0
|
@Override... |
| 119 |
|
public void lockInetAddress(InetAddress interfaceAddress) { |
| 120 |
|
|
| 121 |
|
} |
| 122 |
|
|
| 123 |
|
|
| 124 |
|
|
| 125 |
|
@see |
| 126 |
|
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 127 |
0
|
@Override... |
| 128 |
|
public void unlockInetAddress(InetAddress interfaceAddress) { |
| 129 |
|
|
| 130 |
|
} |
| 131 |
|
|
| 132 |
|
} |