- protected class IPEntry {
-
- /** The network address. */
- private final BitSet networkAddress;
-
- /** The netmask. */
- private final BitSet netmask;
-
- /**
- * Construct a new IPEntry given a network address in CIDR format.
- *
- * @param entry A CIDR-formatted network address/netmask
- *
- * @throws UnknownHostException If entry is malformed.
- */
- public IPEntry(String entry) throws UnknownHostException {
-
- // quick sanity checks
- if (entry == null || entry.length() == 0) {
- throw new UnknownHostException("entry is null.");
- }
-
- int cidrOffset = entry.indexOf("/");
- if (cidrOffset == -1) {
- log.warn("Invalid entry \"" + entry + "\" -- it lacks a netmask component.");
- throw new UnknownHostException("entry lacks a netmask component.");
- }
-
- // ensure that only one "/" is present.
- if (entry.indexOf("/", cidrOffset + 1) != -1) {
- log.warn("Invalid entry \"" + entry + "\" -- too many \"/\" present.");
- throw new UnknownHostException("entry has too many netmask components.");
- }
-
- String networkString = entry.substring(0, cidrOffset);
- String netmaskString = entry.substring(cidrOffset + 1, entry.length());
-
- InetAddress tempAddr = InetAddress.getByName(networkString);
- networkAddress = byteArrayToBitSet(tempAddr.getAddress());
-
- int masklen = Integer.parseInt(netmaskString);
-
- int addrlen;
- if (tempAddr instanceof Inet4Address) {
- addrlen = 32;
- } else if (tempAddr instanceof Inet6Address) {
- addrlen = 128;
- }else{
- throw new UnknownHostException("Unable to determine Inet protocol version");