/* $Id: ip4rangetest.c,v 1.3 2003/04/05 08:05:57 mjt Exp $
 * small program to test ip4range_expand macro
 */

#include <stdio.h>
#include "ip4addr.h"
#include "rbldnsd.h"

#define octets(a) (a>>24)&255, (a>>16)&255, (a>>8)&255, a&255

int fn(unsigned idx, ip4addr_t start, unsigned count) {
  ip4addr_t step = 1u << (idx << 3);
  ip4addr_t last = start + step * (count - 1);
  printf(" +%u: %u.%u.%u.%u-%u.%u.%u.%u/%u (%u x %u.%u.%u.%u)\n",
    idx, octets(start), octets(last), 32-(idx<<3), count, octets(step));
  return 1;
}

int main(int argc, char **argv) {
  int c;
  ip4addr_t a, b;
  for(c = 1; c < argc; ++c) {
    if (!ip4range(argv[c], &a, &b, NULL)) {
      printf("%s: parse error\n", argv[c]);
      continue;
    }
    printf(" %s: %u.%u.%u.%u-%u.%u.%u.%u\n", argv[c], octets(a), octets(b));
    ip4range_expand(a,b,fn);
  }
  return 0;
}
