@Test public void testAddressAtOffset() { Cidr c = new Cidr(10, 0); Assert.assertEquals(c.addressAtOffset(3).getHostAddress(), "10.0.0.3"); Assert.assertEquals(c.addressAtOffset(256*256*8+1).getHostAddress(), "10.8.0.1"); }
public InetAddress addressAtOffset(int offset) { int[] ints = getBytes(); ints[3] += offset; { int i=3; while (ints[i]>=256) { ints[i-1] += (ints[i] / 256); ints[i] %= 256; i--; } } byte[] bytes = new byte[] { 0, 0, 0, 0 }; for (int i=0; i<4; i++) bytes[i] = (byte) ints[i]; return Networking.getInetAddressWithFixedName(bytes); }
Cidr implements Serializable { public InetAddress addressAtOffset(int offset) { int[] ints = getBytes(); ints[3] += offset; { int i=3; while (ints[i]>=256) { ints[i-1] += (ints[i] / 256); ints[i] %= 256; i--; } } byte[] bytes = new byte[] { 0, 0, 0, 0 }; for (int i=0; i<4; i++) bytes[i] = (byte) ints[i]; return Networking.getInetAddressWithFixedName(bytes); } }
Cidr implements Serializable { public InetAddress addressAtOffset(int offset) { int[] ints = getBytes(); ints[3] += offset; { int i=3; while (ints[i]>=256) { ints[i-1] += (ints[i] / 256); ints[i] %= 256; i--; } } byte[] bytes = new byte[] { 0, 0, 0, 0 }; for (int i=0; i<4; i++) bytes[i] = (byte) ints[i]; return Networking.getInetAddressWithFixedName(bytes); } Cidr(String cidr);  Cidr(int ...unsignedBytes);  Cidr(int[] subnetBytes, int length); }
Cidr implements Serializable { public InetAddress addressAtOffset(int offset) { int[] ints = getBytes(); ints[3] += offset; { int i=3; while (ints[i]>=256) { ints[i-1] += (ints[i] / 256); ints[i] %= 256; i--; } } byte[] bytes = new byte[] { 0, 0, 0, 0 }; for (int i=0; i<4; i++) bytes[i] = (byte) ints[i]; return Networking.getInetAddressWithFixedName(bytes); } 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 InetAddress addressAtOffset(int offset) { int[] ints = getBytes(); ints[3] += offset; { int i=3; while (ints[i]>=256) { ints[i-1] += (ints[i] / 256); ints[i] %= 256; i--; } } byte[] bytes = new byte[] { 0, 0, 0, 0 }; for (int i=0; i<4; i++) bytes[i] = (byte) ints[i]; return Networking.getInetAddressWithFixedName(bytes); } 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; }