<commit_before>#include <stdlib.h>
#include <string.h>
#include <math.h>

#include "repsheet.h"
#include "cidr.h"

/**
 * @file cidr.c
 * @author <NAME>
 * @date 10/09/2014
 */

int _string_to_cidr(CIDR *cidr, char *block);

int block_to_range( char *block, range *range )
{
  if (block == NULL) {
    return NIL;
  }

  CIDR cidr;
  int result = _string_to_cidr(&cidr, block);
  if (result == BAD_ADDRESS || result == BAD_CIDR_BLOCK) {
    return result;
  }

  range->lower = cidr.address;
  range->upper = range->lower + (1 <<  (32 - cidr.mask)); 
    // (pow(2, (32 - cidr.mask)) -1); POW is a potential bug because of rounding--POW is double and we're working with INT values 

  if (cidr.address == BAD_ADDRESS) {
    return BAD_ADDRESS;
  }
  return 1;
}

/**
 * Test an IP to see if it is contained in the CIDR block
 *
 * @param block the CIDR block string
 * @param address the IP address string
 *
 * @returns 1 if in the block, 0 if not
 */
int cidr_contains(char *block, int ip)
{
  range range;
  if (ip == BAD_ADDRESS)
  {
    return BAD_ADDRESS;
  }
  int rc =  block_to_range(block, &range);
  if (rc <= 0) {
    return rc;
  }
  return address_in_range(&range, ip);<commit_msg>remove 1 from the mask<commit_after>#include <stdlib.h>
#include <string.h>
#include <math.h>

#include "repsheet.h"
#include "cidr.h"

/**
 * @file cidr.c
 * @author <NAME>
 * @date 10/09/2014
 */

int _string_to_cidr(CIDR *cidr, char *block);

int block_to_range( char *block, range *range )
{
  if (block == NULL) {
    return NIL;
  }

  CIDR cidr;
  int result = _string_to_cidr(&cidr, block);
  if (result == BAD_ADDRESS || result == BAD_CIDR_BLOCK) {
    return result;
  }

  range->lower = cidr.address;
  range->upper = range->lower + (1 <<  (32 - cidr.mask)) - 1; 
    // (pow(2, (32 - cidr.mask)) -1); POW is a potential bug because of rounding--POW is double and we're working with INT values 

  if (cidr.address == BAD_ADDRESS) {
    return BAD_ADDRESS;
  }
  return 1;
}

/**
 * Test an IP to see if it is contained in the CIDR block
 *
 * @param block the CIDR block string
 * @param address the IP address string
 *
 * @returns 1 if in the block, 0 if not
 */
int cidr_contains(char *block, int ip)
{
  range range;
  if (ip == BAD_ADDRESS)
  {
    return BAD_ADDRESS;
  }
  int rc =  block_to_range(block, &range);
  if (rc <= 0) {
    return rc;
  }
  return address_in_range(&range, ip);
{'fraction_non_alphanumeric': 0.14024136496046608, 'fraction_numerical': 0.016645859342488557, 'mean_word_length': 3.0884353741496597, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7335104', 'n_tokens_mistral': 970, 'n_tokens_neox': 939, 'n_words': 278}