@Test public void checkRange_start_end() { String start = "192.168.5.5"; String end = "192.168.5.25"; boolean check1 = IPUtils.isValidRange(start, end, "192.168.5.21"); Assert.assertTrue(check1); boolean check2 = IPUtils.isValidRange(start, end, "192.168.5.45"); Assert.assertFalse(check2); }
@Test public void checkRange_mask_31() { String ipWithMask = "192.168.100.1/24"; boolean allowed1 = IPUtils.isValidRange(ipWithMask, "192.168.100.1"); Assert.assertTrue(allowed1); boolean notAllowed1 = IPUtils.isValidRange(ipWithMask, "192.168.99.255"); Assert.assertFalse(notAllowed1); boolean notAllowed2 = IPUtils.isValidRange(ipWithMask, "192.168.101.1"); Assert.assertFalse(notAllowed2); boolean notAllowed3 = IPUtils.isValidRange(ipWithMask, "212.34.100.0"); Assert.assertFalse(notAllowed3); }
@Override public void execute() throws IOException { boolean dvChanged = true; String key = IPUtils.getUniqueKey(senderIP, senderPort); Neighbor neighbor = DVState.getNeighbors().get(key); if (neighbor == null) { System.err.println(Constants.NO_NEIGHBOUR); return; } if (neighbor != null) { synchronized (neighbor.getLock()) { neighbor.setLinkUp(); DVState.addDVTask(neighbor); DVState.addTimeoutTask(neighbor); } } // Update my distance vector for this node DVEntry entry = DVState.getDistanceVector().get(key); entry.setCost(neighbor.getCost()); entry.setNeighbor(neighbor); if (!received) DVSenderUtil.sendLinkUpMessage(neighbor); // Re-calculate the distance vector dvChanged = DVState.computeDistanceVector(neighbor); // If distance vector changes, send an update to all if (dvChanged) { DVSenderUtil.sendVectorToAllNeighbors(); } }
public static String getWifiIPv4Address(final Context pContext) throws WifiUtilsException { try { return IPUtils.ipAddressToString(WifiUtils.getWifiIPv4AddressRaw(pContext)); } catch (final UnknownHostException e) { throw new WifiUtilsException("Unexpected error!", e); } }
public static String getEmulatorIPAddress() throws WifiUtilsException { try { return IPUtils.ipAddressToString(WifiUtils.getEmulatorIPAddressRaw()); } catch (final UnknownHostException e) { throw new WifiUtilsException("Unexpected error!", e); } }
public static byte[] getWifiIPv4AddressRaw(final Context pContext) { return IPUtils.ipv4AddressToIPAddress( WifiUtils.getWifiManager(pContext).getConnectionInfo().getIpAddress()); }