use of java.net.InterfaceAddress in project mmupnp by ohmae.
the class SsdpNotifyReceiverTest method onReceive_同一セグメントからのメッセージは通知する.
@Test
public void onReceive_同一セグメントからのメッセージは通知する() throws Exception {
final SsdpNotifyReceiver receiver = spy(new SsdpNotifyReceiver(Address.IP_V4, NetworkUtils.getAvailableInet4Interfaces().get(0)));
final InterfaceAddress address = TestUtils.createInterfaceAddress("192.0.2.1", "255.255.0.0", 24);
doReturn(address).when(receiver).getInterfaceAddress();
final NotifyListener listener = mock(NotifyListener.class);
receiver.setNotifyListener(listener);
final byte[] data = TestUtils.getResourceAsByteArray("ssdp-notify-alive0.bin");
receiver.onReceive(InetAddress.getByName("192.0.2.2"), data, data.length);
verify(listener).onReceiveNotify(ArgumentMatchers.any(SsdpRequest.class));
}
use of java.net.InterfaceAddress in project moleculer-java by moleculer-java.
the class UDPLocator method startReceivers.
protected void startReceivers(NetworkInterface ni, String udpMulticast, boolean udpBroadcast) throws Exception {
if (ni == null || ni.isLoopback()) {
return;
}
List<InterfaceAddress> list = ni.getInterfaceAddresses();
if (list == null || list.isEmpty()) {
return;
}
if (udpMulticast != null && ni.supportsMulticast()) {
// Create multicast receiver
receivers.add(new UDPMulticastReceiver(nodeID, udpMulticast, transporter, ni));
}
if (udpBroadcast) {
for (InterfaceAddress ia : list) {
if (ia == null) {
continue;
}
InetAddress address = ia.getBroadcast();
if (address == null || address.isLoopbackAddress()) {
continue;
}
String udpAddress = address.getHostAddress();
if (udpAddress == null || udpAddress.isEmpty() || udpAddress.startsWith("127.")) {
continue;
}
// Create broadcast receiver
receivers.add(new UDPBroadcastReceiver(nodeID, udpAddress, transporter));
}
}
}
use of java.net.InterfaceAddress in project incubator-crail by apache.
the class RdmaStorageServer method getDataNodeAddress.
public static InetSocketAddress getDataNodeAddress() throws IOException {
String ifname = RdmaConstants.STORAGE_RDMA_INTERFACE;
int port = RdmaConstants.STORAGE_RDMA_PORT;
NetworkInterface netif = NetworkInterface.getByName(ifname);
if (netif == null) {
return null;
}
List<InterfaceAddress> addresses = netif.getInterfaceAddresses();
InetAddress addr = null;
for (InterfaceAddress address : addresses) {
// LOG.info("address* " + address.toString() + ", _addr " + _addr.toString() + ", isSiteLocal " + _addr.isSiteLocalAddress() + ", tmp " + tmp + ", size " + tmp.length + ", broadcast " + address.getBroadcast());
if (address.getBroadcast() != null) {
InetAddress _addr = address.getAddress();
addr = _addr;
}
}
InetSocketAddress inetAddr = new InetSocketAddress(addr, port);
return inetAddr;
}
use of java.net.InterfaceAddress in project incubator-crail by apache.
the class TcpStorageServer method getDataNodeAddress.
public static InetSocketAddress getDataNodeAddress() throws IOException {
String ifname = TcpStorageConstants.STORAGE_TCP_INTERFACE;
int port = TcpStorageConstants.STORAGE_TCP_PORT;
NetworkInterface netif = NetworkInterface.getByName(ifname);
if (netif == null) {
return null;
}
List<InterfaceAddress> addresses = netif.getInterfaceAddresses();
InetAddress addr = null;
for (InterfaceAddress address : addresses) {
if (address.getBroadcast() != null) {
InetAddress _addr = address.getAddress();
addr = _addr;
}
}
InetSocketAddress inetAddr = new InetSocketAddress(addr, port);
return inetAddr;
}
use of java.net.InterfaceAddress in project nd4j by deeplearning4j.
the class VoidParameterServer method getLocalAddresses.
/**
* This method returns set of local IP addresses available in system.
*
* PLEASE NOTE: loopback, disabled interfaces, IPv6 addresses are ignored here.
*
* @return
*/
public static Set<String> getLocalAddresses() {
try {
List<NetworkInterface> interfaces = Collections.list(NetworkInterface.getNetworkInterfaces());
Set<String> result = new HashSet<>();
for (NetworkInterface networkInterface : interfaces) {
if (networkInterface.isLoopback() || !networkInterface.isUp())
continue;
for (InterfaceAddress address : networkInterface.getInterfaceAddresses()) {
String addr = address.getAddress().getHostAddress();
if (addr == null || addr.isEmpty() || addr.contains(":"))
continue;
result.add(addr);
}
}
return result;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Aggregations