code: public static boolean matches(String pExpected, String pToCheck) {
          String[] parts = pExpected.split("/",2);
          if (parts.length == 1) {
              // No Net part given, check for equality ...
              // Check for valid ips
              convertToIntTuple(pExpected);
              convertToIntTuple(pToCheck);
              return pExpected.equals(pToCheck);
          } else if (parts.length == 2) {
              int ipToCheck[] = convertToIntTuple(pToCheck);
              int ipPattern[] = convertToIntTuple(parts[0]);
              int netmask[];
              if (parts[1].length() <= 2) {
                  netmask = transformCidrToNetmask(parts[1]);
              } else {
                  netmask = convertToIntTuple(parts[1]);
              }
              for (int i = 0; i<ipToCheck.length; i++) {
                  if ((ipPattern[i] & netmask[i]) != (ipToCheck[i] & netmask[i])) {
                      return false;
                  }
              }
              return true;
          } else {
              throw new IllegalArgumentException("Invalid IP adress specification " + pExpected);
          }
  	}
docs: Check whether a given IP Adress falls within a subnet or is equal to
  
  @param pExpected either a simple IP adress (without "/") or a net specification
  including a netmask (e.g "/24" or "/255.255.255.0")
  @param pToCheck the ip address to check
  @return true if either the address to check is the same as the address expected
  of falls within the subnet if a netmask is given