CLG_GetSubnetBitmap(IPAddr *subnet, int bits, CLG_Bitmap result)
{
  Subnet *s;
  uint32_t ip6[4];
  unsigned long i;
  unsigned long word, bit, mask;

  if (bits >= 0 && bits % 8 == 0) {
    memset (result, 0, TABLE_SIZE/8);
    if (active) {
      switch (subnet->family) {
        case IPADDR_INET4:
          if (bits >= 32)
            return CLG_BADSUBNET;
          s = find_subnet_dont_open(&top_subnet4, &subnet->addr.in4, 1, 32 - bits);
          break;
        case IPADDR_INET6:
          if (bits >= 128)
            return CLG_BADSUBNET;
          split_ip6(subnet, ip6);
          s = find_subnet_dont_open(&top_subnet6, ip6, 4, 128 - bits);
          break;
        default:
          return CLG_BADSUBNET;
      }

      if (s) {
        for (i=0; i<256; i++) {
          if (s->entry[i]) {
            word = i / 32;
            bit =  i % 32;
            mask = 1UL << bit;
            result[word] |= mask;
          }
        }
        return CLG_SUCCESS;
      } else {
        return CLG_EMPTYSUBNET;
      }
    } else {
      return CLG_INACTIVE;
    }
  } else {
    return CLG_BADSUBNET;
  }
}
CLG_GetSubnetBitmap(IPAddr *subnet, int bits, CLG_Bitmap result)
{
  Subnet *s;
  uint32_t ip6[4];
  unsigned long i;
  unsigned long word, bit, mask;

  if (bits >= 0 && bits % 8 == 0) {
    memset (result, 0, TABLE_SIZE/8);
    if (active) {
      switch (subnet->family) {
        case IPADDR_INET4:
          if (bits >= 32)
            return CLG_BADSUBNET;
          s = find_subnet_dont_open(&top_subnet4, &subnet->addr.in4, 1, 32 - bits);
          break;
        case IPADDR_INET6:
          if (bits >= 128)
            return CLG_BADSUBNET;
          split_ip6(subnet, ip6);
          s = find_subnet_dont_open(&top_subnet6, ip6, 4, 128 - bits);
          break;
        default:
          return CLG_BADSUBNET;
      }

      if (s) {
        for (i=0; i<256; i++) {
          if (s->entry[i]) {
            word = i / 32;
            bit =  i % 32;
            mask = 1UL << bit;
            result[word] |= mask;
          }
        }
        return CLG_SUCCESS;
      } else {
        return CLG_EMPTYSUBNET;
      }
    } else {
      return CLG_INACTIVE;
    }
  } else {
    return CLG_BADSUBNET;
  }
}