mirror of
git://git.code.sf.net/p/dhcpd-pools/code
synced 2025-12-16 15:57:00 +00:00
bug: use uint32_t for IP numbers
There where long and unsigned long used for IPs in use which caused occasional off by one errors. The word occasional should be read: pretty much every one with large enough configuration has been affected. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
parent
3c1d033a79
commit
1e82461875
5 changed files with 23 additions and 19 deletions
|
|
@ -44,7 +44,7 @@ int prepare_data(void)
|
|||
unsigned long int i, j, k;
|
||||
|
||||
/* Sort leases */
|
||||
qsort(leases, (size_t) num_leases, sizeof(long int), &intcomp);
|
||||
qsort(leases, (size_t) num_leases, sizeof(uint32_t), &intcomp);
|
||||
|
||||
/* Get rid of lease dublicates */
|
||||
for (k = j = i = 0; i < num_leases; i++) {
|
||||
|
|
@ -67,7 +67,7 @@ int prepare_data(void)
|
|||
}
|
||||
}
|
||||
num_touches = j;
|
||||
qsort(touches, (size_t) num_touches, sizeof(long int), &intcomp);
|
||||
qsort(touches, (size_t) num_touches, sizeof(uint32_t), &intcomp);
|
||||
|
||||
/* Sort ranges */
|
||||
qsort(ranges, (size_t) num_ranges, sizeof(struct range_t),
|
||||
|
|
@ -75,7 +75,7 @@ int prepare_data(void)
|
|||
|
||||
/* Sort backups */
|
||||
if (0 < num_backups) {
|
||||
qsort(backups, (size_t) num_backups, sizeof(long int),
|
||||
qsort(backups, (size_t) num_backups, sizeof(uint32_t),
|
||||
&intcomp);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@
|
|||
# define DHCPD_POOLS_H 1
|
||||
|
||||
#include <config.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <stddef.h>
|
||||
|
||||
/* Feature test switches */
|
||||
|
|
@ -103,8 +104,8 @@ struct shared_network_t {
|
|||
};
|
||||
struct range_t {
|
||||
struct shared_network_t *shared_net;
|
||||
unsigned long int first_ip;
|
||||
unsigned long int last_ip;
|
||||
uint32_t first_ip;
|
||||
uint32_t last_ip;
|
||||
unsigned long int count;
|
||||
unsigned long int touched;
|
||||
unsigned long int backups;
|
||||
|
|
@ -132,13 +133,13 @@ unsigned int num_shared_networks;
|
|||
struct range_t *ranges;
|
||||
unsigned int num_ranges;
|
||||
|
||||
unsigned long int *leases;
|
||||
uint32_t *leases;
|
||||
unsigned long int num_leases;
|
||||
|
||||
unsigned long int *touches;
|
||||
uint32_t *touches;
|
||||
unsigned long int num_touches;
|
||||
|
||||
unsigned long int *backups;
|
||||
uint32_t *backups;
|
||||
unsigned long int num_backups;
|
||||
|
||||
struct macaddr_t *macaddr;
|
||||
|
|
|
|||
|
|
@ -146,9 +146,9 @@ int parse_leases(void)
|
|||
num_leases++;
|
||||
if (leasesmallocsize < num_leases) {
|
||||
leasesmallocsize =
|
||||
sizeof(unsigned long int) * num_leases * 2;
|
||||
sizeof(uint32_t) * num_leases * 2;
|
||||
leases = safe_realloc(leases, leasesmallocsize);
|
||||
leasesmallocsize /= sizeof(unsigned long int);
|
||||
leasesmallocsize /= sizeof(uint32_t);
|
||||
}
|
||||
sw_active_lease = 1;
|
||||
} else if (strstr(line, " binding state free")) {
|
||||
|
|
@ -156,10 +156,10 @@ int parse_leases(void)
|
|||
num_touches++;
|
||||
if (touchesmallocsize < num_touches) {
|
||||
touchesmallocsize =
|
||||
sizeof(unsigned long int) * num_touches * 2;
|
||||
sizeof(uint32_t) * num_touches * 2;
|
||||
touches =
|
||||
safe_realloc(touches, touchesmallocsize);
|
||||
touchesmallocsize /= sizeof(unsigned long int);
|
||||
touchesmallocsize /= sizeof(uint32_t);
|
||||
}
|
||||
} else if (strstr(line, " binding state backup")) {
|
||||
if (num_backups == 0) {
|
||||
|
|
@ -171,10 +171,10 @@ int parse_leases(void)
|
|||
num_backups++;
|
||||
if (backupsmallocsize < num_backups) {
|
||||
backupsmallocsize =
|
||||
sizeof(unsigned long int) * num_backups * 2;
|
||||
sizeof(uint32_t) * num_backups * 2;
|
||||
backups =
|
||||
safe_realloc(backups, backupsmallocsize);
|
||||
backupsmallocsize /= sizeof(unsigned long int);
|
||||
backupsmallocsize /= sizeof(uint32_t);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -43,6 +43,9 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define _FILE_OFFSET_BITS 64
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "dhcpd-pools.h"
|
||||
|
||||
int output_txt(void)
|
||||
|
|
@ -90,7 +93,7 @@ int output_txt(void)
|
|||
}
|
||||
fprintf(outfile, "%-16s", inet_ntoa(first));
|
||||
fprintf(outfile,
|
||||
" - %-16s %5lu %5lu %10.3f %5lu %5lu %9.3f",
|
||||
" - %-16s %5"PRIu32" %5lu %10.3f %5lu %5lu %9.3f",
|
||||
inet_ntoa(last),
|
||||
range_p->last_ip - range_p->first_ip - 1,
|
||||
range_p->count,
|
||||
|
|
@ -256,7 +259,7 @@ int output_xml(void)
|
|||
fprintf(outfile, "- %s</range>\n",
|
||||
inet_ntoa(last));
|
||||
fprintf(outfile, "\t<gateway></gateway>\n");
|
||||
fprintf(outfile, "\t<defined>%lu</defined>\n",
|
||||
fprintf(outfile, "\t<defined>%"PRIu32"</defined>\n",
|
||||
range_p->last_ip - range_p->first_ip - 1);
|
||||
fprintf(outfile, "\t<used>%lu</used>\n",
|
||||
range_p->count);
|
||||
|
|
@ -679,7 +682,7 @@ int output_csv(void)
|
|||
}
|
||||
fprintf(outfile, "\"%s\",", inet_ntoa(first));
|
||||
fprintf(outfile,
|
||||
"\"%s\",\"%lu\",\"%lu\",\"%.3f\",\"%lu\",\"%lu\",\"%.3f\"",
|
||||
"\"%s\",\"%"PRIu32"\",\"%lu\",\"%.3f\",\"%lu\",\"%lu\",\"%.3f\"",
|
||||
inet_ntoa(last),
|
||||
range_p->last_ip - range_p->first_ip - 1,
|
||||
range_p->count,
|
||||
|
|
|
|||
|
|
@ -44,9 +44,9 @@
|
|||
/* Sort functions for range sorting */
|
||||
int intcomp(const void *x, const void *y)
|
||||
{
|
||||
if (*(unsigned long int *) x < *(unsigned long int *) y)
|
||||
if (*(uint32_t *) x < *(uint32_t *) y)
|
||||
return -1;
|
||||
else if (*(unsigned long int *) y < *(unsigned long int *) x)
|
||||
else if (*(uint32_t *) y < *(uint32_t *) x)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue