@Test public void testSubnet() { Cidr c = new Cidr("0.0.0.0/0"); Cidr c10 = c.subnet(10); Assert.assertEquals(c10, new Cidr(10)); Assert.assertEquals(c10.subnet(88, 1), new Cidr(10, 88, 1)); }
public Cidr subnet(int ...extraUnsignedBytes) { if ((length%8)!=0) throw new IllegalStateException("subnet can only be used for byte boundary subnetted CIDR's; not "+this); int[] newBytes = getBytes(); int newLen = this.length + extraUnsignedBytes.length*8; if (newLen>32) throw new IllegalStateException("further subnet for "+Arrays.toString(extraUnsignedBytes)+" not possible on CIDR "+this); for (int i=0; i<extraUnsignedBytes.length; i++) { newBytes[this.length/8 + i] = extraUnsignedBytes[i]; } return new Cidr(newBytes, newLen); }
Cidr implements Serializable { public Cidr subnet(int ...extraUnsignedBytes) { if ((length%8)!=0) throw new IllegalStateException("subnet can only be used for byte boundary subnetted CIDR's; not "+this); int[] newBytes = getBytes(); int newLen = this.length + extraUnsignedBytes.length*8; if (newLen>32) throw new IllegalStateException("further subnet for "+Arrays.toString(extraUnsignedBytes)+" not possible on CIDR "+this); for (int i=0; i<extraUnsignedBytes.length; i++) { newBytes[this.length/8 + i] = extraUnsignedBytes[i]; } return new Cidr(newBytes, newLen); } }
Cidr implements Serializable { public Cidr subnet(int ...extraUnsignedBytes) { if ((length%8)!=0) throw new IllegalStateException("subnet can only be used for byte boundary subnetted CIDR's; not "+this); int[] newBytes = getBytes(); int newLen = this.length + extraUnsignedBytes.length*8; if (newLen>32) throw new IllegalStateException("further subnet for "+Arrays.toString(extraUnsignedBytes)+" not possible on CIDR "+this); for (int i=0; i<extraUnsignedBytes.length; i++) { newBytes[this.length/8 + i] = extraUnsignedBytes[i]; } return new Cidr(newBytes, newLen); } Cidr(String cidr);  Cidr(int ...unsignedBytes);  Cidr(int[] subnetBytes, int length); }
Cidr implements Serializable { public Cidr subnet(int ...extraUnsignedBytes) { if ((length%8)!=0) throw new IllegalStateException("subnet can only be used for byte boundary subnetted CIDR's; not "+this); int[] newBytes = getBytes(); int newLen = this.length + extraUnsignedBytes.length*8; if (newLen>32) throw new IllegalStateException("further subnet for "+Arrays.toString(extraUnsignedBytes)+" not possible on CIDR "+this); for (int i=0; i<extraUnsignedBytes.length; i++) { newBytes[this.length/8 + i] = extraUnsignedBytes[i]; } return new Cidr(newBytes, newLen); } Cidr(String cidr);  Cidr(int ...unsignedBytes);  Cidr(int[] subnetBytes, int length); static boolean isCanonical(String cidr); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString(); int[] getBytes(); int getLength(); Cidr subnet(int ...extraUnsignedBytes); InetAddress netmask(); InetAddress addressAtOffset(int offset); int commonPrefixLength(Cidr other); Cidr commonPrefix(Cidr other); BitList asBitList(); boolean contains(Cidr target); @Deprecated static InetAddress getInetAddressWithFixedName(byte[] ip); }
Cidr implements Serializable { public Cidr subnet(int ...extraUnsignedBytes) { if ((length%8)!=0) throw new IllegalStateException("subnet can only be used for byte boundary subnetted CIDR's; not "+this); int[] newBytes = getBytes(); int newLen = this.length + extraUnsignedBytes.length*8; if (newLen>32) throw new IllegalStateException("further subnet for "+Arrays.toString(extraUnsignedBytes)+" not possible on CIDR "+this); for (int i=0; i<extraUnsignedBytes.length; i++) { newBytes[this.length/8 + i] = extraUnsignedBytes[i]; } return new Cidr(newBytes, newLen); } Cidr(String cidr);  Cidr(int ...unsignedBytes);  Cidr(int[] subnetBytes, int length); static boolean isCanonical(String cidr); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString(); int[] getBytes(); int getLength(); Cidr subnet(int ...extraUnsignedBytes); InetAddress netmask(); InetAddress addressAtOffset(int offset); int commonPrefixLength(Cidr other); Cidr commonPrefix(Cidr other); BitList asBitList(); boolean contains(Cidr target); @Deprecated static InetAddress getInetAddressWithFixedName(byte[] ip); static final Cidr UNIVERSAL; static final Cidr _10; static final Cidr _172_16; static final Cidr _192_168; static final Cidr CLASS_A; static final Cidr CLASS_B; static final Cidr CLASS_C; static final List<Cidr> PRIVATE_NETWORKS_RFC_1918; static final Cidr _169_254; static final Cidr LINK_LOCAL; static final Cidr _127; static final Cidr LOOPBACK; static final List<Cidr> NON_PUBLIC_CIDRS; }