mirror of
git://git.code.sf.net/p/dhcpd-pools/code
synced 2025-12-16 15:57:00 +00:00
maint: coding style fixes
Remove unnecessary type casting, move .gitignore file contents to right location, reindent to use Linux coding style, fix few type mismatches, clean up to help & version output and hint compiler call to these functions will end program. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
parent
68c2d7b8cc
commit
76915512b2
10 changed files with 148 additions and 189 deletions
5
.gitignore
vendored
5
.gitignore
vendored
|
|
@ -21,8 +21,5 @@ Makefile.in
|
||||||
man/Makefile
|
man/Makefile
|
||||||
man/Makefile.in
|
man/Makefile.in
|
||||||
missing
|
missing
|
||||||
src/.deps/
|
|
||||||
src/Makefile
|
|
||||||
src/Makefile.in
|
|
||||||
src/*.o
|
|
||||||
stamp-h1
|
stamp-h1
|
||||||
|
tags
|
||||||
|
|
|
||||||
6
src/.gitignore
vendored
6
src/.gitignore
vendored
|
|
@ -1 +1,7 @@
|
||||||
|
*~
|
||||||
|
*.o
|
||||||
|
.deps/
|
||||||
dhcpd-pools
|
dhcpd-pools
|
||||||
|
Makefile
|
||||||
|
Makefile.in
|
||||||
|
tags
|
||||||
|
|
|
||||||
|
|
@ -73,8 +73,7 @@ int prepare_data(void)
|
||||||
qsort(touches, (size_t) num_touches, sizeof(uint32_t), &intcomp);
|
qsort(touches, (size_t) num_touches, sizeof(uint32_t), &intcomp);
|
||||||
|
|
||||||
/* Sort ranges */
|
/* Sort ranges */
|
||||||
qsort(ranges, (size_t) num_ranges, sizeof(struct range_t),
|
qsort(ranges, (size_t) num_ranges, sizeof(struct range_t), &rangecomp);
|
||||||
&rangecomp);
|
|
||||||
|
|
||||||
/* Sort backups */
|
/* Sort backups */
|
||||||
if (0 < num_backups) {
|
if (0 < num_backups) {
|
||||||
|
|
@ -89,15 +88,14 @@ int prepare_data(void)
|
||||||
int do_counting(void)
|
int do_counting(void)
|
||||||
{
|
{
|
||||||
struct range_t *range_p;
|
struct range_t *range_p;
|
||||||
unsigned int i, j, k, l, block_size;
|
unsigned long i, j, k, l, block_size;
|
||||||
|
|
||||||
range_p = ranges;
|
range_p = ranges;
|
||||||
|
|
||||||
/* Walk through ranges */
|
/* Walk through ranges */
|
||||||
for (i = j = k = l = 0; i < num_ranges; i++) {
|
for (i = j = k = l = 0; i < num_ranges; i++) {
|
||||||
/* Count IPs in use */
|
/* Count IPs in use */
|
||||||
for (; leases[j] < range_p->last_ip
|
for (; leases[j] < range_p->last_ip && j < num_leases; j++) {
|
||||||
&& (unsigned long) j < num_leases; j++) {
|
|
||||||
if (leases[j] < range_p->first_ip) {
|
if (leases[j] < range_p->first_ip) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
@ -109,8 +107,7 @@ int do_counting(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Count touched IPs */
|
/* Count touched IPs */
|
||||||
for (; touches[k] < range_p->last_ip
|
for (; touches[k] < range_p->last_ip && k < num_touches; k++) {
|
||||||
&& (unsigned long) k < num_touches; k++) {
|
|
||||||
if (touches[k] < range_p->first_ip) {
|
if (touches[k] < range_p->first_ip) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
@ -124,7 +121,7 @@ int do_counting(void)
|
||||||
/* Count backup IPs */
|
/* Count backup IPs */
|
||||||
if (0 < num_backups) {
|
if (0 < num_backups) {
|
||||||
for (; backups[l] < range_p->last_ip
|
for (; backups[l] < range_p->last_ip
|
||||||
&& (unsigned long) l < num_touches; l++) {
|
&& l < num_touches; l++) {
|
||||||
if (touches[l] < range_p->first_ip) {
|
if (touches[l] < range_p->first_ip) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
@ -138,8 +135,7 @@ int do_counting(void)
|
||||||
|
|
||||||
/* Size of range, shared net & all networks */
|
/* Size of range, shared net & all networks */
|
||||||
block_size =
|
block_size =
|
||||||
(unsigned int) (range_p->last_ip - range_p->first_ip -
|
(unsigned int)(range_p->last_ip - range_p->first_ip - 1);
|
||||||
1);
|
|
||||||
if (range_p->shared_net) {
|
if (range_p->shared_net) {
|
||||||
range_p->shared_net->available += block_size;
|
range_p->shared_net->available += block_size;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@
|
||||||
# define DEFAULTS_H 1
|
# define DEFAULTS_H 1
|
||||||
|
|
||||||
/* Maximum line length in dhcpd.conf and dhcpd.leases */
|
/* Maximum line length in dhcpd.conf and dhcpd.leases */
|
||||||
static const int MAXLEN = 1024;
|
static const size_t MAXLEN = 1024;
|
||||||
|
|
||||||
/* Maximum number of shared networks */
|
/* Maximum number of shared networks */
|
||||||
static const unsigned int SHARED_NETWORKS = 8192;
|
static const unsigned int SHARED_NETWORKS = 8192;
|
||||||
|
|
|
||||||
|
|
@ -64,16 +64,16 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
/* Options for getopt_long */
|
/* Options for getopt_long */
|
||||||
static struct option const long_options[] = {
|
static struct option const long_options[] = {
|
||||||
{"config", required_argument, 0, (int) 'c'},
|
{"config", required_argument, NULL, 'c'},
|
||||||
{"leases", required_argument, 0, (int) 'l'},
|
{"leases", required_argument, NULL, 'l'},
|
||||||
{"format", required_argument, 0, (int) 'f'},
|
{"format", required_argument, NULL, 'f'},
|
||||||
{"sort", required_argument, 0, (int) 's'},
|
{"sort", required_argument, NULL, 's'},
|
||||||
{"reverse", no_argument, 0, (int) 'r'},
|
{"reverse", no_argument, NULL, 'r'},
|
||||||
{"output", required_argument, 0, (int) 'o'},
|
{"output", required_argument, NULL, 'o'},
|
||||||
{"limit", required_argument, 0, (int) 'L'},
|
{"limit", required_argument, NULL, 'L'},
|
||||||
{"version", no_argument, 0, (int) 'v'},
|
{"version", no_argument, NULL, 'v'},
|
||||||
{"help", no_argument, 0, (int) 'h'},
|
{"help", no_argument, NULL, 'h'},
|
||||||
{0, 0, 0, 0}
|
{NULL, 0, NULL, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
/* FIXME: make these allocations dynamic up on need. */
|
/* FIXME: make these allocations dynamic up on need. */
|
||||||
|
|
@ -86,14 +86,12 @@ int main(int argc, char **argv)
|
||||||
config.output_file[0] = '\0';
|
config.output_file[0] = '\0';
|
||||||
|
|
||||||
/* File location defaults */
|
/* File location defaults */
|
||||||
strncpy(config.dhcpdconf_file, DHCPDCONF_FILE,
|
strncpy(config.dhcpdconf_file, DHCPDCONF_FILE, MAXLEN - 1);
|
||||||
(size_t) MAXLEN - 1);
|
strncpy(config.dhcpdlease_file, DHCPDLEASE_FILE, MAXLEN - 1);
|
||||||
strncpy(config.dhcpdlease_file, DHCPDLEASE_FILE,
|
|
||||||
(size_t) MAXLEN - 1);
|
|
||||||
tmp = OUTPUT_LIMIT;
|
tmp = OUTPUT_LIMIT;
|
||||||
config.output_limit[0] = (int) (*tmp - '0');
|
config.output_limit[0] = (*tmp - '0');
|
||||||
tmp++;
|
tmp++;
|
||||||
config.output_limit[1] = (int) (*tmp - '0');
|
config.output_limit[1] = (*tmp - '0');
|
||||||
fullhtml = false;
|
fullhtml = false;
|
||||||
|
|
||||||
/* Make sure some output format is selected by default */
|
/* Make sure some output format is selected by default */
|
||||||
|
|
@ -113,13 +111,11 @@ int main(int argc, char **argv)
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'c':
|
case 'c':
|
||||||
/* config file */
|
/* config file */
|
||||||
strncpy(config.dhcpdconf_file, optarg,
|
strncpy(config.dhcpdconf_file, optarg, MAXLEN - 1);
|
||||||
(size_t) MAXLEN - 1);
|
|
||||||
break;
|
break;
|
||||||
case 'l':
|
case 'l':
|
||||||
/* lease file */
|
/* lease file */
|
||||||
strncpy(config.dhcpdlease_file, optarg,
|
strncpy(config.dhcpdlease_file, optarg, MAXLEN - 1);
|
||||||
(size_t) MAXLEN - 1);
|
|
||||||
break;
|
break;
|
||||||
case 'f':
|
case 'f':
|
||||||
/* Output format */
|
/* Output format */
|
||||||
|
|
@ -134,8 +130,7 @@ int main(int argc, char **argv)
|
||||||
strncpy(config.sort, optarg, (size_t) 5);
|
strncpy(config.sort, optarg, (size_t) 5);
|
||||||
sorts = 5;
|
sorts = 5;
|
||||||
} else {
|
} else {
|
||||||
strncpy(config.sort, optarg,
|
strncpy(config.sort, optarg, (size_t) sorts);
|
||||||
(size_t) sorts);
|
|
||||||
}
|
}
|
||||||
for (i = 0; i < sorts; i++) {
|
for (i = 0; i < sorts; i++) {
|
||||||
field_selector(config.sort[i]);
|
field_selector(config.sort[i]);
|
||||||
|
|
@ -147,15 +142,14 @@ int main(int argc, char **argv)
|
||||||
break;
|
break;
|
||||||
case 'o':
|
case 'o':
|
||||||
/* Output file */
|
/* Output file */
|
||||||
strncpy(config.output_file, optarg,
|
strncpy(config.output_file, optarg, MAXLEN - 1);
|
||||||
(size_t) MAXLEN - 1);
|
|
||||||
break;
|
break;
|
||||||
case 'L':
|
case 'L':
|
||||||
/* Specification what will be printed */
|
/* Specification what will be printed */
|
||||||
for (i = 0; i < 2; i++) {
|
for (i = 0; i < 2; i++) {
|
||||||
if (optarg[i] >= '0' && optarg[i] < '8') {
|
if (optarg[i] >= '0' && optarg[i] < '8') {
|
||||||
config.output_limit[i] =
|
config.output_limit[i] =
|
||||||
(int) optarg[i] - '0';
|
optarg[i] - '0';
|
||||||
} else {
|
} else {
|
||||||
errx(EXIT_FAILURE,
|
errx(EXIT_FAILURE,
|
||||||
"main: output mask `%s' is illegal",
|
"main: output mask `%s' is illegal",
|
||||||
|
|
|
||||||
|
|
@ -65,8 +65,8 @@ extern char *__progname;
|
||||||
# define program_invocation_short_name \
|
# define program_invocation_short_name \
|
||||||
prog_inv_sh_nm_from_file(__FILE__, 1)
|
prog_inv_sh_nm_from_file(__FILE__, 1)
|
||||||
# endif /* HAVE_PROGRAM_INVOCATION_SHORT_NAME */
|
# endif /* HAVE_PROGRAM_INVOCATION_SHORT_NAME */
|
||||||
static char prog_inv_sh_nm_buf[256];
|
char prog_inv_sh_nm_buf[256];
|
||||||
static inline char *prog_inv_sh_nm_from_file(char *f, char stripext)
|
inline char *prog_inv_sh_nm_from_file(char *f, char stripext)
|
||||||
{
|
{
|
||||||
char *t;
|
char *t;
|
||||||
if ((t = strrchr(f, '/')) != NULL) {
|
if ((t = strrchr(f, '/')) != NULL) {
|
||||||
|
|
@ -119,29 +119,21 @@ struct macaddr_t {
|
||||||
/* Global variables */
|
/* Global variables */
|
||||||
static int const true = 1;
|
static int const true = 1;
|
||||||
static int const false = 0;
|
static int const false = 0;
|
||||||
|
|
||||||
struct configuration_t config;
|
struct configuration_t config;
|
||||||
|
|
||||||
static int const output_limit_bit_1 = 1;
|
static int const output_limit_bit_1 = 1;
|
||||||
static int const output_limit_bit_2 = 2;
|
static int const output_limit_bit_2 = 2;
|
||||||
static int const output_limit_bit_3 = 4;
|
static int const output_limit_bit_3 = 4;
|
||||||
unsigned int fullhtml;
|
unsigned int fullhtml;
|
||||||
|
|
||||||
struct shared_network_t *shared_networks;
|
struct shared_network_t *shared_networks;
|
||||||
unsigned int num_shared_networks;
|
unsigned int num_shared_networks;
|
||||||
|
|
||||||
struct range_t *ranges;
|
struct range_t *ranges;
|
||||||
unsigned int num_ranges;
|
unsigned int num_ranges;
|
||||||
|
|
||||||
uint32_t *leases;
|
uint32_t *leases;
|
||||||
unsigned long int num_leases;
|
unsigned long int num_leases;
|
||||||
|
|
||||||
uint32_t *touches;
|
uint32_t *touches;
|
||||||
unsigned long int num_touches;
|
unsigned long int num_touches;
|
||||||
|
|
||||||
uint32_t *backups;
|
uint32_t *backups;
|
||||||
unsigned long int num_backups;
|
unsigned long int num_backups;
|
||||||
|
|
||||||
struct macaddr_t *macaddr;
|
struct macaddr_t *macaddr;
|
||||||
|
|
||||||
/* Function prototypes */
|
/* Function prototypes */
|
||||||
|
|
@ -159,7 +151,7 @@ int prepare_data(void);
|
||||||
int do_counting(void);
|
int do_counting(void);
|
||||||
void flip_ranges(struct range_t *ranges, struct range_t *tmp_ranges)
|
void flip_ranges(struct range_t *ranges, struct range_t *tmp_ranges)
|
||||||
__attribute__ ((nonnull(1, 2)));
|
__attribute__ ((nonnull(1, 2)));
|
||||||
/* General support functions */
|
/* support functions */
|
||||||
void *safe_malloc(const size_t size)
|
void *safe_malloc(const size_t size)
|
||||||
#if __GNUC__ >= 3
|
#if __GNUC__ >= 3
|
||||||
__attribute__ ((__malloc__))
|
__attribute__ ((__malloc__))
|
||||||
|
|
|
||||||
|
|
@ -86,18 +86,17 @@ int parse_leases(void)
|
||||||
|
|
||||||
dhcpd_leases = fopen(config.dhcpdlease_file, "r");
|
dhcpd_leases = fopen(config.dhcpdlease_file, "r");
|
||||||
if (dhcpd_leases == NULL) {
|
if (dhcpd_leases == NULL) {
|
||||||
err(EXIT_FAILURE, "parse_leases: %s",
|
err(EXIT_FAILURE, "parse_leases: %s", config.dhcpdlease_file);
|
||||||
config.dhcpdlease_file);
|
|
||||||
}
|
}
|
||||||
#ifdef POSIX_FADV_WILLNEED
|
#ifdef POSIX_FADV_WILLNEED
|
||||||
posix_fadvise((long) dhcpd_leases, 0, 0, POSIX_FADV_WILLNEED);
|
posix_fadvise(fileno(dhcpd_leases), 0, 0, POSIX_FADV_WILLNEED);
|
||||||
if (errno) {
|
if (errno) {
|
||||||
err(EXIT_FAILURE, "parse_leases: fadvise %s",
|
err(EXIT_FAILURE, "parse_leases: fadvise %s",
|
||||||
config.dhcpdlease_file);
|
config.dhcpdlease_file);
|
||||||
}
|
}
|
||||||
#endif /* POSIX_FADV_WILLNEED */
|
#endif /* POSIX_FADV_WILLNEED */
|
||||||
#ifdef POSIX_FADV_SEQUENTIAL
|
#ifdef POSIX_FADV_SEQUENTIAL
|
||||||
posix_fadvise((long) dhcpd_leases, 0, 0, POSIX_FADV_SEQUENTIAL);
|
posix_fadvise(fileno(dhcpd_leases), 0, 0, POSIX_FADV_SEQUENTIAL);
|
||||||
if (errno) {
|
if (errno) {
|
||||||
err(EXIT_FAILURE, "parse_leases: fadvise %s",
|
err(EXIT_FAILURE, "parse_leases: fadvise %s",
|
||||||
config.dhcpdlease_file);
|
config.dhcpdlease_file);
|
||||||
|
|
@ -109,15 +108,13 @@ int parse_leases(void)
|
||||||
* If someone has higher density in lease file I'm interested to
|
* If someone has higher density in lease file I'm interested to
|
||||||
* hear about that. */
|
* hear about that. */
|
||||||
if (stat(config.dhcpdlease_file, &lease_file_stats)) {
|
if (stat(config.dhcpdlease_file, &lease_file_stats)) {
|
||||||
err(EXIT_FAILURE, "parse_leases: %s",
|
err(EXIT_FAILURE, "parse_leases: %s", config.dhcpdlease_file);
|
||||||
config.dhcpdlease_file);
|
|
||||||
}
|
}
|
||||||
leasesmallocsize = (lease_file_stats.st_size / 250) + MAXLEN - 2;
|
leasesmallocsize = (lease_file_stats.st_size / 250) + MAXLEN - 2;
|
||||||
touchesmallocsize = (lease_file_stats.st_size / 250) + MAXLEN - 2;
|
touchesmallocsize = (lease_file_stats.st_size / 250) + MAXLEN - 2;
|
||||||
backupsmallocsize = (lease_file_stats.st_size / 120) + MAXLEN - 2;
|
backupsmallocsize = (lease_file_stats.st_size / 120) + MAXLEN - 2;
|
||||||
leases = safe_malloc(sizeof(long int) * leasesmallocsize);
|
leases = safe_malloc(sizeof(long int) * leasesmallocsize);
|
||||||
touches =
|
touches = safe_malloc((size_t) sizeof(long int) * touchesmallocsize);
|
||||||
safe_malloc((size_t) sizeof(long int) * touchesmallocsize);
|
|
||||||
|
|
||||||
memset(leases, 0, sizeof(long int) * leasesmallocsize);
|
memset(leases, 0, sizeof(long int) * leasesmallocsize);
|
||||||
memset(touches, 0, sizeof(long int) * touchesmallocsize);
|
memset(touches, 0, sizeof(long int) * touchesmallocsize);
|
||||||
|
|
@ -133,11 +130,12 @@ int parse_leases(void)
|
||||||
|
|
||||||
while (!feof(dhcpd_leases)) {
|
while (!feof(dhcpd_leases)) {
|
||||||
if (!fgets(line, MAXLEN, dhcpd_leases) && ferror(dhcpd_leases)) {
|
if (!fgets(line, MAXLEN, dhcpd_leases) && ferror(dhcpd_leases)) {
|
||||||
err(EXIT_FAILURE, "parse_leases: %s", config.dhcpdlease_file);
|
err(EXIT_FAILURE, "parse_leases: %s",
|
||||||
|
config.dhcpdlease_file);
|
||||||
}
|
}
|
||||||
/* It's a lease, save IP */
|
/* It's a lease, save IP */
|
||||||
if (strstr(line, "lease") == line) {
|
if (strstr(line, "lease") == line) {
|
||||||
strncpy(ipstring, line, (size_t) MAXLEN);
|
strncpy(ipstring, line, MAXLEN);
|
||||||
nth_field(2, ipstring, ipstring);
|
nth_field(2, ipstring, ipstring);
|
||||||
inet_aton(ipstring, &inp);
|
inet_aton(ipstring, &inp);
|
||||||
sw_active_lease = 0;
|
sw_active_lease = 0;
|
||||||
|
|
@ -187,8 +185,7 @@ int parse_leases(void)
|
||||||
macstring[17] = '\0';
|
macstring[17] = '\0';
|
||||||
macaddr_p->ethernet = safe_strdup(macstring);
|
macaddr_p->ethernet = safe_strdup(macstring);
|
||||||
macaddr_p->ip = safe_strdup(ipstring);
|
macaddr_p->ip = safe_strdup(ipstring);
|
||||||
macaddr_p->next =
|
macaddr_p->next = safe_malloc(sizeof(struct macaddr_t));
|
||||||
safe_malloc(sizeof(struct macaddr_t));
|
|
||||||
macaddr_p = macaddr_p->next;
|
macaddr_p = macaddr_p->next;
|
||||||
macaddr_p->next = NULL;
|
macaddr_p->next = NULL;
|
||||||
}
|
}
|
||||||
|
|
@ -251,8 +248,9 @@ void parse_config(int is_include, char *config_file,
|
||||||
struct shared_network_t *shared_p)
|
struct shared_network_t *shared_p)
|
||||||
{
|
{
|
||||||
FILE *dhcpd_config;
|
FILE *dhcpd_config;
|
||||||
int i = 0, newclause = true, argument = false, comment =
|
int newclause = true, argument = false, comment =
|
||||||
false, braces = 0, quote = false;
|
false, braces = 0, quote = false;
|
||||||
|
size_t i = 0;
|
||||||
char *word, c;
|
char *word, c;
|
||||||
int braces_shared = 1000;
|
int braces_shared = 1000;
|
||||||
struct in_addr inp;
|
struct in_addr inp;
|
||||||
|
|
@ -271,13 +269,13 @@ void parse_config(int is_include, char *config_file,
|
||||||
err(EXIT_FAILURE, "parse_config: %s", config_file);
|
err(EXIT_FAILURE, "parse_config: %s", config_file);
|
||||||
}
|
}
|
||||||
#ifdef POSIX_FADV_WILLNEED
|
#ifdef POSIX_FADV_WILLNEED
|
||||||
posix_fadvise((long) dhcpd_config, 0, 0, POSIX_FADV_WILLNEED);
|
posix_fadvise(fileno(dhcpd_config), 0, 0, POSIX_FADV_WILLNEED);
|
||||||
if (errno) {
|
if (errno) {
|
||||||
err(EXIT_FAILURE, "parse_config: fadvise %s", config_file);
|
err(EXIT_FAILURE, "parse_config: fadvise %s", config_file);
|
||||||
}
|
}
|
||||||
#endif /* POSIX_FADV_WILLNEED */
|
#endif /* POSIX_FADV_WILLNEED */
|
||||||
#ifdef POSIX_FADV_SEQUENTIAL
|
#ifdef POSIX_FADV_SEQUENTIAL
|
||||||
posix_fadvise((long) dhcpd_config, 0, 0, POSIX_FADV_SEQUENTIAL);
|
posix_fadvise(fileno(dhcpd_config), 0, 0, POSIX_FADV_SEQUENTIAL);
|
||||||
if (errno) {
|
if (errno) {
|
||||||
err(EXIT_FAILURE, "parse_config: fadvise %s", config_file);
|
err(EXIT_FAILURE, "parse_config: fadvise %s", config_file);
|
||||||
}
|
}
|
||||||
|
|
@ -313,8 +311,7 @@ void parse_config(int is_include, char *config_file,
|
||||||
if (quote == true) {
|
if (quote == true) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (comment == false && argument != 2
|
if (comment == false && argument != 2 && argument != 4) {
|
||||||
&& argument != 4) {
|
|
||||||
newclause = true;
|
newclause = true;
|
||||||
i = 0;
|
i = 0;
|
||||||
} else if (argument == 2) {
|
} else if (argument == 2) {
|
||||||
|
|
@ -364,8 +361,7 @@ void parse_config(int is_include, char *config_file,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Either inside comment or Nth word of clause. */
|
/* Either inside comment or Nth word of clause. */
|
||||||
if (comment == true
|
if (comment == true || (newclause == false && argument == 0)) {
|
||||||
|| (newclause == false && argument == 0)) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
/* Strip white spaces before new clause word. */
|
/* Strip white spaces before new clause word. */
|
||||||
|
|
@ -446,8 +442,7 @@ void parse_config(int is_include, char *config_file,
|
||||||
shared_p->used = 0;
|
shared_p->used = 0;
|
||||||
shared_p->touched = 0;
|
shared_p->touched = 0;
|
||||||
shared_p->backups = 0;
|
shared_p->backups = 0;
|
||||||
if (SHARED_NETWORKS <
|
if (SHARED_NETWORKS < num_shared_networks + 2) {
|
||||||
num_shared_networks + 2) {
|
|
||||||
/* FIXME: make this
|
/* FIXME: make this
|
||||||
* away by reallocationg
|
* away by reallocationg
|
||||||
* more space. */
|
* more space. */
|
||||||
|
|
|
||||||
28
src/other.c
28
src/other.c
|
|
@ -123,38 +123,35 @@ void clean_up(void)
|
||||||
free(shared_networks);
|
free(shared_networks);
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_version(void)
|
void __attribute__ ((__noreturn__)) print_version(void)
|
||||||
{
|
{
|
||||||
fprintf(stdout, "%s\n", PACKAGE_STRING);
|
fprintf(stdout, "%s\n"
|
||||||
fprintf(stdout,
|
"Written by Sami Kerola.\n"
|
||||||
"Written by Sami Kerola.\nXML support by Dominic Germain, Sogetel inc.\n\n");
|
"XML support by Dominic Germain, Sogetel inc.\n\n"
|
||||||
fprintf(stdout,
|
"The software has FreeBSD License.\n", PACKAGE_STRING);
|
||||||
"The software has FreeBSD License.\n");
|
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
void usage(int status)
|
void __attribute__ ((__noreturn__)) usage(int status)
|
||||||
{
|
{
|
||||||
FILE *out;
|
FILE *out;
|
||||||
out = status != 0 ? stderr : stdout;
|
out = status != 0 ? stderr : stdout;
|
||||||
|
|
||||||
fprintf(out, "\n\
|
fprintf(out, "\
|
||||||
Usage: %s [OPTIONS]\n\n", program_invocation_short_name);
|
Usage: %s [OPTIONS]\n\n", program_invocation_short_name);
|
||||||
|
|
||||||
fprintf(out, "\
|
fprintf(out, "\
|
||||||
This is ISC dhcpd pools usage analyzer.\n\
|
This is ISC dhcpd pools usage analyzer.\n\
|
||||||
\n");
|
\n\
|
||||||
fprintf(out, "\
|
|
||||||
-c, --config=FILE path to the dhcpd.conf file\n\
|
-c, --config=FILE path to the dhcpd.conf file\n\
|
||||||
-l, --leases=FILE path to the dhcpd.leases file\n\
|
-l, --leases=FILE path to the dhcpd.leases file\n\
|
||||||
-f, --format=[thHcxX] output format\n");
|
-f, --format=[thHcxX] output format\n\
|
||||||
fprintf(out, "\
|
|
||||||
t for text\n\
|
t for text\n\
|
||||||
h for html table\n\
|
h for html table\n\
|
||||||
H for full html page\n\
|
H for full html page\n\
|
||||||
x for xml\n\
|
x for xml\n\
|
||||||
X for xml with active lease details\n\
|
X for xml with active lease details\n\
|
||||||
c for comma separated values\n");
|
c for comma separated values\n\
|
||||||
fprintf(out, "\
|
|
||||||
-s, --sort=[nimcptTe] sort ranges by\n\
|
-s, --sort=[nimcptTe] sort ranges by\n\
|
||||||
n name\n\
|
n name\n\
|
||||||
i IP\n\
|
i IP\n\
|
||||||
|
|
@ -163,8 +160,7 @@ This is ISC dhcpd pools usage analyzer.\n\
|
||||||
p percent\n\
|
p percent\n\
|
||||||
t touched\n\
|
t touched\n\
|
||||||
T t+c\n\
|
T t+c\n\
|
||||||
e t+c perc\n");
|
e t+c perc\n\
|
||||||
fprintf(out, "\
|
|
||||||
-r, --reverse reverse order sort\n\
|
-r, --reverse reverse order sort\n\
|
||||||
-o, --output=FILE output into a file\n\
|
-o, --output=FILE output into a file\n\
|
||||||
-L, --limit=NR output limit mask 77 - 00\n\
|
-L, --limit=NR output limit mask 77 - 00\n\
|
||||||
|
|
|
||||||
71
src/output.c
71
src/output.c
|
|
@ -58,8 +58,7 @@ int output_txt(void)
|
||||||
if (config.output_file[0]) {
|
if (config.output_file[0]) {
|
||||||
outfile = fopen(config.output_file, "w+");
|
outfile = fopen(config.output_file, "w+");
|
||||||
if (outfile == NULL) {
|
if (outfile == NULL) {
|
||||||
err(EXIT_FAILURE, "output_txt: %s",
|
err(EXIT_FAILURE, "output_txt: %s", config.output_file);
|
||||||
config.output_file);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
outfile = stdout;
|
outfile = stdout;
|
||||||
|
|
@ -91,7 +90,8 @@ int output_txt(void)
|
||||||
}
|
}
|
||||||
fprintf(outfile, "%-16s", inet_ntoa(first));
|
fprintf(outfile, "%-16s", inet_ntoa(first));
|
||||||
fprintf(outfile,
|
fprintf(outfile,
|
||||||
" - %-16s %5"PRIu32" %5lu %10.3f %5lu %5lu %9.3f",
|
" - %-16s %5" PRIu32
|
||||||
|
" %5lu %10.3f %5lu %5lu %9.3f",
|
||||||
inet_ntoa(last),
|
inet_ntoa(last),
|
||||||
range_p->last_ip - range_p->first_ip - 1,
|
range_p->last_ip - range_p->first_ip - 1,
|
||||||
range_p->count,
|
range_p->count,
|
||||||
|
|
@ -101,8 +101,8 @@ int output_txt(void)
|
||||||
range_p->touched + range_p->count,
|
range_p->touched + range_p->count,
|
||||||
(float)(100 *
|
(float)(100 *
|
||||||
(range_p->touched +
|
(range_p->touched +
|
||||||
range_p->count)) /
|
range_p->count)) / (range_p->last_ip -
|
||||||
(range_p->last_ip - range_p->first_ip -
|
range_p->first_ip -
|
||||||
1));
|
1));
|
||||||
if (0 < num_backups) {
|
if (0 < num_backups) {
|
||||||
fprintf(outfile, "%7lu %8.3f",
|
fprintf(outfile, "%7lu %8.3f",
|
||||||
|
|
@ -216,8 +216,7 @@ int output_xml(void)
|
||||||
if (config.output_file[0]) {
|
if (config.output_file[0]) {
|
||||||
outfile = fopen(config.output_file, "w+");
|
outfile = fopen(config.output_file, "w+");
|
||||||
if (outfile == NULL) {
|
if (outfile == NULL) {
|
||||||
err(EXIT_FAILURE, "output_xml: %s",
|
err(EXIT_FAILURE, "output_xml: %s", config.output_file);
|
||||||
config.output_file);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
outfile = stdout;
|
outfile = stdout;
|
||||||
|
|
@ -247,15 +246,13 @@ int output_xml(void)
|
||||||
"\t<location>%s</location>\n",
|
"\t<location>%s</location>\n",
|
||||||
range_p->shared_net->name);
|
range_p->shared_net->name);
|
||||||
} else {
|
} else {
|
||||||
fprintf(outfile,
|
fprintf(outfile, "\t<location></location>\n");
|
||||||
"\t<location></location>\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(outfile, "\t<network></network>\n");
|
fprintf(outfile, "\t<network></network>\n");
|
||||||
fprintf(outfile, "\t<netmask></netmask>\n");
|
fprintf(outfile, "\t<netmask></netmask>\n");
|
||||||
fprintf(outfile, "\t<range>%s ", inet_ntoa(first));
|
fprintf(outfile, "\t<range>%s ", inet_ntoa(first));
|
||||||
fprintf(outfile, "- %s</range>\n",
|
fprintf(outfile, "- %s</range>\n", inet_ntoa(last));
|
||||||
inet_ntoa(last));
|
|
||||||
fprintf(outfile, "\t<gateway></gateway>\n");
|
fprintf(outfile, "\t<gateway></gateway>\n");
|
||||||
fprintf(outfile, "\t<defined>%" PRIu32 "</defined>\n",
|
fprintf(outfile, "\t<defined>%" PRIu32 "</defined>\n",
|
||||||
range_p->last_ip - range_p->first_ip - 1);
|
range_p->last_ip - range_p->first_ip - 1);
|
||||||
|
|
@ -291,11 +288,9 @@ int output_xml(void)
|
||||||
shared_networks->name);
|
shared_networks->name);
|
||||||
fprintf(outfile, "\t<defined>%lu</defined>\n",
|
fprintf(outfile, "\t<defined>%lu</defined>\n",
|
||||||
shared_networks->available);
|
shared_networks->available);
|
||||||
fprintf(outfile, "\t<used>%lu</used>\n",
|
fprintf(outfile, "\t<used>%lu</used>\n", shared_networks->used);
|
||||||
shared_networks->used);
|
|
||||||
fprintf(outfile, "\t<free>%lu</free>\n",
|
fprintf(outfile, "\t<free>%lu</free>\n",
|
||||||
shared_networks->available -
|
shared_networks->available - shared_networks->used);
|
||||||
shared_networks->used);
|
|
||||||
fprintf(outfile, "</summary>\n");
|
fprintf(outfile, "</summary>\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -317,8 +312,7 @@ int output_xml(void)
|
||||||
|
|
||||||
void html_header(FILE * f)
|
void html_header(FILE * f)
|
||||||
{
|
{
|
||||||
fprintf(f,
|
fprintf(f, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \n");
|
||||||
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \n");
|
|
||||||
fprintf(f, " \"http://www.w3.org/TR/html4/strict.dtd\">\n");
|
fprintf(f, " \"http://www.w3.org/TR/html4/strict.dtd\">\n");
|
||||||
fprintf(f, "<html>\n");
|
fprintf(f, "<html>\n");
|
||||||
fprintf(f, "<head>\n");
|
fprintf(f, "<head>\n");
|
||||||
|
|
@ -381,7 +375,7 @@ void html_footer(FILE * f)
|
||||||
fprintf(f, "<hr>\n");
|
fprintf(f, "<hr>\n");
|
||||||
fprintf(f, "<p class=created>\nData generated by ");
|
fprintf(f, "<p class=created>\nData generated by ");
|
||||||
fprintf(f, "<a href=\"%s\">", PACKAGE_URL);
|
fprintf(f, "<a href=\"%s\">", PACKAGE_URL);
|
||||||
fprintf(f, "dhcpd-pools</a>.\n</p>\n");
|
fprintf(f, "%s</a>.\n</p>\n", PACKAGE_NAME);
|
||||||
fprintf(f, "<p class=updated>\n");
|
fprintf(f, "<p class=updated>\n");
|
||||||
fprintf(f, "<script type=\"text/javascript\">\n");
|
fprintf(f, "<script type=\"text/javascript\">\n");
|
||||||
fprintf(f, " document.write(\"Last Updated On \" + ");
|
fprintf(f, " document.write(\"Last Updated On \" + ");
|
||||||
|
|
@ -419,7 +413,7 @@ void output_float(FILE * f, char *type, float fl)
|
||||||
void table_start(FILE * f)
|
void table_start(FILE * f)
|
||||||
{
|
{
|
||||||
fprintf(f, "<table width=\"75%%\" ");
|
fprintf(f, "<table width=\"75%%\" ");
|
||||||
fprintf(f, "class=\"dhcpd-pools\" ");
|
fprintf(f, "class=\"%s\" ", PACKAGE_NAME);
|
||||||
fprintf(f, "summary=\"ISC dhcpd pool usage report\">\n");
|
fprintf(f, "summary=\"ISC dhcpd pool usage report\">\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -492,13 +486,10 @@ int output_html(void)
|
||||||
output_line(outfile, "td", "calign",
|
output_line(outfile, "td", "calign",
|
||||||
"not_defined");
|
"not_defined");
|
||||||
}
|
}
|
||||||
output_line(outfile, "td", "calign",
|
output_line(outfile, "td", "calign", inet_ntoa(first));
|
||||||
inet_ntoa(first));
|
output_line(outfile, "td", "calign", inet_ntoa(last));
|
||||||
output_line(outfile, "td", "calign",
|
|
||||||
inet_ntoa(last));
|
|
||||||
output_long(outfile, "td",
|
output_long(outfile, "td",
|
||||||
range_p->last_ip - range_p->first_ip -
|
range_p->last_ip - range_p->first_ip - 1);
|
||||||
1);
|
|
||||||
output_long(outfile, "td", range_p->count);
|
output_long(outfile, "td", range_p->count);
|
||||||
output_float(outfile, "td",
|
output_float(outfile, "td",
|
||||||
(float)(100 * range_p->count) /
|
(float)(100 * range_p->count) /
|
||||||
|
|
@ -514,8 +505,7 @@ int output_html(void)
|
||||||
(range_p->last_ip -
|
(range_p->last_ip -
|
||||||
range_p->first_ip - 1));
|
range_p->first_ip - 1));
|
||||||
if (0 < num_backups) {
|
if (0 < num_backups) {
|
||||||
output_long(outfile, "td",
|
output_long(outfile, "td", range_p->backups);
|
||||||
range_p->backups);
|
|
||||||
output_float(outfile, "td",
|
output_float(outfile, "td",
|
||||||
(float)(100 *
|
(float)(100 *
|
||||||
range_p->backups) /
|
range_p->backups) /
|
||||||
|
|
@ -548,8 +538,7 @@ int output_html(void)
|
||||||
for (i = 0; i < num_shared_networks; i++) {
|
for (i = 0; i < num_shared_networks; i++) {
|
||||||
shared_p++;
|
shared_p++;
|
||||||
newrow(outfile);
|
newrow(outfile);
|
||||||
output_line(outfile, "td", "calign",
|
output_line(outfile, "td", "calign", shared_p->name);
|
||||||
shared_p->name);
|
|
||||||
output_long(outfile, "td", shared_p->available);
|
output_long(outfile, "td", shared_p->available);
|
||||||
output_long(outfile, "td", shared_p->used);
|
output_long(outfile, "td", shared_p->used);
|
||||||
output_float(outfile, "td",
|
output_float(outfile, "td",
|
||||||
|
|
@ -564,8 +553,7 @@ int output_html(void)
|
||||||
shared_p->used)) /
|
shared_p->used)) /
|
||||||
shared_p->available);
|
shared_p->available);
|
||||||
if (0 < num_backups) {
|
if (0 < num_backups) {
|
||||||
output_long(outfile, "td",
|
output_long(outfile, "td", shared_p->backups);
|
||||||
shared_p->backups);
|
|
||||||
output_float(outfile, "td",
|
output_float(outfile, "td",
|
||||||
(float)(100 *
|
(float)(100 *
|
||||||
shared_p->backups) /
|
shared_p->backups) /
|
||||||
|
|
@ -594,8 +582,7 @@ int output_html(void)
|
||||||
}
|
}
|
||||||
if (config.output_limit[1] & output_limit_bit_3) {
|
if (config.output_limit[1] & output_limit_bit_3) {
|
||||||
newrow(outfile);
|
newrow(outfile);
|
||||||
output_line(outfile, "td", "calign",
|
output_line(outfile, "td", "calign", shared_networks->name);
|
||||||
shared_networks->name);
|
|
||||||
output_long(outfile, "td", shared_networks->available);
|
output_long(outfile, "td", shared_networks->available);
|
||||||
output_long(outfile, "td", shared_networks->used);
|
output_long(outfile, "td", shared_networks->used);
|
||||||
output_float(outfile, "td",
|
output_float(outfile, "td",
|
||||||
|
|
@ -603,16 +590,14 @@ int output_html(void)
|
||||||
shared_networks->available);
|
shared_networks->available);
|
||||||
output_long(outfile, "td", shared_networks->touched);
|
output_long(outfile, "td", shared_networks->touched);
|
||||||
output_long(outfile, "td",
|
output_long(outfile, "td",
|
||||||
shared_networks->touched +
|
shared_networks->touched + shared_networks->used);
|
||||||
shared_networks->used);
|
|
||||||
output_float(outfile, "td",
|
output_float(outfile, "td",
|
||||||
(float)(100 *
|
(float)(100 *
|
||||||
(shared_networks->touched +
|
(shared_networks->touched +
|
||||||
shared_networks->used)) /
|
shared_networks->used)) /
|
||||||
shared_networks->available);
|
shared_networks->available);
|
||||||
if (0 < num_backups) {
|
if (0 < num_backups) {
|
||||||
output_long(outfile, "td",
|
output_long(outfile, "td", shared_networks->backups);
|
||||||
shared_networks->backups);
|
|
||||||
output_float(outfile, "td",
|
output_float(outfile, "td",
|
||||||
(float)(100 *
|
(float)(100 *
|
||||||
shared_networks->backups) /
|
shared_networks->backups) /
|
||||||
|
|
@ -649,8 +634,7 @@ int output_csv(void)
|
||||||
if (config.output_file[0]) {
|
if (config.output_file[0]) {
|
||||||
outfile = fopen(config.output_file, "w+");
|
outfile = fopen(config.output_file, "w+");
|
||||||
if (outfile == NULL) {
|
if (outfile == NULL) {
|
||||||
err(EXIT_FAILURE, "output_csv: %s",
|
err(EXIT_FAILURE, "output_csv: %s", config.output_file);
|
||||||
config.output_file);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
outfile = stdout;
|
outfile = stdout;
|
||||||
|
|
@ -680,7 +664,8 @@ int output_csv(void)
|
||||||
}
|
}
|
||||||
fprintf(outfile, "\"%s\",", inet_ntoa(first));
|
fprintf(outfile, "\"%s\",", inet_ntoa(first));
|
||||||
fprintf(outfile,
|
fprintf(outfile,
|
||||||
"\"%s\",\"%"PRIu32"\",\"%lu\",\"%.3f\",\"%lu\",\"%lu\",\"%.3f\"",
|
"\"%s\",\"%" PRIu32
|
||||||
|
"\",\"%lu\",\"%.3f\",\"%lu\",\"%lu\",\"%.3f\"",
|
||||||
inet_ntoa(last),
|
inet_ntoa(last),
|
||||||
range_p->last_ip - range_p->first_ip - 1,
|
range_p->last_ip - range_p->first_ip - 1,
|
||||||
range_p->count,
|
range_p->count,
|
||||||
|
|
@ -690,8 +675,8 @@ int output_csv(void)
|
||||||
range_p->touched + range_p->count,
|
range_p->touched + range_p->count,
|
||||||
(float)(100 *
|
(float)(100 *
|
||||||
(range_p->touched +
|
(range_p->touched +
|
||||||
range_p->count)) /
|
range_p->count)) / (range_p->last_ip -
|
||||||
(range_p->last_ip - range_p->first_ip -
|
range_p->first_ip -
|
||||||
1));
|
1));
|
||||||
if (0 < num_backups) {
|
if (0 < num_backups) {
|
||||||
fprintf(outfile, ",\"%lu\",\"%.3f\"",
|
fprintf(outfile, ",\"%lu\",\"%.3f\"",
|
||||||
|
|
@ -777,13 +762,11 @@ int output_csv(void)
|
||||||
if (ret) {
|
if (ret) {
|
||||||
warn("output_cvs: fflush");
|
warn("output_cvs: fflush");
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
ret = fclose(outfile);
|
ret = fclose(outfile);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
warn("output_cvs: fclose");
|
warn("output_cvs: fclose");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue