Search in sources :

Example 46 with InterfaceAddress

use of java.net.InterfaceAddress in project cxf by apache.

the class WSDiscoveryClientTest method findIpv4Interface.

static NetworkInterface findIpv4Interface() throws Exception {
    Enumeration<NetworkInterface> ifcs = NetworkInterface.getNetworkInterfaces();
    List<NetworkInterface> possibles = new ArrayList<>();
    while (ifcs.hasMoreElements()) {
        NetworkInterface ni = ifcs.nextElement();
        if (ni.supportsMulticast() && ni.isUp()) {
            for (InterfaceAddress ia : ni.getInterfaceAddresses()) {
                if (ia.getAddress() instanceof java.net.Inet4Address && !ia.getAddress().isLoopbackAddress() && !ni.getDisplayName().startsWith("vnic")) {
                    possibles.add(ni);
                }
            }
        }
    }
    return possibles.isEmpty() ? null : possibles.get(possibles.size() - 1);
}
Also used : InterfaceAddress(java.net.InterfaceAddress) ArrayList(java.util.ArrayList) NetworkInterface(java.net.NetworkInterface)

Aggregations

InterfaceAddress (java.net.InterfaceAddress)46 NetworkInterface (java.net.NetworkInterface)36 InetAddress (java.net.InetAddress)28 Inet4Address (java.net.Inet4Address)17 SocketException (java.net.SocketException)11 ArrayList (java.util.ArrayList)11 Command (com.android.server.NativeDaemonConnector.Command)6 IOException (java.io.IOException)6 UnknownHostException (java.net.UnknownHostException)6 LinkAddress (android.net.LinkAddress)5 List (java.util.List)4 SharedPreferences (android.content.SharedPreferences)3 DatagramPacket (java.net.DatagramPacket)3 Enumeration (java.util.Enumeration)3 Configuration (android.content.res.Configuration)2 Paint (android.graphics.Paint)2 ConnectivityManager (android.net.ConnectivityManager)2 Network (android.net.Network)2 NetworkInfo (android.net.NetworkInfo)2 SpannableString (android.text.SpannableString)2