Ejemplo 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);
 }
Ejemplo n.º 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);
 }