mirror of
git://git.code.sf.net/p/dhcpd-pools/code
synced 2025-12-16 15:57:00 +00:00
getdata: get rid of remaining stdbool usage
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
parent
8a8c28a17e
commit
87c06a1b13
2 changed files with 39 additions and 40 deletions
|
|
@ -144,12 +144,12 @@ int main(int argc, char **argv)
|
||||||
* command line option */
|
* command line option */
|
||||||
config.output_file[0] = '\0';
|
config.output_file[0] = '\0';
|
||||||
/* Alarming defaults. */
|
/* Alarming defaults. */
|
||||||
config.snet_alarms = false;
|
config.snet_alarms = 0;
|
||||||
config.warning = ALARM_WARN;
|
config.warning = ALARM_WARN;
|
||||||
config.critical = ALARM_CRIT;
|
config.critical = ALARM_CRIT;
|
||||||
config.warn_count = 0x100000000; /* == 2^32 that is the entire IPv4 space */
|
config.warn_count = 0x100000000; /* == 2^32 that is the entire IPv4 space */
|
||||||
config.crit_count = 0x100000000; /* basically turns off the count criteria */
|
config.crit_count = 0x100000000; /* basically turns off the count criteria */
|
||||||
config.perfdata = false;
|
config.perfdata = 0;
|
||||||
/* File location defaults */
|
/* File location defaults */
|
||||||
strncpy(config.dhcpdconf_file, DHCPDCONF_FILE, MAXLEN - 1);
|
strncpy(config.dhcpdconf_file, DHCPDCONF_FILE, MAXLEN - 1);
|
||||||
strncpy(config.dhcpdlease_file, DHCPDLEASE_FILE, MAXLEN - 1);
|
strncpy(config.dhcpdlease_file, DHCPDLEASE_FILE, MAXLEN - 1);
|
||||||
|
|
@ -160,8 +160,8 @@ int main(int argc, char **argv)
|
||||||
/* Make sure some output format is selected by default */
|
/* Make sure some output format is selected by default */
|
||||||
print_mac_addreses_tmp = OUTPUT_FORMAT;
|
print_mac_addreses_tmp = OUTPUT_FORMAT;
|
||||||
/* Default sort order is by IPs small to big */
|
/* Default sort order is by IPs small to big */
|
||||||
config.reverse_order = false;
|
config.reverse_order = 0;
|
||||||
config.backups_found = false;
|
config.backups_found = 0;
|
||||||
prepare_memory();
|
prepare_memory();
|
||||||
/* Parse command line options */
|
/* Parse command line options */
|
||||||
while (1) {
|
while (1) {
|
||||||
|
|
@ -204,7 +204,7 @@ int main(int argc, char **argv)
|
||||||
break;
|
break;
|
||||||
case 'r':
|
case 'r':
|
||||||
/* What ever sort in reverse order */
|
/* What ever sort in reverse order */
|
||||||
config.reverse_order = true;
|
config.reverse_order = 1;
|
||||||
break;
|
break;
|
||||||
case 'o':
|
case 'o':
|
||||||
/* Output file */
|
/* Output file */
|
||||||
|
|
@ -216,7 +216,7 @@ int main(int argc, char **argv)
|
||||||
config.number_limit = return_limit(optarg[1]);
|
config.number_limit = return_limit(optarg[1]);
|
||||||
break;
|
break;
|
||||||
case OPT_SNET_ALARMS:
|
case OPT_SNET_ALARMS:
|
||||||
config.snet_alarms = true;
|
config.snet_alarms = 1;
|
||||||
break;
|
break;
|
||||||
case OPT_WARN:
|
case OPT_WARN:
|
||||||
print_mac_addreses_tmp = "a";
|
print_mac_addreses_tmp = "a";
|
||||||
|
|
@ -239,7 +239,7 @@ int main(int argc, char **argv)
|
||||||
break;
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
/* Print additional performance data in alarming mode */
|
/* Print additional performance data in alarming mode */
|
||||||
config.perfdata = true;
|
config.perfdata = 1;
|
||||||
break;
|
break;
|
||||||
case 'v':
|
case 'v':
|
||||||
/* Print version */
|
/* Print version */
|
||||||
|
|
@ -295,14 +295,14 @@ int main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
/* Do the job */
|
/* Do the job */
|
||||||
set_ipv_functions(IPvUNKNOWN);
|
set_ipv_functions(IPvUNKNOWN);
|
||||||
parse_config(true, config.dhcpdconf_file, shared_networks);
|
parse_config(1, config.dhcpdconf_file, shared_networks);
|
||||||
parse_leases();
|
parse_leases();
|
||||||
prepare_data();
|
prepare_data();
|
||||||
do_counting();
|
do_counting();
|
||||||
tmp_ranges = xmalloc(sizeof(struct range_t) * num_ranges);
|
tmp_ranges = xmalloc(sizeof(struct range_t) * num_ranges);
|
||||||
if (config.sorts != NULL)
|
if (config.sorts != NULL)
|
||||||
mergesort_ranges(ranges, num_ranges, tmp_ranges);
|
mergesort_ranges(ranges, num_ranges, tmp_ranges);
|
||||||
if (config.reverse_order == true)
|
if (config.reverse_order == 1)
|
||||||
flip_ranges(ranges, tmp_ranges);
|
flip_ranges(ranges, tmp_ranges);
|
||||||
free(tmp_ranges);
|
free(tmp_ranges);
|
||||||
ret_val = output_analysis();
|
ret_val = output_analysis();
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,6 @@
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <stdbool.h>
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
@ -65,7 +64,7 @@ int parse_leases(void)
|
||||||
char *line, *ipstring, macstring[20], *stop;
|
char *line, *ipstring, macstring[20], *stop;
|
||||||
union ipaddr_t addr;
|
union ipaddr_t addr;
|
||||||
struct stat lease_file_stats;
|
struct stat lease_file_stats;
|
||||||
bool ethernets = false;
|
int ethernets = 0; /* boolean */
|
||||||
struct leases_t *lease;
|
struct leases_t *lease;
|
||||||
|
|
||||||
dhcpd_leases = fopen(config.dhcpdlease_file, "r");
|
dhcpd_leases = fopen(config.dhcpdlease_file, "r");
|
||||||
|
|
@ -92,7 +91,7 @@ int parse_leases(void)
|
||||||
ipstring = xmalloc(sizeof(char) * MAXLEN);
|
ipstring = xmalloc(sizeof(char) * MAXLEN);
|
||||||
ipstring[0] = '\0';
|
ipstring[0] = '\0';
|
||||||
if (config.print_mac_addreses == 1)
|
if (config.print_mac_addreses == 1)
|
||||||
ethernets = true;
|
ethernets = 1;
|
||||||
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))
|
||||||
error(EXIT_FAILURE, errno, "parse_leases: %s", config.dhcpdlease_file);
|
error(EXIT_FAILURE, errno, "parse_leases: %s", config.dhcpdlease_file);
|
||||||
|
|
@ -128,10 +127,10 @@ int parse_leases(void)
|
||||||
if ((lease = find_lease(&addr)) != NULL)
|
if ((lease = find_lease(&addr)) != NULL)
|
||||||
delete_lease(lease);
|
delete_lease(lease);
|
||||||
add_lease(&addr, BACKUP);
|
add_lease(&addr, BACKUP);
|
||||||
config.backups_found = true;
|
config.backups_found = 1;
|
||||||
break;
|
break;
|
||||||
case PREFIX_HARDWARE_ETHERNET:
|
case PREFIX_HARDWARE_ETHERNET:
|
||||||
if (ethernets == false)
|
if (ethernets == 0)
|
||||||
break;
|
break;
|
||||||
memcpy(macstring, line + 20, 17);
|
memcpy(macstring, line + 20, 17);
|
||||||
macstring[17] = '\0';
|
macstring[17] = '\0';
|
||||||
|
|
@ -184,7 +183,7 @@ void parse_config(int is_include, const char *restrict config_file,
|
||||||
struct shared_network_t *restrict shared_p)
|
struct shared_network_t *restrict shared_p)
|
||||||
{
|
{
|
||||||
FILE *dhcpd_config;
|
FILE *dhcpd_config;
|
||||||
bool newclause = true, comment = false, one_ip_range = false;
|
int newclause = 1, comment = 0, one_ip_range = 0; /* booleans */
|
||||||
int quote = 0, braces = 0, argument = ITS_NOTHING_INTERESTING;
|
int quote = 0, braces = 0, argument = ITS_NOTHING_INTERESTING;
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
char *word;
|
char *word;
|
||||||
|
|
@ -220,10 +219,10 @@ void parse_config(int is_include, const char *restrict config_file,
|
||||||
/* Handle comments if they are not quoted */
|
/* Handle comments if they are not quoted */
|
||||||
case '#':
|
case '#':
|
||||||
if (quote == 0)
|
if (quote == 0)
|
||||||
comment = true;
|
comment = 1;
|
||||||
continue;
|
continue;
|
||||||
case '"':
|
case '"':
|
||||||
if (comment == false) {
|
if (comment == 0) {
|
||||||
quote++;
|
quote++;
|
||||||
/* Either one or zero */
|
/* Either one or zero */
|
||||||
quote = quote % 2;
|
quote = quote % 2;
|
||||||
|
|
@ -233,18 +232,18 @@ void parse_config(int is_include, const char *restrict config_file,
|
||||||
/* New line resets comment section, but
|
/* New line resets comment section, but
|
||||||
* not if quoted */
|
* not if quoted */
|
||||||
if (quote == 0)
|
if (quote == 0)
|
||||||
comment = false;
|
comment = 0;
|
||||||
break;
|
break;
|
||||||
case ';':
|
case ';':
|
||||||
/* Quoted colon does not mean new clause */
|
/* Quoted colon does not mean new clause */
|
||||||
if (0 < quote)
|
if (0 < quote)
|
||||||
break;
|
break;
|
||||||
if (comment == false
|
if (comment == 0
|
||||||
&& argument != ITS_A_RANGE_FIRST_IP
|
&& argument != ITS_A_RANGE_FIRST_IP
|
||||||
&& argument != ITS_A_RANGE_SECOND_IP && argument != ITS_AN_INCLUCE) {
|
&& argument != ITS_A_RANGE_SECOND_IP && argument != ITS_AN_INCLUCE) {
|
||||||
newclause = true;
|
newclause = 1;
|
||||||
i = 0;
|
i = 0;
|
||||||
} else if (argument == ITS_A_RANGE_FIRST_IP && one_ip_range == true) {
|
} else if (argument == ITS_A_RANGE_FIRST_IP && one_ip_range == 1) {
|
||||||
argument = ITS_A_RANGE_SECOND_IP;
|
argument = ITS_A_RANGE_SECOND_IP;
|
||||||
c = ' ';
|
c = ' ';
|
||||||
} else if (argument == ITS_A_RANGE_SECOND_IP && 0 < i) {
|
} else if (argument == ITS_A_RANGE_SECOND_IP && 0 < i) {
|
||||||
|
|
@ -274,14 +273,14 @@ void parse_config(int is_include, const char *restrict config_file,
|
||||||
*
|
*
|
||||||
* shared-network DSL{ ... */
|
* shared-network DSL{ ... */
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
newclause = true;
|
newclause = 1;
|
||||||
continue;
|
continue;
|
||||||
} else
|
} else
|
||||||
break;
|
break;
|
||||||
case '}':
|
case '}':
|
||||||
if (0 < quote)
|
if (0 < quote)
|
||||||
break;
|
break;
|
||||||
if (comment == false) {
|
if (comment == 0) {
|
||||||
braces--;
|
braces--;
|
||||||
/* End of shared-network */
|
/* End of shared-network */
|
||||||
if (braces_shared == braces) {
|
if (braces_shared == braces) {
|
||||||
|
|
@ -290,23 +289,23 @@ void parse_config(int is_include, const char *restrict config_file,
|
||||||
braces_shared = 1000;
|
braces_shared = 1000;
|
||||||
shared_p = shared_networks;
|
shared_p = shared_networks;
|
||||||
}
|
}
|
||||||
/* Not literally true, but works for this
|
/* Not literally 1, but works for this
|
||||||
* program */
|
* program */
|
||||||
newclause = true;
|
newclause = 1;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
/* Either inside comment or Nth word of clause. */
|
/* Either inside comment or Nth word of clause. */
|
||||||
if (comment == true || (newclause == false && argument == ITS_NOTHING_INTERESTING))
|
if (comment == 1 || (newclause == 0 && argument == ITS_NOTHING_INTERESTING))
|
||||||
continue;
|
continue;
|
||||||
/* Strip white spaces before new clause word. */
|
/* Strip white spaces before new clause word. */
|
||||||
if ((newclause == true || argument != ITS_NOTHING_INTERESTING)
|
if ((newclause == 1 || argument != ITS_NOTHING_INTERESTING)
|
||||||
&& isspace(c) && i == 0 && one_ip_range == false)
|
&& isspace(c) && i == 0 && one_ip_range == 0)
|
||||||
continue;
|
continue;
|
||||||
/* Save to word which clause this is. */
|
/* Save to word which clause this is. */
|
||||||
if ((newclause == true || argument != ITS_NOTHING_INTERESTING)
|
if ((newclause == 1 || argument != ITS_NOTHING_INTERESTING)
|
||||||
&& (!isspace(c) || 0 < quote)) {
|
&& (!isspace(c) || 0 < quote)) {
|
||||||
word[i] = c;
|
word[i] = c;
|
||||||
i++;
|
i++;
|
||||||
|
|
@ -314,26 +313,26 @@ void parse_config(int is_include, const char *restrict config_file,
|
||||||
* of words are this long which the program is
|
* of words are this long which the program is
|
||||||
* searching. */
|
* searching. */
|
||||||
if (MAXLEN == i) {
|
if (MAXLEN == i) {
|
||||||
newclause = false;
|
newclause = 0;
|
||||||
i = 0;
|
i = 0;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* See if clause is something that parser is looking for. */
|
/* See if clause is something that parser is looking for. */
|
||||||
else if (newclause == true) {
|
else if (newclause == 1) {
|
||||||
/* Insert string end & set state */
|
/* Insert string end & set state */
|
||||||
word[i] = '\0';
|
word[i] = '\0';
|
||||||
if (word[i - 1] != '{')
|
if (word[i - 1] != '{')
|
||||||
newclause = false;
|
newclause = 0;
|
||||||
i = 0;
|
i = 0;
|
||||||
argument = is_interesting_config_clause(word);
|
argument = is_interesting_config_clause(word);
|
||||||
if (argument == ITS_A_RANGE_FIRST_IP)
|
if (argument == ITS_A_RANGE_FIRST_IP)
|
||||||
one_ip_range = true;
|
one_ip_range = 1;
|
||||||
}
|
}
|
||||||
/* words after range, shared-network or include */
|
/* words after range, shared-network or include */
|
||||||
else if (argument != ITS_NOTHING_INTERESTING) {
|
else if (argument != ITS_NOTHING_INTERESTING) {
|
||||||
word[i] = '\0';
|
word[i] = '\0';
|
||||||
newclause = false;
|
newclause = 0;
|
||||||
i = 0;
|
i = 0;
|
||||||
|
|
||||||
switch (argument) {
|
switch (argument) {
|
||||||
|
|
@ -342,8 +341,8 @@ void parse_config(int is_include, const char *restrict config_file,
|
||||||
range_p = ranges + num_ranges;
|
range_p = ranges + num_ranges;
|
||||||
argument = ITS_NOTHING_INTERESTING;
|
argument = ITS_NOTHING_INTERESTING;
|
||||||
parse_ipaddr(word, &addr);
|
parse_ipaddr(word, &addr);
|
||||||
if (one_ip_range == true) {
|
if (one_ip_range == 1) {
|
||||||
one_ip_range = false;
|
one_ip_range = 0;
|
||||||
copy_ipaddr(&range_p->first_ip, &addr);
|
copy_ipaddr(&range_p->first_ip, &addr);
|
||||||
}
|
}
|
||||||
copy_ipaddr(&range_p->last_ip, &addr);
|
copy_ipaddr(&range_p->last_ip, &addr);
|
||||||
|
|
@ -359,7 +358,7 @@ void parse_config(int is_include, const char *restrict config_file,
|
||||||
ranges = xrealloc(ranges, sizeof(struct range_t) * RANGES);
|
ranges = xrealloc(ranges, sizeof(struct range_t) * RANGES);
|
||||||
range_p = ranges + num_ranges;
|
range_p = ranges + num_ranges;
|
||||||
}
|
}
|
||||||
newclause = true;
|
newclause = 1;
|
||||||
break;
|
break;
|
||||||
case ITS_A_RANGE_FIRST_IP:
|
case ITS_A_RANGE_FIRST_IP:
|
||||||
/* printf ("range 1nd ip: %s\n", word); */
|
/* printf ("range 1nd ip: %s\n", word); */
|
||||||
|
|
@ -368,7 +367,7 @@ void parse_config(int is_include, const char *restrict config_file,
|
||||||
/* word was not ip, try again */
|
/* word was not ip, try again */
|
||||||
break;
|
break;
|
||||||
copy_ipaddr(&range_p->first_ip, &addr);
|
copy_ipaddr(&range_p->first_ip, &addr);
|
||||||
one_ip_range = false;
|
one_ip_range = 0;
|
||||||
argument = ITS_A_RANGE_SECOND_IP;
|
argument = ITS_A_RANGE_SECOND_IP;
|
||||||
break;
|
break;
|
||||||
case ITS_A_SHAREDNET:
|
case ITS_A_SHAREDNET:
|
||||||
|
|
@ -390,8 +389,8 @@ void parse_config(int is_include, const char *restrict config_file,
|
||||||
case ITS_AN_INCLUCE:
|
case ITS_AN_INCLUCE:
|
||||||
/* printf ("include file: %s\n", word); */
|
/* printf ("include file: %s\n", word); */
|
||||||
argument = ITS_NOTHING_INTERESTING;
|
argument = ITS_NOTHING_INTERESTING;
|
||||||
parse_config(false, word, shared_p);
|
parse_config(0, word, shared_p);
|
||||||
newclause = true;
|
newclause = 1;
|
||||||
break;
|
break;
|
||||||
case ITS_NOTHING_INTERESTING:
|
case ITS_NOTHING_INTERESTING:
|
||||||
/* printf ("nothing interesting: %s\n", word); */
|
/* printf ("nothing interesting: %s\n", word); */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue