Exemplo n.º 1
0
 public static InetAddress determineBindAddress(InetAddress destAddress) {
   ArrayList<InetAddress> removeIPv6Addresses =
       Network.removeIPv6Addresses(Network.removeLoopbackAddresses(Network.getLocalIpAddresses()));
   for (InetAddress removeIPv6Address : removeIPv6Addresses) {
     InetAddress inetAddress = null;
     try {
       Enumeration inetAddresses =
           NetworkInterface.getByInetAddress(removeIPv6Address).getInetAddresses();
       while (inetAddresses.hasMoreElements()) {
         inetAddress = (InetAddress) inetAddresses.nextElement();
         if (inetAddress.equals(destAddress)) {
           return inetAddress;
         }
       }
     } catch (SocketException e) {
       if (inetAddress != null) {
         RobotLog.v(
             String.format(
                 "socket exception while trying to get network interface of %s",
                 inetAddress.getHostAddress()));
       } else {
         RobotLog.v("exception while trying to get remote address");
       }
     }
   }
   return determineBindAddressBasedOnWifiP2pSubnet(removeIPv6Addresses, destAddress);
 }
Exemplo n.º 2
0
 public static InetAddress determineBindAddressBasedOnWifiP2pSubnet(
     ArrayList<InetAddress> localIpAddresses, InetAddress destAddress) {
   int byteArrayToInt = TypeConversion.byteArrayToInt(destAddress.getAddress());
   for (InetAddress inetAddress : localIpAddresses) {
     if ((TypeConversion.byteArrayToInt(inetAddress.getAddress()) & WIFI_P2P_SUBNET_MASK)
         == (byteArrayToInt & WIFI_P2P_SUBNET_MASK)) {
       return inetAddress;
     }
   }
   return Network.getLoopbackAddress();
 }
Exemplo n.º 3
0
 public static InetAddress determineBindAddressBasedOnWifiP2pSubnet(
     ArrayList<InetAddress> localIpAddresses, InetAddress destAddress) {
   int byteArrayToInt = TypeConversion.byteArrayToInt(destAddress.getAddress());
   Iterator it = localIpAddresses.iterator();
   while (it.hasNext()) {
     InetAddress inetAddress = (InetAddress) it.next();
     if ((TypeConversion.byteArrayToInt(inetAddress.getAddress()) & WIFI_P2P_SUBNET_MASK)
         == (byteArrayToInt & WIFI_P2P_SUBNET_MASK)) {
       return inetAddress;
     }
   }
   return Network.getLoopbackAddress();
 }
Exemplo n.º 4
0
 public static InetAddress determineBindAddress(InetAddress destAddress) {
   ArrayList removeIPv6Addresses =
       Network.removeIPv6Addresses(Network.removeLoopbackAddresses(Network.getLocalIpAddresses()));
   Iterator it = removeIPv6Addresses.iterator();
   while (it.hasNext()) {
     try {
       Enumeration inetAddresses =
           NetworkInterface.getByInetAddress((InetAddress) it.next()).getInetAddresses();
       while (inetAddresses.hasMoreElements()) {
         InetAddress inetAddress = (InetAddress) inetAddresses.nextElement();
         if (inetAddress.equals(destAddress)) {
           return inetAddress;
         }
       }
       continue;
     } catch (SocketException e) {
       RobotLog.m254v(
           String.format(
               "socket exception while trying to get network interface of %s",
               new Object[] {r0.getHostAddress()}));
     }
   }
   return determineBindAddressBasedOnWifiP2pSubnet(removeIPv6Addresses, destAddress);
 }
Exemplo n.º 5
0
 public static InetAddress determineBindAddressBasedOnIsReachable(
     ArrayList<InetAddress> localIpAddresses, InetAddress destAddress) {
   for (InetAddress inetAddress : localIpAddresses) {
     try {
       if (inetAddress.isReachable(NetworkInterface.getByInetAddress(inetAddress), TTL, TIMEOUT)) {
         return inetAddress;
       }
     } catch (SocketException e) {
       RobotLog.v(
           String.format(
               "socket exception while trying to get network interface of %s",
               inetAddress.getHostAddress()));
     } catch (IOException e2) {
       RobotLog.v(
           String.format(
               "IO exception while trying to determine if %s is reachable via %s",
               destAddress.getHostAddress(), inetAddress.getHostAddress()));
     }
   }
   return Network.getLoopbackAddress();
 }
Exemplo n.º 6
0
 public static InetAddress determineBindAddressBasedOnIsReachable(
     ArrayList<InetAddress> localIpAddresses, InetAddress destAddress) {
   Iterator it = localIpAddresses.iterator();
   while (it.hasNext()) {
     InetAddress inetAddress = (InetAddress) it.next();
     try {
       if (inetAddress.isReachable(NetworkInterface.getByInetAddress(inetAddress), TTL, TIMEOUT)) {
         return inetAddress;
       }
     } catch (SocketException e) {
       RobotLog.m254v(
           String.format(
               "socket exception while trying to get network interface of %s",
               new Object[] {inetAddress.getHostAddress()}));
     } catch (IOException e2) {
       RobotLog.m254v(
           String.format(
               "IO exception while trying to determine if %s is reachable via %s",
               new Object[] {destAddress.getHostAddress(), inetAddress.getHostAddress()}));
     }
   }
   return Network.getLoopbackAddress();
 }