main: move print_mac_addreses to state structure

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
Sami Kerola 2018-05-20 11:46:23 +01:00
parent 4e7ab66fd4
commit e8e9d49ebb
No known key found for this signature in database
GPG key ID: A9553245FDE9B739
4 changed files with 16 additions and 17 deletions

View file

@ -321,6 +321,9 @@ static char parse_command_line_opts(struct conf_t *state, int argc, char **argv)
output_format = default_format[0];
}
}
if (output_format == 'X' || output_format == 'J') {
state->print_mac_addreses = 1;
}
return output_format;
}
@ -355,10 +358,7 @@ int main(int argc, char **argv)
/* Do the job */
parse_config(&state, 1, state.dhcpdconf_file, state.shared_net_root);
if (output_format == 'X' || output_format == 'J')
parse_leases(&state, 1);
else
parse_leases(&state, 0);
parse_leases(&state);
prepare_data(&state);
do_counting(&state);
if (state.sorts != NULL)

View file

@ -224,6 +224,7 @@ struct conf_t {
double crit_count; /*!< Maximum number of free IP's before critical. */
double minsize; /*!< Minimum size of range or shared network to be considered exceeding threshold. */
unsigned int
print_mac_addreses:1, /*!< Print mac address in xml or json. */
reverse_order:1, /*!< Reverse sort order. */
backups_found:1, /*!< Indicator if dhcpd.leases file has leases in backup state. */
snet_alarms:1, /*!< Suppress alarming thresholds for ranges that are part of a shared network. */
@ -246,7 +247,7 @@ extern void prepare_data(struct conf_t *state);
extern void do_counting(struct conf_t *state);
/* getdata.c */
extern int parse_leases(struct conf_t *state, const int print_mac_addreses);
extern int parse_leases(struct conf_t *state);
extern void parse_config(struct conf_t *state, const int is_include,
const char *restrict config_file,
struct shared_network_t *restrict shared_p);

View file

@ -79,7 +79,7 @@ enum isc_conf_parser {
/*! \brief Lease file parser. The parser can only read ISC DHCPD
* dhcpd.leases file format. */
int parse_leases(struct conf_t *state, const int print_mac_addreses)
int parse_leases(struct conf_t *state)
{
FILE *dhcpd_leases;
char *line, *ipstring, macstring[20], *stop;
@ -144,7 +144,7 @@ int parse_leases(struct conf_t *state, const int print_mac_addreses)
state->backups_found = 1;
break;
case PREFIX_HARDWARE_ETHERNET:
if (print_mac_addreses == 0)
if (state->print_mac_addreses == 0)
break;
memcpy(macstring, line + 20, 17);
macstring[17] = '\0';

View file

@ -364,7 +364,7 @@ static int output_txt(struct conf_t *state)
}
/*! \brief The xml output formats. */
static int output_xml(struct conf_t *state, const int print_mac_addreses)
static int output_xml(struct conf_t *state)
{
unsigned int i;
struct range_t *range_p;
@ -377,7 +377,7 @@ static int output_xml(struct conf_t *state, const int print_mac_addreses)
fprintf(outfile, "<dhcpstatus>\n");
if (print_mac_addreses == 1) {
if (state->print_mac_addreses) {
struct leases_t *l;
for (l = state->leases; l != NULL; l = l->hh.next) {
@ -449,7 +449,7 @@ static int output_xml(struct conf_t *state, const int print_mac_addreses)
}
/*! \brief The json output formats. */
static int output_json(struct conf_t *state, const int print_mac_addreses)
static int output_json(struct conf_t *state)
{
unsigned int i = 0;
struct range_t *range_p;
@ -464,7 +464,7 @@ static int output_json(struct conf_t *state, const int print_mac_addreses)
fprintf(outfile, "{\n");
if (print_mac_addreses == 1) {
if (state->print_mac_addreses) {
struct leases_t *l;
fprintf(outfile, " \"active_leases\": [");
@ -1200,16 +1200,14 @@ int output_analysis(struct conf_t *state, const char output_format)
ret = output_html(state);
break;
case 'x':
ret = output_xml(state, 0);
break;
/* fallthrough */
case 'X':
ret = output_xml(state, 1);
ret = output_xml(state);
break;
case 'j':
ret = output_json(state, 0);
break;
/* fallthrough */
case 'J':
ret = output_json(state, 1);
ret = output_json(state);
break;
case 'c':
ret = output_csv(state);