/* ** Copyright (C) 2006- Sami Kerola ** ** This program is free software; you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation; either version 2 of the License, or ** (at your option) any later version. ** ** This program is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. ** ** You should have received a copy of the GNU General Public License ** along with this program; if not, write to the Free Software ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifdef HAVE_CONFIG_H #include #endif #include #include #include "dhcpd-pools.h" /* Clean up data */ int prepare_data (void) { unsigned long int i, j, k; /* Sort leases */ qsort (leases, (size_t) num_leases, sizeof (long int), &intcomp); /* Get rid of dublicates */ for (k = j = i = 0; i < num_leases; i++) { if (j != leases[i]) { leases[k] = leases[i]; j = leases[i]; k++; } } num_leases = k; /* Sort ranges */ qsort (ranges, (size_t) num_ranges, sizeof (struct range_t), &rangecomp); return 0; } /* Join leases and ranges into couter structs */ int do_counting (void) { struct range_t *range_p; unsigned int i, block_size; range_p = ranges; for (i = 0; i < num_leases; i++) { /* IP with in range */ if (range_p->first_ip < leases[i] && range_p->last_ip > leases[i]) { range_p->count++; if (range_p->shared_net) { range_p->shared_net->used++; } shared_networks->used++; } /* IP out of range */ if (range_p->last_ip < leases[i]) { range_p++; /* Break loop before trying to access memorory that is * not allocated. */ if (range_p - ranges > num_ranges) { break; } block_size = range_p->last_ip - range_p->first_ip - 1; if (range_p->shared_net) { range_p->shared_net->available += block_size; } shared_networks->available += block_size; i--; } } return 0; }