@Test public void shouldContainIps48through63() throws Exception { int i; String ipStr; IPv4Cidr cidr = new IPv4Cidr("192.168.3.48/28"); assertFalse(cidr.contains("192.168.3.47")); for(i=48;i<=63;i++){ ipStr = String.format("192.168.3.%d",i); } assertFalse(cidr.contains("192.168.3.64")); }
public boolean contains(String ip) throws IPStringConversionException, IpTypeMissMatchException { boolean out; if(!IPUtils.isValidIpv4String(ip)) { return false; } byte[] theirBytes = new IPv4(ip).getBytes(); byte[] mySubnet = IPUtils.opBytes(ipBytes, maskBytes, ByteStreamOperation.AND); byte[] theirSubnet = IPUtils.opBytes(theirBytes, maskBytes, ByteStreamOperation.AND); out = IPUtils.bytesEqual(theirSubnet, mySubnet); return out; }
IPv4Cidr { public boolean contains(String ip) throws IPStringConversionException, IpTypeMissMatchException { boolean out; if(!IPUtils.isValidIpv4String(ip)) { return false; } byte[] theirBytes = new IPv4(ip).getBytes(); byte[] mySubnet = IPUtils.opBytes(ipBytes, maskBytes, ByteStreamOperation.AND); byte[] theirSubnet = IPUtils.opBytes(theirBytes, maskBytes, ByteStreamOperation.AND); out = IPUtils.bytesEqual(theirSubnet, mySubnet); return out; } }
IPv4Cidr { public boolean contains(String ip) throws IPStringConversionException, IpTypeMissMatchException { boolean out; if(!IPUtils.isValidIpv4String(ip)) { return false; } byte[] theirBytes = new IPv4(ip).getBytes(); byte[] mySubnet = IPUtils.opBytes(ipBytes, maskBytes, ByteStreamOperation.AND); byte[] theirSubnet = IPUtils.opBytes(theirBytes, maskBytes, ByteStreamOperation.AND); out = IPUtils.bytesEqual(theirSubnet, mySubnet); return out; } IPv4Cidr();  IPv4Cidr(String cidr); }
IPv4Cidr { public boolean contains(String ip) throws IPStringConversionException, IpTypeMissMatchException { boolean out; if(!IPUtils.isValidIpv4String(ip)) { return false; } byte[] theirBytes = new IPv4(ip).getBytes(); byte[] mySubnet = IPUtils.opBytes(ipBytes, maskBytes, ByteStreamOperation.AND); byte[] theirSubnet = IPUtils.opBytes(theirBytes, maskBytes, ByteStreamOperation.AND); out = IPUtils.bytesEqual(theirSubnet, mySubnet); return out; } IPv4Cidr();  IPv4Cidr(String cidr); void setCidr(String in); boolean contains(String ip); String getCidr(); String getIp(); int getSubnet(); byte[] getIpBytes(); byte[] getMaskBytes(); }
IPv4Cidr { public boolean contains(String ip) throws IPStringConversionException, IpTypeMissMatchException { boolean out; if(!IPUtils.isValidIpv4String(ip)) { return false; } byte[] theirBytes = new IPv4(ip).getBytes(); byte[] mySubnet = IPUtils.opBytes(ipBytes, maskBytes, ByteStreamOperation.AND); byte[] theirSubnet = IPUtils.opBytes(theirBytes, maskBytes, ByteStreamOperation.AND); out = IPUtils.bytesEqual(theirSubnet, mySubnet); return out; } IPv4Cidr();  IPv4Cidr(String cidr); void setCidr(String in); boolean contains(String ip); String getCidr(); String getIp(); int getSubnet(); byte[] getIpBytes(); byte[] getMaskBytes();  }