// if there is more than one network interface then check that
// we can join on specific interfaces and that we only receive
// if data is received on that interface
if (atLeastTwoInterfaces) {
// set up server on first interfaces
NetworkInterface loopbackInterface = NetworkInterface
.getByInetAddress(InetAddress.getByName("127.0.0.1"));
theInterfaces = NetworkInterface.getNetworkInterfaces();
while (theInterfaces.hasMoreElements()) {
NetworkInterface thisInterface = (NetworkInterface) theInterfaces
.nextElement();
if ((thisInterface.getInetAddresses() != null && thisInterface
.getInetAddresses().hasMoreElements())
&& (Support_NetworkInterface
.useInterface(thisInterface) == true)) {
// get the first address on the interface
// start server which is joined to the group and has
// only asked for packets on this interface
Enumeration addresses = thisInterface
.getInetAddresses();
NetworkInterface sendingInterface = null;
boolean isLoopback = false;
if (addresses != null) {
InetAddress firstAddress = (InetAddress) addresses
.nextElement();
if (firstAddress.isLoopbackAddress()) {
isLoopback = true;
}
if (firstAddress instanceof Inet4Address) {
group = InetAddress.getByName("224.0.0.4");
if (networkInterface1.equals(NetworkInterface
.getByInetAddress(InetAddress
.getByName("127.0.0.1")))) {
sendingInterface = networkInterface2;
} else {
sendingInterface = networkInterface1;
}
} else {
// if this interface only seems to support
// IPV6 addresses
group = InetAddress
.getByName("FF01:0:0:0:0:0:2:8001");
sendingInterface = IPV6networkInterface1;
}
}
InetAddress useAddress = null;
addresses = sendingInterface.getInetAddresses();
if ((addresses != null)
&& (addresses.hasMoreElements())) {
useAddress = (InetAddress) addresses.nextElement();
}