}
return binding;
}
private static NetworkInterfaceBinding resolveInterface(final OverallInterfaceCriteria criteria) throws SocketException {
NetworkInterfaceBinding result = null;
final Map<NetworkInterface, Set<InetAddress>> candidates = new HashMap<NetworkInterface, Set<InetAddress>>();
final Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
while (networkInterfaces.hasMoreElements()) {
storeAddresses(networkInterfaces.nextElement(), candidates);
}
Map<NetworkInterface, Set<InetAddress>> acceptable = criteria.getAcceptableAddresses(candidates);
if (acceptable.size() == 1 && acceptable.values().iterator().next().size() == 1) {
// single result
Map.Entry<NetworkInterface, Set<InetAddress>> entry = acceptable.entrySet().iterator().next();
InetAddress addr = entry.getValue().iterator().next();
result = new NetworkInterfaceBinding(Collections.singleton(entry.getKey()), addr);
}
return result;
}