Пример #1
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();
 }
Пример #2
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);
 }