Skip to content
Snippets Groups Projects
Commit db2fdc66 authored by terry-norbraten's avatar terry-norbraten
Browse files

strengthen the findIp4Interface search criteria

parent db5eee01
No related branches found
No related tags found
No related merge requests found
...@@ -327,32 +327,34 @@ public class DisThreadedNetIF ...@@ -327,32 +327,34 @@ public class DisThreadedNetIF
catch (InterruptedException ex) {} catch (InterruptedException ex) {}
} }
/** Find proper interface /**
* @return a network interface to use to join a multicast group * Find proper interface
*/ *
public static NetworkInterface findIp4Interface() * @return a network interface to use to join a multicast group
{ */
Enumeration<NetworkInterface> ifaces = null; public static NetworkInterface findIp4Interface() {
try { try {
ifaces = NetworkInterface.getNetworkInterfaces(); Enumeration<NetworkInterface> ifaces = NetworkInterface.getNetworkInterfaces();
} catch (SocketException ex) { NetworkInterface nif;
Logger.getLogger(DisThreadedNetIF.class.getName()).log(Level.SEVERE, null, ex); Enumeration<InetAddress> addresses;
} InetAddress addr;
NetworkInterface nif;
Enumeration<InetAddress> addresses; while (ifaces != null && ifaces.hasMoreElements()) {
InetAddress addr; nif = ifaces.nextElement();
if (nif.isUp()) {
while (ifaces != null && ifaces.hasMoreElements()) { addresses = nif.getInetAddresses();
nif = ifaces.nextElement(); while (addresses.hasMoreElements()) {
addresses = nif.getInetAddresses(); addr = addresses.nextElement();
while (addresses.hasMoreElements()) { if (addr instanceof Inet4Address && !addr.isLoopbackAddress() && !addr.isLinkLocalAddress()) {
addr = addresses.nextElement(); System.out.println("Using network interface " + nif.getDisplayName());
if (addr instanceof Inet4Address && !addr.isLoopbackAddress()) { return nif;
System.out.println("Using network interface " + nif.getDisplayName()); }
return nif; }
}
}
} catch (SocketException ex) {
Logger.getLogger(DisThreadedNetIF.class.getName()).log(Level.SEVERE, null, ex);
} }
} return null;
} }
return null;
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment