Search in sources :

Example 41 with InterfaceAddress

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));
}
Also used : InterfaceAddress(java.net.InterfaceAddress) NotifyListener(net.mm2d.upnp.SsdpNotifyReceiver.NotifyListener) Test(org.junit.Test)

Example 42 with InterfaceAddress

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));
        }
    }
}
Also used : InterfaceAddress(java.net.InterfaceAddress) InetAddress(java.net.InetAddress)

Example 43 with InterfaceAddress

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;
}
Also used : InterfaceAddress(java.net.InterfaceAddress) InetSocketAddress(java.net.InetSocketAddress) NetworkInterface(java.net.NetworkInterface) InetAddress(java.net.InetAddress)

Example 44 with InterfaceAddress

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;
}
Also used : InterfaceAddress(java.net.InterfaceAddress) InetSocketAddress(java.net.InetSocketAddress) NetworkInterface(java.net.NetworkInterface) InetAddress(java.net.InetAddress) NaRPCServerEndpoint(com.ibm.narpc.NaRPCServerEndpoint)

Example 45 with InterfaceAddress

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);
    }
}
Also used : InterfaceAddress(java.net.InterfaceAddress) NetworkInterface(java.net.NetworkInterface) ND4JIllegalStateException(org.nd4j.linalg.exception.ND4JIllegalStateException)

Aggregations

InterfaceAddress (java.net.InterfaceAddress)94 NetworkInterface (java.net.NetworkInterface)63 InetAddress (java.net.InetAddress)52 Inet4Address (java.net.Inet4Address)26 SocketException (java.net.SocketException)24 Test (org.junit.Test)19 ArrayList (java.util.ArrayList)15 IOException (java.io.IOException)9 UnknownHostException (java.net.UnknownHostException)7 NotifyListener (net.mm2d.upnp.SsdpNotifyReceiver.NotifyListener)7 Command (com.android.server.NativeDaemonConnector.Command)6 Inet6Address (java.net.Inet6Address)6 LinkAddress (android.net.LinkAddress)5 DatagramPacket (java.net.DatagramPacket)5 InetSocketAddress (java.net.InetSocketAddress)4 List (java.util.List)4 SharedPreferences (android.content.SharedPreferences)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 Enumeration (java.util.Enumeration)3 LinkedList (java.util.LinkedList)3